فهرست منبع

refactor(eav): 迁移EAV模块数据库迁移文件到Phinx并优化时间戳字段

- 将所有EAV相关迁移文件从think\migration\Migrator迁移到Phinx\Migration\AbstractMigration
- 在所有EAV表中明确指定create_time和update_time字段名称替代默认timestamps
- 手动添加delete_time字段用于软删除功能替代addSoftDelete方法
- 为所有迁移文件添加strict_types声明确保类型安全
- 移除对think\migration\db\Column的依赖改用Phinx原生列定义方式
runphp 1 ماه پیش
والد
کامیت
5e8d856b02

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

@@ -1,8 +1,10 @@
 <?php
 
-use think\migration\Migrator;
+declare(strict_types=1);
 
-class ExtensionEavEntityType extends Migrator
+use Phinx\Migration\AbstractMigration;
+
+class ExtensionEavEntityType extends AbstractMigration
 {
     /**
      * Change Method.
@@ -18,8 +20,8 @@ class ExtensionEavEntityType extends Migrator
         $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();
     }
 }

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

@@ -1,8 +1,10 @@
 <?php
 
-use think\migration\Migrator;
+declare(strict_types=1);
 
-class ExtensionEavAttribute extends Migrator
+use Phinx\Migration\AbstractMigration;
+
+class ExtensionEavAttribute extends AbstractMigration
 {
     /**
      * Change Method.
@@ -19,8 +21,8 @@ class ExtensionEavAttribute extends Migrator
             ->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();
     }
 }

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

@@ -1,9 +1,9 @@
 <?php
+declare(strict_types=1);
 
-use think\migration\Migrator;
-use think\migration\db\Column;
+use Phinx\Migration\AbstractMigration;
 
-class ExtensionEavValue extends Migrator
+class ExtensionEavValue extends AbstractMigration
 {
     /**
      * Change Method.
@@ -40,8 +40,8 @@ class ExtensionEavValue extends Migrator
             ->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();
     }
 }

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

@@ -1,9 +1,9 @@
 <?php
+declare(strict_types=1);
 
-use think\migration\Migrator;
-use think\migration\db\Column;
+use Phinx\Migration\AbstractMigration;
 
-class ExtensionEavAttributeOption extends Migrator
+class ExtensionEavAttributeOption extends AbstractMigration
 {
     /**
      * Change Method.
@@ -13,12 +13,12 @@ class ExtensionEavAttributeOption extends Migrator
     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();
     }

+ 4 - 3
database/migrations/20250918015319_eav_attribute_prepend_append.php

@@ -1,9 +1,10 @@
 <?php
 
-use think\migration\Migrator;
-use think\migration\db\Column;
+declare(strict_types=1);
 
-class EavAttributePrependAppend extends Migrator
+use Phinx\Migration\AbstractMigration;
+
+class EavAttributePrependAppend extends AbstractMigration
 {
     /**
      * Change Method.