From d347f6ae60829abfa2e5464110bf9646d3a3cd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 27 Nov 2023 11:51:56 +0100 Subject: [PATCH] Fix migrations to take into account the change in table name for Person's entity --- .../migrations/Version20160318111334.php | 29 +++++++++++++++---- .../migrations/Version20190110140538.php | 10 +++++-- .../migrations/Version20190115140042.php | 12 +++++--- .../migrations/Version20190201143121.php | 12 +++++--- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php b/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php index 4689fe413..908f2bfea 100644 --- a/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php +++ b/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\Migrations\Event; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; @@ -19,10 +20,14 @@ use Doctrine\Migrations\AbstractMigration; */ class Version20160318111334 extends AbstractMigration { + public function getDescription(): string + { + return 'initialize the bundle chill event'; + } + public function down(Schema $schema): void { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE chill_event_role DROP CONSTRAINT FK_AA714E54C54C8C93'); $this->addSql('ALTER TABLE chill_event_status DROP CONSTRAINT FK_A6CC85D0C54C8C93'); @@ -50,8 +55,7 @@ class Version20160318111334 extends AbstractMigration public function up(Schema $schema): void { - // this up() migration is auto-generated, please modify it to your needs - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('CREATE SEQUENCE chill_event_event_type_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE chill_event_role_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); @@ -123,11 +127,26 @@ class Version20160318111334 extends AbstractMigration .'FOREIGN KEY (event_id) ' .'REFERENCES chill_event_event (id) ' .'NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE chill_event_participation ' + + // before adding fk constraint to person, check what is the table name + $results = $this->connection->executeQuery('SELECT EXISTS (SELECT 1 FROM pg_tables WHERE tablename = \'chill_person_person\')'); + /** @var bool $isChillPersonPersonTable */ + $isChillPersonPersonTable = $results->fetchFirstColumn()[0]; + + if ($isChillPersonPersonTable) { + $this->addSql('ALTER TABLE chill_event_participation ' + .'ADD CONSTRAINT FK_4E7768AC217BBB47 ' + .'FOREIGN KEY (person_id) ' + .'REFERENCES chill_person_person (id) ' + .'NOT DEFERRABLE INITIALLY IMMEDIATE'); + } else { + $this->addSql('ALTER TABLE chill_event_participation ' .'ADD CONSTRAINT FK_4E7768AC217BBB47 ' .'FOREIGN KEY (person_id) ' .'REFERENCES Person (id) ' .'NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + $this->addSql('ALTER TABLE chill_event_participation ' .'ADD CONSTRAINT FK_4E7768ACD60322AC ' .'FOREIGN KEY (role_id) ' diff --git a/src/Bundle/ChillEventBundle/migrations/Version20190110140538.php b/src/Bundle/ChillEventBundle/migrations/Version20190110140538.php index bc004119e..d83e1b397 100644 --- a/src/Bundle/ChillEventBundle/migrations/Version20190110140538.php +++ b/src/Bundle/ChillEventBundle/migrations/Version20190110140538.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\Migrations\Event; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; @@ -19,9 +20,14 @@ use Doctrine\Migrations\AbstractMigration; */ final class Version20190110140538 extends AbstractMigration { + public function getDescription(): string + { + return 'switch event date to datetime'; + } + public function down(Schema $schema): void { - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE chill_event_event ALTER date TYPE DATE'); $this->addSql('ALTER TABLE chill_event_event ALTER date DROP DEFAULT'); @@ -29,7 +35,7 @@ final class Version20190110140538 extends AbstractMigration public function up(Schema $schema): void { - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE chill_event_event ALTER date TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); $this->addSql('ALTER TABLE chill_event_event ALTER date DROP DEFAULT'); diff --git a/src/Bundle/ChillEventBundle/migrations/Version20190115140042.php b/src/Bundle/ChillEventBundle/migrations/Version20190115140042.php index c0ced1044..4ef21a834 100644 --- a/src/Bundle/ChillEventBundle/migrations/Version20190115140042.php +++ b/src/Bundle/ChillEventBundle/migrations/Version20190115140042.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\Migrations\Event; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; @@ -19,10 +20,14 @@ use Doctrine\Migrations\AbstractMigration; */ final class Version20190115140042 extends AbstractMigration { + public function getDescription(): string + { + return 'add a moderator field to events'; + } + public function down(Schema $schema): void { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE chill_event_event DROP CONSTRAINT FK_FA320FC8D0AFA354'); $this->addSql('DROP INDEX IDX_FA320FC8D0AFA354'); @@ -31,8 +36,7 @@ final class Version20190115140042 extends AbstractMigration public function up(Schema $schema): void { - // this up() migration is auto-generated, please modify it to your needs - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE chill_event_event ADD moderator_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE chill_event_event ADD CONSTRAINT FK_FA320FC8D0AFA354 FOREIGN KEY (moderator_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); diff --git a/src/Bundle/ChillEventBundle/migrations/Version20190201143121.php b/src/Bundle/ChillEventBundle/migrations/Version20190201143121.php index f9d64da75..cc8445f95 100644 --- a/src/Bundle/ChillEventBundle/migrations/Version20190201143121.php +++ b/src/Bundle/ChillEventBundle/migrations/Version20190201143121.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\Migrations\Event; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; @@ -19,10 +20,14 @@ use Doctrine\Migrations\AbstractMigration; */ final class Version20190201143121 extends AbstractMigration { + public function getDescription(): string + { + return 'fix moderator: relation with user (not person)'; + } + public function down(Schema $schema): void { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE chill_event_event DROP CONSTRAINT fk_fa320fc8d0afa354'); $this->addSql('ALTER TABLE chill_event_event ADD CONSTRAINT fk_fa320fc8d0afa354 FOREIGN KEY (moderator_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); @@ -30,8 +35,7 @@ final class Version20190201143121 extends AbstractMigration public function up(Schema $schema): void { - // this up() migration is auto-generated, please modify it to your needs - $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE chill_event_event DROP CONSTRAINT FK_FA320FC8D0AFA354'); $this->addSql('ALTER TABLE chill_event_event ADD CONSTRAINT FK_FA320FC8D0AFA354 FOREIGN KEY (moderator_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');