migrations/Version20230312162901.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 Version20230312162901 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add audit table';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('CREATE TABLE creator_audit (id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, creator_id BIGINT UNSIGNED DEFAULT NULL, status VARCHAR(255) NOT NULL, report JSON DEFAULT (JSON_ARRAY()) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_1D0BE9C761220EA6 (creator_id), INDEX status (status, created_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
  15.         $this->addSql('ALTER TABLE creator_audit ADD CONSTRAINT FK_1D0BE9C761220EA6 FOREIGN KEY (creator_id) REFERENCES creator (id)');
  16.         $this->addSql('ALTER TABLE creator ADD creator_audit_id BIGINT UNSIGNED DEFAULT NULL');
  17.         $this->addSql('ALTER TABLE creator ADD CONSTRAINT FK_BC06EA63EACFD4C5 FOREIGN KEY (creator_audit_id) REFERENCES creator_audit (id)');
  18.         $this->addSql('CREATE UNIQUE INDEX UNIQ_BC06EA63EACFD4C5 ON creator (creator_audit_id)');
  19.     }
  20.     public function down(Schema $schema): void
  21.     {
  22.         $this->addSql('ALTER TABLE creator DROP FOREIGN KEY FK_BC06EA63EACFD4C5');
  23.         $this->addSql('DROP TABLE creator_audit');
  24.         $this->addSql('DROP INDEX UNIQ_BC06EA63EACFD4C5 ON creator');
  25.         $this->addSql('ALTER TABLE creator DROP creator_audit_id');
  26.      }
  27.     public function isTransactional(): bool
  28.     {
  29.         return false;
  30.     }
  31. }