migrations/Version20230823192742.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20230823192742 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add tables for activity complaints';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('CREATE TABLE complaint (id INT UNSIGNED AUTO_INCREMENT NOT NULL, reason_id SMALLINT UNSIGNED NOT NULL, sponsor_id BIGINT UNSIGNED NOT NULL, comment LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_2DD0CD6B59BB1592 (reason_id), INDEX IDX_2DD0CD6B12F7FB51 (sponsor_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
  15.         $this->addSql('CREATE TABLE complaint_reason (id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
  16.         $this->addSql('ALTER TABLE complaint ADD CONSTRAINT FK_2DD0CD6B59BB1592 FOREIGN KEY (reason_id) REFERENCES complaint_reason (id) ON DELETE CASCADE');
  17.         $this->addSql('ALTER TABLE complaint ADD CONSTRAINT FK_2DD0CD6B12F7FB51 FOREIGN KEY (sponsor_id) REFERENCES sponsor (id) ON DELETE CASCADE');
  18.         $this->addSql('ALTER TABLE activity ADD complaint_id INT UNSIGNED DEFAULT NULL');
  19.         $this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095ADA449A0B FOREIGN KEY (complaint_id) REFERENCES complaint (id)');
  20.         $this->addSql('CREATE UNIQUE INDEX UNIQ_AC74095ADA449A0B ON activity (complaint_id)');
  21.     }
  22.     public function down(Schema $schema): void
  23.     {
  24.         $this->addSql('ALTER TABLE activity DROP FOREIGN KEY FK_AC74095ADA449A0B');
  25.         $this->addSql('ALTER TABLE complaint DROP FOREIGN KEY FK_2DD0CD6B59BB1592');
  26.         $this->addSql('ALTER TABLE complaint DROP FOREIGN KEY FK_2DD0CD6B12F7FB51');
  27.         $this->addSql('DROP TABLE complaint');
  28.         $this->addSql('DROP TABLE complaint_reason');
  29.         $this->addSql('DROP INDEX UNIQ_AC74095ADA449A0B ON activity');
  30.         $this->addSql('ALTER TABLE activity DROP complaint_id');
  31.     }
  32. }