<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250911075525 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create dtb_mail_queue table for email queue management';
}
public function up(Schema $schema): void
{
// Kiểm tra xem bảng mail_queue đã tồn tại chưa
if (!$schema->hasTable('dtb_mail_queue')) {
$table = $schema->createTable('dtb_mail_queue');
$table->addColumn('id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
'comment' => 'Primary key, auto increment'
]);
$table->setPrimaryKey(['id']);
$table->addColumn('user_id', 'integer', [
'notnull' => true,
'comment' => 'User ID'
]);
$table->addColumn('event_type', 'smallint', [
'notnull' => true,
'comment' => 'Event type: 11-temporary user email confirmation, 2-activation success, 3-user info update'
]);
$table->addColumn('email', 'string', [
'length' => 255,
'notnull' => true,
'comment' => 'Recipient email'
]);
$table->addColumn('link', 'string', [
'length' => 255,
'notnull' => false,
'comment' => 'Link (if any)'
]);
$table->addColumn('status', 'smallint', [
'notnull' => true,
'default' => 0,
'comment' => 'Status: 0-todo (default), 1-sent successfully, 2-send failed'
]);
$table->addColumn('created_at', 'datetime', [
'notnull' => true,
'default' => 'CURRENT_TIMESTAMP',
'comment' => 'Creation time'
]);
$table->addColumn('updated_at', 'datetime', [
'notnull' => true,
'default' => 'CURRENT_TIMESTAMP',
'comment' => 'Update time'
]);
$table->addColumn('sent_at', 'datetime', [
'notnull' => false,
'comment' => 'Time when email was sent successfully'
]);
// Tạo cột last_error - TEXT, NULL
$table->addColumn('last_error', 'text', [
'notnull' => false,
'comment' => 'Error information (if any)'
]);
$table->addUniqueIndex(['user_id', 'event_type'], 'unique_user_event');
}
}
public function down(Schema $schema): void
{
// Kiểm tra xem bảng mail_queue có tồn tại không trước khi xóa
if ($schema->hasTable('dtb_mail_queue')) {
$schema->dropTable('dtb_mail_queue');
}
}
}