Browse Source

refactor(migrations): 统一数据库迁移文件格式

- 为所有迁移文件添加 declare(strict_types=1) 声明
- 移除旧版 Column 类的使用,改用数组配置方式定义字段
- 统一时间戳字段命名为 create_time 和 update_time
- 使用 addColumn 方法替代 addTimestamps 和 addSoftDelete
- 标准化字段定义参数格式,提升代码一致性
runphp 3 tháng trước cách đây
mục cha
commit
eb43f7a524

+ 4 - 2
database/migrations/20250712021908_extension_eav_entity_type.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 use Phinx\Migration\AbstractMigration;
 
 class ExtensionEavEntityType extends AbstractMigration
@@ -18,8 +20,8 @@ class ExtensionEavEntityType extends AbstractMigration
         $table->addColumn('entity_type_code', 'string', ['limit' => 50, 'comment' => '实体类型编码'])
             ->addColumn('entity_table', 'string', ['limit' => 64, 'comment' => '实体主表名'])
             ->addIndex(['entity_type_code'], ['name' => 'entity_type_code', 'unique' => true])
-            ->addTimestamps()
-            ->addSoftDelete()
+            ->addTimestamps('create_time', 'update_time')
+            ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间'])
             ->create();
     }
 }

+ 4 - 2
database/migrations/20250712021931_extension_eav_attribute.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 use Phinx\Migration\AbstractMigration;
 
 class ExtensionEavAttribute extends AbstractMigration
@@ -19,8 +21,8 @@ class ExtensionEavAttribute extends AbstractMigration
             ->addColumn('frontend_label', 'string', ['comment' => '显示标签', 'limit' => 255])
             ->addColumn('is_required', 'boolean', ['comment' => '是否必填', 'default' => false])
             ->addIndex(['entity_type_id', 'attribute_code'], ['unique' => true])
-            ->addTimestamps()
-            ->addSoftDelete()
+            ->addTimestamps('create_time', 'update_time')
+            ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间'])
             ->create();
     }
 }

+ 3 - 3
database/migrations/20250712022607_extension_eav_value.php

@@ -1,7 +1,7 @@
 <?php
+declare(strict_types=1);
 
 use Phinx\Migration\AbstractMigration;
-use think\migration\db\Column;
 
 class ExtensionEavValue extends AbstractMigration
 {
@@ -40,8 +40,8 @@ class ExtensionEavValue extends AbstractMigration
             ->addColumn('value_datetime', 'datetime', ['comment' => '日期时间值'])
             ->addIndex(['entity_id', 'attribute_id'], ['name' => 'entity_id_attribute_id'])
             ->addIndex(['entity_id', 'entity_type_id'],['name' => 'idx_entity_id_entity_type_id'])
-            ->addTimestamps()
-            ->addSoftDelete()
+            ->addTimestamps('create_time', 'update_time')
+            ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间'])
             ->create();
     }
 }

+ 7 - 7
database/migrations/20250712025652_extension_eav_attribute_option.php

@@ -1,7 +1,7 @@
 <?php
+declare(strict_types=1);
 
 use Phinx\Migration\AbstractMigration;
-use think\migration\db\Column;
 
 class ExtensionEavAttributeOption extends AbstractMigration
 {
@@ -13,12 +13,12 @@ class ExtensionEavAttributeOption extends AbstractMigration
     public function change()
     {
         $table = $this->table('extension_eav_attribute_option', ['engine' => 'InnoDB', 'comment' => '属性选项表']);
-        $table->addColumn(Column::unsignedInteger('attribute_id')->setComment('属性ID'))
-            ->addColumn(Column::string('label')->setComment('显示文本'))
-            ->addColumn(Column::string('value')->setComment('选项值'))
-            ->addColumn(Column::unsignedInteger('sort')->setComment('排序'))
-            ->addTimestamps()
-            ->addSoftDelete()
+        $table->addColumn('attribute_id', 'integer', ['signed' => false, 'comment' => '属性ID'])
+            ->addColumn('label', 'string', ['comment' => '显示文本'])
+            ->addColumn('value', 'string', ['comment' => '选项值'])
+            ->addColumn('sort', 'integer', ['signed' => false, 'comment' => '排序'])
+            ->addTimestamps('create_time', 'update_time')
+            ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间'])
             ->addIndex(['attribute_id'])
             ->create();
     }

+ 2 - 1
database/migrations/20250918015319_eav_attribute_prepend_append.php

@@ -1,7 +1,8 @@
 <?php
 
+declare(strict_types=1);
+
 use Phinx\Migration\AbstractMigration;
-use think\migration\db\Column;
 
 class EavAttributePrependAppend extends AbstractMigration
 {