From 7c3152f2775ad0a61d809af3403376e25d0c7d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 27 Nov 2023 20:29:48 +0100 Subject: [PATCH] Fix migration when executed after the person entity table name change --- .../migrations/Version20141129012050.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillReportBundle/migrations/Version20141129012050.php b/src/Bundle/ChillReportBundle/migrations/Version20141129012050.php index 2408df14c..c45d1ef0b 100644 --- a/src/Bundle/ChillReportBundle/migrations/Version20141129012050.php +++ b/src/Bundle/ChillReportBundle/migrations/Version20141129012050.php @@ -32,7 +32,18 @@ class Version20141129012050 extends AbstractMigration $this->addSql('CREATE INDEX IDX_C38372B2217BBB47 ON Report (person_id);'); $this->addSql('CREATE INDEX IDX_C38372B216D2C9F0 ON Report (cFGroup_id);'); $this->addSql('ALTER TABLE Report ADD CONSTRAINT FK_C38372B2A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE;'); - $this->addSql('ALTER TABLE Report ADD CONSTRAINT FK_C38372B2217BBB47 FOREIGN KEY (person_id) REFERENCES Person (id) NOT DEFERRABLE INITIALLY IMMEDIATE;'); + + // 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 Report ADD CONSTRAINT FK_C38372B2217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE;'); + } else { + $this->addSql('ALTER TABLE Report ADD CONSTRAINT FK_C38372B2217BBB47 FOREIGN KEY (person_id) REFERENCES Person (id) NOT DEFERRABLE INITIALLY IMMEDIATE;'); + } + $this->addSql('ALTER TABLE Report ADD CONSTRAINT FK_C38372B216D2C9F0 FOREIGN KEY (cFGroup_id) REFERENCES CustomFieldsGroup (id) NOT DEFERRABLE INITIALLY IMMEDIATE;'); } }