migrations/Version20230214081937.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\Enum\LocaleEnum;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  */
  10. final class Version20230214081937 extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return '';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         // this up() migration is auto-generated, please modify it to your needs
  19.         $this->addSql('CREATE TABLE location_translation (id INT AUTO_INCREMENT NOT NULL, location_id INT NOT NULL, created_by_id INT NOT NULL, updated_by_id INT DEFAULT NULL, locale VARCHAR(255) NOT NULL, headquarter VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, city VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_A2BCA22B64D218E (location_id), INDEX IDX_A2BCA22BB03A8386 (created_by_id), INDEX IDX_A2BCA22B896DBBDE (updated_by_id), UNIQUE INDEX UNIQ_A2BCA22B64D218E4180C698 (location_id, locale), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  20.         $this->addSql('ALTER TABLE location_translation ADD CONSTRAINT FK_A2BCA22B64D218E FOREIGN KEY (location_id) REFERENCES location (id)');
  21.         $this->addSql('ALTER TABLE location_translation ADD CONSTRAINT FK_A2BCA22BB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  22.         $this->addSql('ALTER TABLE location_translation ADD CONSTRAINT FK_A2BCA22B896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  23.         $this->addSql('
  24.             INSERT INTO location_translation
  25.             (location_id, locale, headquarter, description, city, created_by_id, created_at)
  26.             SELECT id, :locale, headquarter_hu, description_hu, city_hu, created_by_id, COALESCE(updated_at, NOW())
  27.             FROM location
  28.         ', ['locale' => LocaleEnum::HUNGARIAN]);
  29.         $this->addSql('ALTER TABLE location DROP headquarter_hu, DROP description_hu, DROP city_hu');
  30.     }
  31.     public function down(Schema $schema): void
  32.     {
  33.         // this down() migration is auto-generated, please modify it to your needs
  34.         $this->addSql('DROP TABLE location_translation');
  35.         $this->addSql('ALTER TABLE location ADD headquarter_hu VARCHAR(255) DEFAULT NULL, ADD description_hu LONGTEXT DEFAULT NULL, ADD city_hu VARCHAR(255) NOT NULL');
  36.     }
  37. }