Fix migrations to take into account the change in table name for Person's entity

This commit is contained in:
Julien Fastré 2023-11-27 11:51:56 +01:00
parent 8ef001e67e
commit d347f6ae60
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 48 additions and 15 deletions

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\Migrations\Event; namespace Chill\Migrations\Event;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\AbstractMigration;
@ -19,10 +20,14 @@ use Doctrine\Migrations\AbstractMigration;
*/ */
class Version20160318111334 extends AbstractMigration class Version20160318111334 extends AbstractMigration
{ {
public function getDescription(): string
{
return 'initialize the bundle chill event';
}
public function down(Schema $schema): void public function down(Schema $schema): void
{ {
// this down() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), '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_role DROP CONSTRAINT FK_AA714E54C54C8C93');
$this->addSql('ALTER TABLE chill_event_status DROP CONSTRAINT FK_A6CC85D0C54C8C93'); $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 public function up(Schema $schema): void
{ {
// this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), '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_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'); $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) ' .'FOREIGN KEY (event_id) '
.'REFERENCES chill_event_event (id) ' .'REFERENCES chill_event_event (id) '
.'NOT DEFERRABLE INITIALLY IMMEDIATE'); .'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 ' .'ADD CONSTRAINT FK_4E7768AC217BBB47 '
.'FOREIGN KEY (person_id) ' .'FOREIGN KEY (person_id) '
.'REFERENCES Person (id) ' .'REFERENCES Person (id) '
.'NOT DEFERRABLE INITIALLY IMMEDIATE'); .'NOT DEFERRABLE INITIALLY IMMEDIATE');
}
$this->addSql('ALTER TABLE chill_event_participation ' $this->addSql('ALTER TABLE chill_event_participation '
.'ADD CONSTRAINT FK_4E7768ACD60322AC ' .'ADD CONSTRAINT FK_4E7768ACD60322AC '
.'FOREIGN KEY (role_id) ' .'FOREIGN KEY (role_id) '

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\Migrations\Event; namespace Chill\Migrations\Event;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\AbstractMigration;
@ -19,9 +20,14 @@ use Doctrine\Migrations\AbstractMigration;
*/ */
final class Version20190110140538 extends AbstractMigration final class Version20190110140538 extends AbstractMigration
{ {
public function getDescription(): string
{
return 'switch event date to datetime';
}
public function down(Schema $schema): void 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 TYPE DATE');
$this->addSql('ALTER TABLE chill_event_event ALTER date DROP DEFAULT'); $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 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 TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE chill_event_event ALTER date DROP DEFAULT'); $this->addSql('ALTER TABLE chill_event_event ALTER date DROP DEFAULT');

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\Migrations\Event; namespace Chill\Migrations\Event;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\AbstractMigration;
@ -19,10 +20,14 @@ use Doctrine\Migrations\AbstractMigration;
*/ */
final class Version20190115140042 extends AbstractMigration final class Version20190115140042 extends AbstractMigration
{ {
public function getDescription(): string
{
return 'add a moderator field to events';
}
public function down(Schema $schema): void public function down(Schema $schema): void
{ {
// this down() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), '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 DROP CONSTRAINT FK_FA320FC8D0AFA354');
$this->addSql('DROP INDEX IDX_FA320FC8D0AFA354'); $this->addSql('DROP INDEX IDX_FA320FC8D0AFA354');
@ -31,8 +36,7 @@ final class Version20190115140042 extends AbstractMigration
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
// this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), '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 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'); $this->addSql('ALTER TABLE chill_event_event ADD CONSTRAINT FK_FA320FC8D0AFA354 FOREIGN KEY (moderator_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE');

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\Migrations\Event; namespace Chill\Migrations\Event;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\AbstractMigration;
@ -19,10 +20,14 @@ use Doctrine\Migrations\AbstractMigration;
*/ */
final class Version20190201143121 extends AbstractMigration final class Version20190201143121 extends AbstractMigration
{ {
public function getDescription(): string
{
return 'fix moderator: relation with user (not person)';
}
public function down(Schema $schema): void public function down(Schema $schema): void
{ {
// this down() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), '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 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'); $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 public function up(Schema $schema): void
{ {
// this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), '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 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'); $this->addSql('ALTER TABLE chill_event_event ADD CONSTRAINT FK_FA320FC8D0AFA354 FOREIGN KEY (moderator_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');