<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220115020721 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 cars__brands (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, type VARCHAR(255) DEFAULT \'vehicle\' NOT NULL, INDEX type (type), UNIQUE INDEX name (name, type), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE cars__chassis (id INT AUTO_INCREMENT NOT NULL, model_id INT NOT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_AA72D6117975B7E7 (model_id), INDEX name (name), UNIQUE INDEX model_id_name_uniq (model_id, name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE cars__engines (id INT AUTO_INCREMENT NOT NULL, model_id INT NOT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_17543D427975B7E7 (model_id), INDEX name (name), UNIQUE INDEX model_id_name_uniq (model_id, name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE cars__models (id INT AUTO_INCREMENT NOT NULL, brand_id INT NOT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_E0975B4F44F5D008 (brand_id), INDEX name (name), UNIQUE INDEX brand_id_name_uniq (brand_id, name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE cars__sets (id INT AUTO_INCREMENT NOT NULL, engine_id INT DEFAULT NULL, chassis_id INT DEFAULT NULL, INDEX IDX_666D7550E78C9C0A (engine_id), INDEX IDX_666D755063EE729 (chassis_id), UNIQUE INDEX engine_chassis_uniq (engine_id, chassis_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE cars__chassis ADD CONSTRAINT FK_AA72D6117975B7E7 FOREIGN KEY (model_id) REFERENCES cars__models (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE cars__engines ADD CONSTRAINT FK_17543D427975B7E7 FOREIGN KEY (model_id) REFERENCES cars__models (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE cars__models ADD CONSTRAINT FK_E0975B4F44F5D008 FOREIGN KEY (brand_id) REFERENCES cars__brands (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE cars__sets ADD CONSTRAINT FK_666D7550E78C9C0A FOREIGN KEY (engine_id) REFERENCES cars__engines (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE cars__sets ADD CONSTRAINT FK_666D755063EE729 FOREIGN KEY (chassis_id) REFERENCES cars__chassis (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE cars__models DROP FOREIGN KEY FK_E0975B4F44F5D008');
$this->addSql('ALTER TABLE cars__sets DROP FOREIGN KEY FK_666D755063EE729');
$this->addSql('ALTER TABLE cars__sets DROP FOREIGN KEY FK_666D7550E78C9C0A');
$this->addSql('ALTER TABLE cars__chassis DROP FOREIGN KEY FK_AA72D6117975B7E7');
$this->addSql('ALTER TABLE cars__engines DROP FOREIGN KEY FK_17543D427975B7E7');
$this->addSql('DROP TABLE cars__brands');
$this->addSql('DROP TABLE cars__chassis');
$this->addSql('DROP TABLE cars__engines');
$this->addSql('DROP TABLE cars__models');
$this->addSql('DROP TABLE cars__sets');
}
}