<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20251201000000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create dtb_banner table for banner management';
}
public function up(Schema $schema): void
{
// Kiểm tra xem bảng dtb_banner đã tồn tại chưa
if (!$schema->hasTable('dtb_banner')) {
$table = $schema->createTable('dtb_banner');
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
'unsigned' => true,
'comment' => 'Primary key, auto increment'
]);
$table->setPrimaryKey(['id']);
$table->addColumn('image_path', 'string', [
'length' => 255,
'notnull' => true,
'comment' => 'Banner image path'
]);
$table->addColumn('link_url', 'string', [
'length' => 4000,
'notnull' => false,
'comment' => 'Banner link URL'
]);
$table->addColumn('title', 'string', [
'length' => 255,
'notnull' => false,
'comment' => 'Banner title (optional)'
]);
$table->addColumn('description', 'text', [
'notnull' => false,
'comment' => 'Banner description (optional)'
]);
$table->addColumn('sort_no', 'integer', [
'notnull' => true,
'default' => 0,
'unsigned' => true,
'comment' => 'Sort order for display'
]);
$table->addColumn('status', 'smallint', [
'notnull' => true,
'default' => 1,
'comment' => 'Status: 0=OFF, 1=ON'
]);
$table->addColumn('create_date', 'datetimetz', [
'notnull' => true,
'comment' => 'Creation date'
]);
$table->addColumn('update_date', 'datetimetz', [
'notnull' => true,
'comment' => 'Update date'
]);
// Add index for sort_no for better performance
$table->addIndex(['sort_no'], 'dtb_banner_sort_no_idx');
$table->addIndex(['status'], 'dtb_banner_status_idx');
}
}
public function down(Schema $schema): void
{
if ($schema->hasTable('dtb_banner')) {
$schema->dropTable('dtb_banner');
}
}
}