migrations/Version20220921083527.php line 1

Open in your IDE?
  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 Version20220921083527 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('CREATE TABLE category (id SERIAL NOT NULL, created_by_id INT NOT NULL, name VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY(id))');
  19.         $this->addSql('CREATE INDEX IDX_64C19C1B03A8386 ON category (created_by_id)');
  20.         $this->addSql('CREATE TABLE news_tag (news_id INT NOT NULL, tag_id INT NOT NULL, PRIMARY KEY(news_id, tag_id))');
  21.         $this->addSql('CREATE INDEX IDX_BE3ED8A1B5A459A0 ON news_tag (news_id)');
  22.         $this->addSql('CREATE INDEX IDX_BE3ED8A1BAD26311 ON news_tag (tag_id)');
  23.         $this->addSql('CREATE TABLE tag (id SERIAL NOT NULL, created_by_id INT NOT NULL, name VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY(id))');
  24.         $this->addSql('CREATE INDEX IDX_389B783B03A8386 ON tag (created_by_id)');
  25.         $this->addSql('ALTER TABLE category ADD CONSTRAINT FK_64C19C1B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  26.         $this->addSql('ALTER TABLE news_tag ADD CONSTRAINT FK_BE3ED8A1B5A459A0 FOREIGN KEY (news_id) REFERENCES news (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
  27.         $this->addSql('ALTER TABLE news_tag ADD CONSTRAINT FK_BE3ED8A1BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
  28.         $this->addSql('ALTER TABLE tag ADD CONSTRAINT FK_389B783B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  29.         $this->addSql('ALTER TABLE news ADD category_id INT DEFAULT NULL');
  30.         $this->addSql('ALTER TABLE news ADD CONSTRAINT FK_1DD3995012469DE2 FOREIGN KEY (category_id) REFERENCES category (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  31.         $this->addSql('CREATE INDEX IDX_1DD3995012469DE2 ON news (category_id)');
  32.     }
  33.     public function down(Schema $schema): void
  34.     {
  35.         // this down() migration is auto-generated, please modify it to your needs
  36.         $this->addSql('ALTER TABLE news DROP CONSTRAINT FK_1DD3995012469DE2');
  37.         $this->addSql('ALTER TABLE category DROP CONSTRAINT FK_64C19C1B03A8386');
  38.         $this->addSql('ALTER TABLE news_tag DROP CONSTRAINT FK_BE3ED8A1B5A459A0');
  39.         $this->addSql('ALTER TABLE news_tag DROP CONSTRAINT FK_BE3ED8A1BAD26311');
  40.         $this->addSql('ALTER TABLE tag DROP CONSTRAINT FK_389B783B03A8386');
  41.         $this->addSql('DROP TABLE category');
  42.         $this->addSql('DROP TABLE news_tag');
  43.         $this->addSql('DROP TABLE tag');
  44.         $this->addSql('DROP INDEX IDX_1DD3995012469DE2');
  45.         $this->addSql('ALTER TABLE news DROP category_id');
  46.     }
  47. }