migrations/Version20230602091757.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. final class Version20230602091757 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add likes for wiki post';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         // this up() migration is auto-generated, please modify it to your needs
  15.         $this->addSql('CREATE TABLE wiki_post_like (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, post_id INT DEFAULT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_6E063E9CA76ED395 (user_id), INDEX IDX_6E063E9C4B89032C (post_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
  16.         $this->addSql('ALTER TABLE wiki_post_like ADD CONSTRAINT FK_6E063E9CA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
  17.         $this->addSql('ALTER TABLE wiki_post_like ADD CONSTRAINT FK_6E063E9C4B89032C FOREIGN KEY (post_id) REFERENCES wiki_post (id)');
  18.         $this->addSql('ALTER TABLE wiki_post CHANGE created_at created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL');
  19.     }
  20.     public function down(Schema $schema): void
  21.     {
  22.         // this down() migration is auto-generated, please modify it to your needs
  23.         $this->addSql('ALTER TABLE wiki_post_like DROP FOREIGN KEY FK_6E063E9CA76ED395');
  24.         $this->addSql('ALTER TABLE wiki_post_like DROP FOREIGN KEY FK_6E063E9C4B89032C');
  25.         $this->addSql('DROP TABLE wiki_post_like');
  26.         $this->addSql('ALTER TABLE wiki_post CHANGE created_at created_at DATETIME NOT NULL');
  27.     }
  28. }