migrations/Version20220422111513.php line 1

Open in your IDE?
  1. <?php
  2. /* @noinspection PhpUnused */
  3. declare(strict_types=1);
  4. namespace DoctrineMigrations;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  *
  10.  * @package API
  11.  * @internal
  12.  */
  13. final class Version20220422111513 extends AbstractMigration
  14. {
  15.     public function down(Schema $schema): void
  16.     {
  17.         // this down() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('ALTER TABLE protective_gear_l10n DROP FOREIGN KEY FK_5204FE3D706E52B3');
  19.         $this->addSql('ALTER TABLE protective_gear_l10n DROP FOREIGN KEY FK_5204FE3D6A2856C7');
  20.         $this->addSql('ALTER TABLE protective_gear DROP FOREIGN KEY FK_EA3B186612469DE2');
  21.         $this->addSql('ALTER TABLE protective_gear_category_l10n DROP FOREIGN KEY FK_1EA080C4706E52B3');
  22.         $this->addSql('ALTER TABLE protective_gear_category_l10n DROP FOREIGN KEY FK_1EA080C46A2856C7');
  23.         $this->addSql('DROP TABLE protective_gear');
  24.         $this->addSql('DROP TABLE protective_gear_category');
  25.         $this->addSql('DROP TABLE protective_gear_category_l10n');
  26.         $this->addSql('DROP TABLE protective_gear_l10n');
  27.     }
  28.     public function getDescription(): string
  29.     {
  30.         return
  31.             "- Introduces protective gear table and localizations.\n" .
  32.             "- Introduces protective gear category table and localizations.";
  33.     }
  34.     public function up(Schema $schema): void
  35.     {
  36.         // this up() migration is auto-generated, please modify it to your needs
  37.         $this->addSql(
  38.             '
  39.                 CREATE TABLE protective_gear (
  40.                     id INT AUTO_INCREMENT NOT NULL COMMENT \'Internal ID\',
  41.                     created INT NOT NULL COMMENT \'Entity creation date as UNIX timestamp\',
  42.                     category_id INT DEFAULT NULL COMMENT \'Internal ID\',
  43.                     active SMALLINT DEFAULT 1 NOT NULL COMMENT \'Indicator if entity is active\',
  44.                     last_active_date DATE DEFAULT NULL COMMENT \'Last active date\',
  45.                     INDEX IDX_EA3B186612469DE2 (category_id),
  46.                     PRIMARY KEY(id)
  47.                 ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  48.             '
  49.         );
  50.         $this->addSql(
  51.             '
  52.                 CREATE TABLE protective_gear_category (
  53.                     id INT AUTO_INCREMENT NOT NULL COMMENT \'Internal ID\',
  54.                     created INT NOT NULL COMMENT \'Entity creation date as UNIX timestamp\',
  55.                     active SMALLINT DEFAULT 1 NOT NULL COMMENT \'Indicator if entity is active\',
  56.                     last_active_date DATE DEFAULT NULL COMMENT \'Last active date\',
  57.                     PRIMARY KEY(id)
  58.                 ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  59.             '
  60.         );
  61.         $this->addSql(
  62.             '
  63.                 CREATE TABLE protective_gear_category_l10n (
  64.                     language_id VARCHAR(2) NOT NULL COMMENT \'Language code in lower case (ISO 639-1)\',
  65.                     parent_entity_id INT NOT NULL COMMENT \'Internal ID\',
  66.                     name VARCHAR(225) DEFAULT NULL COMMENT \'Protective gear category name in referenced language\',
  67.                     INDEX IDX_1EA080C482F1BAF4 (language_id),
  68.                     INDEX IDX_1EA080C4706E52B3 (parent_entity_id),
  69.                     PRIMARY KEY(parent_entity_id, language_id)
  70.                 ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  71.             '
  72.         );
  73.         $this->addSql(
  74.             '
  75.                 CREATE TABLE protective_gear_l10n (
  76.                     language_id VARCHAR(2) NOT NULL COMMENT \'Language code in lower case (ISO 639-1)\',
  77.                     parent_entity_id INT NOT NULL COMMENT \'Internal ID\',
  78.                     name VARCHAR(225) DEFAULT NULL COMMENT \'Protective gear name in referenced language\',
  79.                     INDEX IDX_5204FE3D82F1BAF4 (language_id),
  80.                     INDEX IDX_5204FE3D706E52B3 (parent_entity_id),
  81.                     PRIMARY KEY(parent_entity_id, language_id)
  82.                 ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  83.             '
  84.         );
  85.         $this->addSql(
  86.             '
  87.                 ALTER TABLE protective_gear ADD CONSTRAINT FK_EA3B186612469DE2 FOREIGN KEY
  88.                     (category_id) REFERENCES protective_gear_category (id) ON DELETE SET NULL
  89.             '
  90.         );
  91.         $this->addSql(
  92.             '
  93.                 ALTER TABLE protective_gear_category_l10n ADD CONSTRAINT FK_1EA080C46A2856C7 FOREIGN KEY
  94.                     (language_id) REFERENCES language (id) ON DELETE CASCADE
  95.             '
  96.         );
  97.         $this->addSql(
  98.             '
  99.                 ALTER TABLE protective_gear_category_l10n ADD CONSTRAINT FK_1EA080C4706E52B3 FOREIGN KEY
  100.                     (parent_entity_id) REFERENCES protective_gear_category (id) ON DELETE CASCADE
  101.             '
  102.         );
  103.         $this->addSql(
  104.             '
  105.                 ALTER TABLE protective_gear_l10n ADD CONSTRAINT FK_5204FE3D6A2856C7 FOREIGN KEY
  106.                     (language_id) REFERENCES language (id) ON DELETE CASCADE
  107.             '
  108.         );
  109.         $this->addSql(
  110.             '
  111.                 ALTER TABLE protective_gear_l10n ADD CONSTRAINT FK_5204FE3D706E52B3 FOREIGN KEY
  112.                     (parent_entity_id) REFERENCES protective_gear (id) ON DELETE CASCADE
  113.             '
  114.         );
  115.     }
  116. }