migrations/Version20230227091315.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\DBAL\Types\Types;
  6. use Doctrine\Migrations\AbstractMigration;
  7. final class Version20230227091315 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add notification info table';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->hasTable('notification'),
  17.             'The notification table already exists!'
  18.         );
  19.         $table $schema->createTable('notification');
  20.         $table->addColumn('id'Types::GUID)->setNotnull(true);
  21.         $table->addColumn('created_at'Types::DATETIME_IMMUTABLE)->setNotnull(true);
  22.         $table->addColumn('read_at'Types::DATETIME_IMMUTABLE)->setNotnull(false);
  23.         $table->addColumn('title'Types::STRING, ['length' => 255])->setNotnull(true);
  24.         $table->addColumn('content'Types::STRING, ['length' => 255])->setNotnull(false);
  25.         $table->addColumn('type'Types::STRING, ['length' => 30])->setNotnull(false);
  26.         $table->addColumn('external_link'Types::STRING, ['length' => 255])->setNotnull(false);
  27.         $table->addColumn('my_cmcm_user_id'Types::GUID)->setNotnull(true);
  28.         $table->setPrimaryKey(['id']);
  29.         $myCmcmUserTable $schema->getTable('mycmcm_user');
  30.         $table->addForeignKeyConstraint(
  31.             $myCmcmUserTable,
  32.             ['my_cmcm_user_id'],
  33.             ['id'],
  34.             [],
  35.             'fk_notification_my_cmcm_user'
  36.         );
  37.         $table->addIndex(['my_cmcm_user_id'], 'idx_notification_my_cmcm_user_id');
  38.     }
  39.     public function down(Schema $schema): void
  40.     {
  41.         $this->skipIf(
  42.             false === $schema->hasTable('notification'),
  43.             'The notification table is already removed !'
  44.         );
  45.         $schema->dropTable('notification');
  46.     }
  47. }