app/DoctrineMigrations/Version20250911075525.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\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20250911075525 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Create dtb_mail_queue table for email queue management';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // Kiểm tra xem bảng mail_queue đã tồn tại chưa
  18.         if (!$schema->hasTable('dtb_mail_queue')) {
  19.             $table $schema->createTable('dtb_mail_queue');
  20.             
  21.             $table->addColumn('id''bigint', [
  22.                 'autoincrement' => true,
  23.                 'notnull' => true,
  24.                 'comment' => 'Primary key, auto increment'
  25.             ]);
  26.             $table->setPrimaryKey(['id']);
  27.             
  28.             $table->addColumn('user_id''integer', [
  29.                 'notnull' => true,
  30.                 'comment' => 'User ID'
  31.             ]);
  32.             
  33.             $table->addColumn('event_type''smallint', [
  34.                 'notnull' => true,
  35.                 'comment' => 'Event type: 11-temporary user email confirmation, 2-activation success, 3-user info update'
  36.             ]);
  37.             
  38.             $table->addColumn('email''string', [
  39.                 'length' => 255,
  40.                 'notnull' => true,
  41.                 'comment' => 'Recipient email'
  42.             ]);
  43.             
  44.             $table->addColumn('link''string', [
  45.                 'length' => 255,
  46.                 'notnull' => false,
  47.                 'comment' => 'Link (if any)'
  48.             ]);
  49.             
  50.             $table->addColumn('status''smallint', [
  51.                 'notnull' => true,
  52.                 'default' => 0,
  53.                 'comment' => 'Status: 0-todo (default), 1-sent successfully, 2-send failed'
  54.             ]);
  55.             
  56.             $table->addColumn('created_at''datetime', [
  57.                 'notnull' => true,
  58.                 'default' => 'CURRENT_TIMESTAMP',
  59.                 'comment' => 'Creation time'
  60.             ]);
  61.             
  62.             $table->addColumn('updated_at''datetime', [
  63.                 'notnull' => true,
  64.                 'default' => 'CURRENT_TIMESTAMP',
  65.                 'comment' => 'Update time'
  66.             ]);
  67.             
  68.             $table->addColumn('sent_at''datetime', [
  69.                 'notnull' => false,
  70.                 'comment' => 'Time when email was sent successfully'
  71.             ]);
  72.             
  73.             // Tạo cột last_error - TEXT, NULL
  74.             $table->addColumn('last_error''text', [
  75.                 'notnull' => false,
  76.                 'comment' => 'Error information (if any)'
  77.             ]);
  78.             
  79.             $table->addUniqueIndex(['user_id''event_type'], 'unique_user_event');
  80.         }
  81.     }
  82.     public function down(Schema $schema): void
  83.     {
  84.         // Kiểm tra xem bảng mail_queue có tồn tại không trước khi xóa
  85.         if ($schema->hasTable('dtb_mail_queue')) {
  86.             $schema->dropTable('dtb_mail_queue');
  87.         }
  88.     }
  89. }