48 lines
1.8 KiB
PHP
48 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
/**
|
|
* Class Version20250526101759.
|
|
*
|
|
* @author bernard-ng <bernard@devscast.tech>
|
|
*/
|
|
final class Version20250526101759 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'add comment table with foreign keys to user and article tables';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql(<<<'SQL'
|
|
CREATE TABLE comment (id BINARY(16) NOT NULL COMMENT '(DC2Type:comment_id)', user_id BINARY(16) NOT NULL COMMENT '(DC2Type:user_id)', article_id BINARY(16) NOT NULL COMMENT '(DC2Type:article_id)', content VARCHAR(512) NOT NULL, sentiment VARCHAR(30) DEFAULT 'neutral' NOT NULL, is_spam TINYINT(1) DEFAULT 0 NOT NULL, created_at DATETIME NOT NULL COMMENT '(DC2Type:datetime_immutable)', INDEX IDX_9474526CA76ED395 (user_id), INDEX IDX_9474526C7294869C (article_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
|
|
SQL);
|
|
$this->addSql(<<<'SQL'
|
|
ALTER TABLE comment ADD CONSTRAINT FK_9474526CA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
|
|
SQL);
|
|
$this->addSql(<<<'SQL'
|
|
ALTER TABLE comment ADD CONSTRAINT FK_9474526C7294869C FOREIGN KEY (article_id) REFERENCES article (id) ON DELETE CASCADE
|
|
SQL);
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql(<<<'SQL'
|
|
ALTER TABLE comment DROP FOREIGN KEY FK_9474526CA76ED395
|
|
SQL);
|
|
$this->addSql(<<<'SQL'
|
|
ALTER TABLE comment DROP FOREIGN KEY FK_9474526C7294869C
|
|
SQL);
|
|
$this->addSql(<<<'SQL'
|
|
DROP TABLE comment
|
|
SQL);
|
|
}
|
|
}
|