53 lines
4.1 KiB
PHP
53 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
/**
|
|
* Written by hand from the diff, keeping only the mailing tables and upload.mailing_template_id:
|
|
* doctrine:migrations:diff also sweeps in the pre-existing drift of the dev database.
|
|
*/
|
|
final class Version20261111115642 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add mailing templates and the record of sent assignment mailings';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql('CREATE TABLE mailing_template (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, name VARCHAR(255) NOT NULL, subject VARCHAR(255) NOT NULL, message LONGTEXT NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, deleted_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_4A7CB3AFD17F50A6 (uuid), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
|
$this->addSql('CREATE TABLE mailing (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, subject VARCHAR(255) NOT NULL, message LONGTEXT NOT NULL, recipient_count INT NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, deleted_at DATETIME DEFAULT NULL, template_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_3ED9315ED17F50A6 (uuid), INDEX IDX_3ED9315E5DA0FB8 (template_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
|
$this->addSql('CREATE TABLE mailing_assignment (mailing_id INT NOT NULL, assignment_id INT NOT NULL, INDEX IDX_D6941DCB3931AB76 (mailing_id), INDEX IDX_D6941DCBD19302F8 (assignment_id), PRIMARY KEY (mailing_id, assignment_id)) DEFAULT CHARACTER SET utf8mb4');
|
|
$this->addSql('CREATE TABLE mailing_attachment (mailing_id INT NOT NULL, upload_id INT NOT NULL, INDEX IDX_9F0E80CA3931AB76 (mailing_id), INDEX IDX_9F0E80CACCCFBA31 (upload_id), PRIMARY KEY (mailing_id, upload_id)) DEFAULT CHARACTER SET utf8mb4');
|
|
$this->addSql('ALTER TABLE mailing ADD CONSTRAINT FK_3ED9315E5DA0FB8 FOREIGN KEY (template_id) REFERENCES mailing_template (id)');
|
|
$this->addSql('ALTER TABLE mailing_assignment ADD CONSTRAINT FK_D6941DCB3931AB76 FOREIGN KEY (mailing_id) REFERENCES mailing (id) ON DELETE CASCADE');
|
|
$this->addSql('ALTER TABLE mailing_assignment ADD CONSTRAINT FK_D6941DCBD19302F8 FOREIGN KEY (assignment_id) REFERENCES assignment (id) ON DELETE CASCADE');
|
|
$this->addSql('ALTER TABLE mailing_attachment ADD CONSTRAINT FK_9F0E80CA3931AB76 FOREIGN KEY (mailing_id) REFERENCES mailing (id) ON DELETE CASCADE');
|
|
$this->addSql('ALTER TABLE mailing_attachment ADD CONSTRAINT FK_9F0E80CACCCFBA31 FOREIGN KEY (upload_id) REFERENCES upload (id) ON DELETE CASCADE');
|
|
$this->addSql('ALTER TABLE upload ADD mailing_template_id INT DEFAULT NULL');
|
|
$this->addSql('ALTER TABLE upload ADD CONSTRAINT FK_17BDE61F223E1F4B FOREIGN KEY (mailing_template_id) REFERENCES mailing_template (id)');
|
|
$this->addSql('CREATE INDEX IDX_17BDE61F223E1F4B ON upload (mailing_template_id)');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE upload DROP FOREIGN KEY FK_17BDE61F223E1F4B');
|
|
$this->addSql('DROP INDEX IDX_17BDE61F223E1F4B ON upload');
|
|
$this->addSql('ALTER TABLE upload DROP mailing_template_id');
|
|
$this->addSql('ALTER TABLE mailing DROP FOREIGN KEY FK_3ED9315E5DA0FB8');
|
|
$this->addSql('ALTER TABLE mailing_assignment DROP FOREIGN KEY FK_D6941DCB3931AB76');
|
|
$this->addSql('ALTER TABLE mailing_assignment DROP FOREIGN KEY FK_D6941DCBD19302F8');
|
|
$this->addSql('ALTER TABLE mailing_attachment DROP FOREIGN KEY FK_9F0E80CA3931AB76');
|
|
$this->addSql('ALTER TABLE mailing_attachment DROP FOREIGN KEY FK_9F0E80CACCCFBA31');
|
|
$this->addSql('DROP TABLE mailing_attachment');
|
|
$this->addSql('DROP TABLE mailing_assignment');
|
|
$this->addSql('DROP TABLE mailing');
|
|
$this->addSql('DROP TABLE mailing_template');
|
|
}
|
|
}
|