<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230227091315 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add notification info table';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->hasTable('notification'),
'The notification table already exists!'
);
$table = $schema->createTable('notification');
$table->addColumn('id', Types::GUID)->setNotnull(true);
$table->addColumn('created_at', Types::DATETIME_IMMUTABLE)->setNotnull(true);
$table->addColumn('read_at', Types::DATETIME_IMMUTABLE)->setNotnull(false);
$table->addColumn('title', Types::STRING, ['length' => 255])->setNotnull(true);
$table->addColumn('content', Types::STRING, ['length' => 255])->setNotnull(false);
$table->addColumn('type', Types::STRING, ['length' => 30])->setNotnull(false);
$table->addColumn('external_link', Types::STRING, ['length' => 255])->setNotnull(false);
$table->addColumn('my_cmcm_user_id', Types::GUID)->setNotnull(true);
$table->setPrimaryKey(['id']);
$myCmcmUserTable = $schema->getTable('mycmcm_user');
$table->addForeignKeyConstraint(
$myCmcmUserTable,
['my_cmcm_user_id'],
['id'],
[],
'fk_notification_my_cmcm_user'
);
$table->addIndex(['my_cmcm_user_id'], 'idx_notification_my_cmcm_user_id');
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->hasTable('notification'),
'The notification table is already removed !'
);
$schema->dropTable('notification');
}
}