<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use App\Enum\LocaleEnum;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230214081937 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$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');
$this->addSql('ALTER TABLE location_translation ADD CONSTRAINT FK_A2BCA22B64D218E FOREIGN KEY (location_id) REFERENCES location (id)');
$this->addSql('ALTER TABLE location_translation ADD CONSTRAINT FK_A2BCA22BB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE location_translation ADD CONSTRAINT FK_A2BCA22B896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('
INSERT INTO location_translation
(location_id, locale, headquarter, description, city, created_by_id, created_at)
SELECT id, :locale, headquarter_hu, description_hu, city_hu, created_by_id, COALESCE(updated_at, NOW())
FROM location
', ['locale' => LocaleEnum::HUNGARIAN]);
$this->addSql('ALTER TABLE location DROP headquarter_hu, DROP description_hu, DROP city_hu');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE location_translation');
$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');
}
}