app/DoctrineMigrations/Version20251201000000.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. final class Version20251201000000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Create dtb_banner table for banner management';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         // Kiểm tra xem bảng dtb_banner đã tồn tại chưa
  15.         if (!$schema->hasTable('dtb_banner')) {
  16.             $table $schema->createTable('dtb_banner');
  17.             $table->addColumn('id''integer', [
  18.                 'autoincrement' => true,
  19.                 'notnull' => true,
  20.                 'unsigned' => true,
  21.                 'comment' => 'Primary key, auto increment'
  22.             ]);
  23.             $table->setPrimaryKey(['id']);
  24.             $table->addColumn('image_path''string', [
  25.                 'length' => 255,
  26.                 'notnull' => true,
  27.                 'comment' => 'Banner image path'
  28.             ]);
  29.             $table->addColumn('link_url''string', [
  30.                 'length' => 4000,
  31.                 'notnull' => false,
  32.                 'comment' => 'Banner link URL'
  33.             ]);
  34.             $table->addColumn('title''string', [
  35.                 'length' => 255,
  36.                 'notnull' => false,
  37.                 'comment' => 'Banner title (optional)'
  38.             ]);
  39.             $table->addColumn('description''text', [
  40.                 'notnull' => false,
  41.                 'comment' => 'Banner description (optional)'
  42.             ]);
  43.             $table->addColumn('sort_no''integer', [
  44.                 'notnull' => true,
  45.                 'default' => 0,
  46.                 'unsigned' => true,
  47.                 'comment' => 'Sort order for display'
  48.             ]);
  49.             $table->addColumn('status''smallint', [
  50.                 'notnull' => true,
  51.                 'default' => 1,
  52.                 'comment' => 'Status: 0=OFF, 1=ON'
  53.             ]);
  54.             $table->addColumn('create_date''datetimetz', [
  55.                 'notnull' => true,
  56.                 'comment' => 'Creation date'
  57.             ]);
  58.             $table->addColumn('update_date''datetimetz', [
  59.                 'notnull' => true,
  60.                 'comment' => 'Update date'
  61.             ]);
  62.             // Add index for sort_no for better performance
  63.             $table->addIndex(['sort_no'], 'dtb_banner_sort_no_idx');
  64.             $table->addIndex(['status'], 'dtb_banner_status_idx');
  65.         }
  66.     }
  67.     public function down(Schema $schema): void
  68.     {
  69.         if ($schema->hasTable('dtb_banner')) {
  70.             $schema->dropTable('dtb_banner');
  71.         }
  72.     }
  73. }