Internal: Fix migration for agenda_reminders to avoid FK and index issues

pull/5649/head
Angel Fernando Quiroz Campos 5 months ago
parent 2618d75e6b
commit c63568dc8c
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 24
      src/CoreBundle/Migrations/Schema/V200/Version20240425192900.php

@ -20,14 +20,28 @@ class Version20240425192900 extends AbstractMigration
{
if (!$schema->hasTable('agenda_reminder')) {
$this->addSql(
'CREATE TABLE agenda_reminder (id INT AUTO_INCREMENT NOT NULL, event_id INT NOT NULL, date_interval VARCHAR(255) NOT NULL COMMENT "(DC2Type:dateinterval)", sent TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT "(DC2Type:datetime)", updated_at DATETIME NOT NULL COMMENT "(DC2Type:datetime)", PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;'
"CREATE TABLE agenda_reminder (id INT AUTO_INCREMENT NOT NULL, event_id INT NOT NULL, date_interval VARCHAR(255) NOT NULL COMMENT '(DC2Type:dateinterval)', sent TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', INDEX IDX_416FFA2471F7E88B (event_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC"
);
$this->addSql("ALTER TABLE agenda_reminder ADD CONSTRAINT FK_416FFA2471F7E88B FOREIGN KEY (event_id) REFERENCES c_calendar_event (iid)");
} else {
$this->addSql('ALTER TABLE agenda_reminder DROP type');
$this->addSql('ALTER TABLE agenda_reminder CHANGE id id INT AUTO_INCREMENT NOT NULL;');
$tblAgendaReminder = $schema->getTable('agenda_reminder');
if ($tblAgendaReminder->hasColumn('type')) {
$this->addSql("ALTER TABLE agenda_reminder DROP type");
}
$this->addSql("ALTER TABLE agenda_reminder CHANGE id id INT AUTO_INCREMENT NOT NULL");
if (!$tblAgendaReminder->hasForeignKey('FK_416FFA2471F7E88B')) {
$this->addSql('DELETE FROM agenda_reminder WHERE event_id IS NULL OR event_id NOT IN (SELECT iid FROM c_calendar_event)');
$this->addSql("ALTER TABLE agenda_reminder ADD CONSTRAINT FK_416FFA2471F7E88B FOREIGN KEY (event_id) REFERENCES c_calendar_event (iid)");
}
if (!$tblAgendaReminder->hasIndex('IDX_416FFA2471F7E88B')) {
$this->addSql("CREATE INDEX IDX_416FFA2471F7E88B ON agenda_reminder (event_id)");
}
}
$this->addSql('ALTER TABLE agenda_reminder ADD CONSTRAINT FK_416FFA2471F7E88B FOREIGN KEY (event_id) REFERENCES c_calendar_event (iid)');
$this->addSql('CREATE INDEX IDX_416FFA2471F7E88B ON agenda_reminder (event_id)');
}
}

Loading…
Cancel
Save