app/DoctrineMigrations/Version20250127000000.php line 1

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DoctrineMigrations;
  3. use Doctrine\DBAL\Schema\Schema;
  4. use Doctrine\Migrations\AbstractMigration;
  5. final class Version20250127000000 extends AbstractMigration
  6. {
  7.     public function up(Schema $schema) : void
  8.     {
  9.         // Kiểm tra xem cột product_type đã tồn tại chưa
  10.         $table $schema->getTable('dtb_product');
  11.         if (!$table->hasColumn('product_type')) {
  12.             // Thêm cột product_type vào bảng dtb_product
  13.             $this->addSql("ALTER TABLE dtb_product ADD product_type INT DEFAULT NULL");
  14.             
  15.             // Thêm comment cho cột
  16.             $this->addSql("COMMENT ON COLUMN dtb_product.product_type IS 'Product type: 1=WiFi Modem, 2=SIM, 3=Data Package, 4=Other'");
  17.         }
  18.     }
  19.     public function down(Schema $schema) : void
  20.     {
  21.         // Kiểm tra xem cột product_type có tồn tại không trước khi xóa
  22.         $table $schema->getTable('dtb_product');
  23.         if ($table->hasColumn('product_type')) {
  24.             // Xóa cột product_type khỏi bảng dtb_product
  25.             $this->addSql("ALTER TABLE dtb_product DROP COLUMN product_type");
  26.         }
  27.     }