<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240502104621 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create joined table with only two columns: person_id and point_of_interest_id. Add the foreign keys to the person and point_of_interest tables.';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE person_point_of_interests (person_id INT NOT NULL, point_of_interest_id INT NOT NULL, PRIMARY KEY(person_id, point_of_interest_id))');
$this->addSql('CREATE INDEX IDX_5A3D3C3A9E6F5DFB ON person_point_of_interests (person_id)');
$this->addSql('CREATE INDEX IDX_5A3D3C3A3B5E7B7C ON person_point_of_interests (point_of_interest_id)');
$this->addSql('ALTER TABLE person_point_of_interests ADD CONSTRAINT FK_5A3D3C3A9E6F5DFB FOREIGN KEY (person_id) REFERENCES person (id)');
$this->addSql('ALTER TABLE person_point_of_interests ADD CONSTRAINT FK_5A3D3C3A3B5E7B7C FOREIGN KEY (point_of_interest_id) REFERENCES point_of_interest (id)');
// Add all the values where referent_id in person table is not null
$this->addSql('INSERT INTO person_point_of_interests (person_id, point_of_interest_id) SELECT referent_id, id FROM point_of_interest WHERE referent_id IS NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE person_point_of_interests');
}
}