<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20230823192742 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add tables for activity complaints';
}
public function up(Schema $schema): void
{
$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');
$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');
$this->addSql('ALTER TABLE complaint ADD CONSTRAINT FK_2DD0CD6B59BB1592 FOREIGN KEY (reason_id) REFERENCES complaint_reason (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE complaint ADD CONSTRAINT FK_2DD0CD6B12F7FB51 FOREIGN KEY (sponsor_id) REFERENCES sponsor (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE activity ADD complaint_id INT UNSIGNED DEFAULT NULL');
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095ADA449A0B FOREIGN KEY (complaint_id) REFERENCES complaint (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_AC74095ADA449A0B ON activity (complaint_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE activity DROP FOREIGN KEY FK_AC74095ADA449A0B');
$this->addSql('ALTER TABLE complaint DROP FOREIGN KEY FK_2DD0CD6B59BB1592');
$this->addSql('ALTER TABLE complaint DROP FOREIGN KEY FK_2DD0CD6B12F7FB51');
$this->addSql('DROP TABLE complaint');
$this->addSql('DROP TABLE complaint_reason');
$this->addSql('DROP INDEX UNIQ_AC74095ADA449A0B ON activity');
$this->addSql('ALTER TABLE activity DROP complaint_id');
}
}