src/Migrations/Version20201026145106.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20201026145106 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('delete from university_category_relation');
  19.         $this->addSql('ALTER TABLE university_category_relation DROP FOREIGN KEY FK_EFBAC27D21D6F15');
  20.         $this->addSql('CREATE TABLE universities (id INT AUTO_INCREMENT NOT NULL, organisation_id INT DEFAULT NULL, have_dorm TINYINT(1) DEFAULT \'0\' NOT NULL, have_military_department TINYINT(1) DEFAULT \'0\' NOT NULL, UNIQUE INDEX UNIQ_E36065DE9E6B1585 (organisation_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  21.         $this->addSql('CREATE TABLE university_category (id INT AUTO_INCREMENT NOT NULL, created_by_id INT DEFAULT NULL, updated_by_id INT DEFAULT NULL, caption VARCHAR(255) NOT NULL, weight INT DEFAULT 10 NOT NULL, deleted TINYINT(1) DEFAULT \'0\' NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, active TINYINT(1) DEFAULT \'1\' NOT NULL, INDEX IDX_BE513B6BB03A8386 (created_by_id), INDEX IDX_BE513B6B896DBBDE (updated_by_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  22.         $this->addSql('ALTER TABLE universities ADD CONSTRAINT FK_E36065DE9E6B1585 FOREIGN KEY (organisation_id) REFERENCES organisation (id)');
  23.         $this->addSql('ALTER TABLE university_category ADD CONSTRAINT FK_BE513B6BB03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)');
  24.         $this->addSql('ALTER TABLE university_category ADD CONSTRAINT FK_BE513B6B896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)');
  25.         $this->addSql('DROP TABLE university_categories');
  26.         $this->addSql('ALTER TABLE organisation ADD address LONGTEXT DEFAULT NULL, DROP have_dorm, DROP have_military_department');
  27.         $this->addSql('ALTER TABLE university_category_relation DROP FOREIGN KEY FK_EFBAC27D9E6B1585');
  28.         $this->addSql('DROP INDEX IDX_EFBAC27D9E6B1585 ON university_category_relation');
  29.         $this->addSql('DROP INDEX IDX_EFBAC27D21D6F15 ON university_category_relation');
  30.         $this->addSql('ALTER TABLE university_category_relation DROP PRIMARY KEY');
  31.         $this->addSql('ALTER TABLE university_category_relation ADD university_id INT NOT NULL, ADD category_id INT NOT NULL, DROP organisation_id, DROP university_category_id');
  32.         $this->addSql('ALTER TABLE university_category_relation ADD CONSTRAINT FK_EFBAC27D309D1878 FOREIGN KEY (university_id) REFERENCES universities (id) ON DELETE CASCADE');
  33.         $this->addSql('ALTER TABLE university_category_relation ADD CONSTRAINT FK_EFBAC27D12469DE2 FOREIGN KEY (category_id) REFERENCES university_category (id) ON DELETE CASCADE');
  34.         $this->addSql('CREATE INDEX IDX_EFBAC27D309D1878 ON university_category_relation (university_id)');
  35.         $this->addSql('CREATE INDEX IDX_EFBAC27D12469DE2 ON university_category_relation (category_id)');
  36.         $this->addSql('ALTER TABLE university_category_relation ADD PRIMARY KEY (university_id, category_id)');
  37.     }
  38.     public function down(Schema $schema): void
  39.     {
  40.         // this down() migration is auto-generated, please modify it to your needs
  41.         $this->addSql('ALTER TABLE university_category_relation DROP FOREIGN KEY FK_EFBAC27D309D1878');
  42.         $this->addSql('ALTER TABLE university_category_relation DROP FOREIGN KEY FK_EFBAC27D12469DE2');
  43.         $this->addSql('CREATE TABLE university_categories (id INT AUTO_INCREMENT NOT NULL, created_by_id INT DEFAULT NULL, updated_by_id INT DEFAULT NULL, caption VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, deleted TINYINT(1) DEFAULT \'0\' NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, active TINYINT(1) DEFAULT \'1\' NOT NULL, weight INT DEFAULT 10 NOT NULL, INDEX IDX_BB7BEBF2896DBBDE (updated_by_id), INDEX IDX_BB7BEBF2B03A8386 (created_by_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
  44.         $this->addSql('ALTER TABLE university_categories ADD CONSTRAINT FK_BB7BEBF2896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)');
  45.         $this->addSql('ALTER TABLE university_categories ADD CONSTRAINT FK_BB7BEBF2B03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)');
  46.         $this->addSql('DROP TABLE universities');
  47.         $this->addSql('DROP TABLE university_category');
  48.         $this->addSql('ALTER TABLE organisation ADD have_dorm TINYINT(1) DEFAULT \'0\' NOT NULL, ADD have_military_department TINYINT(1) DEFAULT \'0\' NOT NULL, DROP address');
  49.         $this->addSql('DROP INDEX IDX_EFBAC27D309D1878 ON university_category_relation');
  50.         $this->addSql('DROP INDEX IDX_EFBAC27D12469DE2 ON university_category_relation');
  51.         $this->addSql('ALTER TABLE university_category_relation DROP PRIMARY KEY');
  52.         $this->addSql('ALTER TABLE university_category_relation ADD organisation_id INT NOT NULL, ADD university_category_id INT NOT NULL, DROP university_id, DROP category_id');
  53.         $this->addSql('ALTER TABLE university_category_relation ADD CONSTRAINT FK_EFBAC27D21D6F15 FOREIGN KEY (university_category_id) REFERENCES university_categories (id) ON DELETE CASCADE');
  54.         $this->addSql('ALTER TABLE university_category_relation ADD CONSTRAINT FK_EFBAC27D9E6B1585 FOREIGN KEY (organisation_id) REFERENCES organisation (id) ON DELETE CASCADE');
  55.         $this->addSql('CREATE INDEX IDX_EFBAC27D9E6B1585 ON university_category_relation (organisation_id)');
  56.         $this->addSql('CREATE INDEX IDX_EFBAC27D21D6F15 ON university_category_relation (university_category_id)');
  57.         $this->addSql('ALTER TABLE university_category_relation ADD PRIMARY KEY (organisation_id, university_category_id)');
  58.     }
  59. }