<?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 Version20220921083527 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 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))');
$this->addSql('CREATE INDEX IDX_64C19C1B03A8386 ON category (created_by_id)');
$this->addSql('CREATE TABLE news_tag (news_id INT NOT NULL, tag_id INT NOT NULL, PRIMARY KEY(news_id, tag_id))');
$this->addSql('CREATE INDEX IDX_BE3ED8A1B5A459A0 ON news_tag (news_id)');
$this->addSql('CREATE INDEX IDX_BE3ED8A1BAD26311 ON news_tag (tag_id)');
$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))');
$this->addSql('CREATE INDEX IDX_389B783B03A8386 ON tag (created_by_id)');
$this->addSql('ALTER TABLE category ADD CONSTRAINT FK_64C19C1B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE news_tag ADD CONSTRAINT FK_BE3ED8A1B5A459A0 FOREIGN KEY (news_id) REFERENCES news (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE news_tag ADD CONSTRAINT FK_BE3ED8A1BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE tag ADD CONSTRAINT FK_389B783B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE news ADD category_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE news ADD CONSTRAINT FK_1DD3995012469DE2 FOREIGN KEY (category_id) REFERENCES category (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_1DD3995012469DE2 ON news (category_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE news DROP CONSTRAINT FK_1DD3995012469DE2');
$this->addSql('ALTER TABLE category DROP CONSTRAINT FK_64C19C1B03A8386');
$this->addSql('ALTER TABLE news_tag DROP CONSTRAINT FK_BE3ED8A1B5A459A0');
$this->addSql('ALTER TABLE news_tag DROP CONSTRAINT FK_BE3ED8A1BAD26311');
$this->addSql('ALTER TABLE tag DROP CONSTRAINT FK_389B783B03A8386');
$this->addSql('DROP TABLE category');
$this->addSql('DROP TABLE news_tag');
$this->addSql('DROP TABLE tag');
$this->addSql('DROP INDEX IDX_1DD3995012469DE2');
$this->addSql('ALTER TABLE news DROP category_id');
}
}