refactor: 处理优化migration文件与model文件字段不一致

This commit is contained in:
2025-06-12 17:41:14 +08:00
parent 736bf19cd6
commit 7eac43e146
13 changed files with 58 additions and 19 deletions

View File

@@ -25,6 +25,7 @@ class ProductTcoCategoryBaseModel extends BaseModel
'tco_path' => 'string', 'tco_path' => 'string',
'erp_id' => 'int', 'erp_id' => 'int',
'erp_pid' => 'int', 'erp_pid' => 'int',
'erp_code' => 'string',
'erp_path' => 'string', 'erp_path' => 'string',
'disabled' => 'int', 'disabled' => 'int',
'sync_time' => 'int', 'sync_time' => 'int',

View File

@@ -17,13 +17,14 @@ class SysConfigGroupBaseModel extends BaseModel
// 字段信息 // 字段信息
protected $schema = [ protected $schema = [
'id' => 'int', 'id' => 'int',
'language_id' => 'int', 'language_id' => 'int',
'name' => 'string', 'unique_label' => 'string',
'sort' => 'int', 'name' => 'string',
'status' => 'int', 'sort' => 'int',
'created_at' => 'datetime', 'status' => 'int',
'updated_at' => 'datetime', 'created_at' => 'datetime',
'deleted_at' => 'datetime', 'updated_at' => 'datetime',
'deleted_at' => 'datetime',
]; ];
} }

View File

@@ -35,6 +35,7 @@ class CreateProductTcoCategory extends Migrator
->addColumn('tco_path', 'string', ['limit' => 120, 'default' => null, 'comment' => '产品目录分类上下级关联路径']) ->addColumn('tco_path', 'string', ['limit' => 120, 'default' => null, 'comment' => '产品目录分类上下级关联路径'])
->addColumn('erp_id', 'integer', ['default' => null, 'comment' => '分类在ERP中的ID']) ->addColumn('erp_id', 'integer', ['default' => null, 'comment' => '分类在ERP中的ID'])
->addColumn('erp_pid', 'integer', ['default' => null, 'comment' => '分类在ERP中的父级ID']) ->addColumn('erp_pid', 'integer', ['default' => null, 'comment' => '分类在ERP中的父级ID'])
->addColumn('erp_code', 'string', ['limit' => 64, 'null' => true, 'default' => null, 'comment' => '分类在ERP中的编码'])
->addColumn('erp_path', 'string', ['limit' => 120, 'default' => null, 'comment' => '分类在ERP中的上下级关联路径']) ->addColumn('erp_path', 'string', ['limit' => 120, 'default' => null, 'comment' => '分类在ERP中的上下级关联路径'])
->addColumn('disabled', 'boolean', ['null' => false, 'default' => 0, 'comment' => '0为启用, 1为禁用']) ->addColumn('disabled', 'boolean', ['null' => false, 'default' => 0, 'comment' => '0为启用, 1为禁用'])
->addColumn('sync_time', 'integer', ['null' => false, 'default' => 0, 'comment' => '同步时间']) ->addColumn('sync_time', 'integer', ['null' => false, 'default' => 0, 'comment' => '同步时间'])

View File

@@ -31,6 +31,7 @@ class CreateArticleCategory extends Migrator
$table = $this->table('article_category', ['engine' => 'MyISAM', 'comment' => '文章分类表']); $table = $this->table('article_category', ['engine' => 'MyISAM', 'comment' => '文章分类表']);
$table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID']) $table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID'])
->addColumn('pid', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'comment' => '父级ID']) ->addColumn('pid', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'comment' => '父级ID'])
->addColumn('unique_label', 'string', ['limit' => 64, 'null' => false, 'comment' => '唯一标识'])
->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '分类名称']) ->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '分类名称'])
->addColumn('short_name', 'string', ['limit' => 64, 'null' => true, 'default' => null, 'comment' => '分类简称']) ->addColumn('short_name', 'string', ['limit' => 64, 'null' => true, 'default' => null, 'comment' => '分类简称'])
->addColumn('icon', 'string', ['limit' => 125, 'default' => null, 'comment' => '图标']) ->addColumn('icon', 'string', ['limit' => 125, 'default' => null, 'comment' => '图标'])
@@ -41,6 +42,7 @@ class CreateArticleCategory extends Migrator
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '新增时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '新增时间'])
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间']) ->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间'])
->addIndex(['language_id', 'unique_label'], ['name' => 'idx_language_id_unique_label', 'unique' => true])
->create(); ->create();
} }
} }

View File

@@ -28,7 +28,8 @@ class CreateAttachmentCategory extends Migrator
public function change() public function change()
{ {
$table = $this->table('attachment_category', ['engine' => 'MyISAM', 'comment' => '附件分类表']); $table = $this->table('attachment_category', ['engine' => 'MyISAM', 'comment' => '附件分类表']);
$table->addColumn('language_id', 'integer', ['signed' => false , 'null' => false, 'comment' => '语言ID']) $table->addColumn('pid', 'integer', ['null' => true, 'default' => 0, 'comment' => '上级id'])
->addColumn('language_id', 'integer', ['signed' => false , 'null' => false, 'comment' => '语言ID'])
->addColumn('name', 'string', ['limit' => 64 , 'null' => false, 'comment' => '分类名称']) ->addColumn('name', 'string', ['limit' => 64 , 'null' => false, 'comment' => '分类名称'])
->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序']) ->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序'])
->addColumn('is_show', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否显示:1是,0否']) ->addColumn('is_show', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否显示:1是,0否'])

View File

@@ -37,7 +37,7 @@ class CreateBulkPurchaseInquiry extends Migrator
->addColumn('province', 'string', ['limit' => 64, 'null' => true, 'comment' => '省']) ->addColumn('province', 'string', ['limit' => 64, 'null' => true, 'comment' => '省'])
->addColumn('city', 'string', ['limit' => 64, 'null' => true, 'comment' => '市']) ->addColumn('city', 'string', ['limit' => 64, 'null' => true, 'comment' => '市'])
->addColumn('district', 'string', ['limit' => 64, 'null' => true, 'comment' => '区']) ->addColumn('district', 'string', ['limit' => 64, 'null' => true, 'comment' => '区'])
->addColumn('address', 'string', ['limit' => 255, 'null' => true, 'comment' => '地址']) ->addColumn('street', 'string', ['limit' => 255, 'null' => true, 'comment' => '街道'])
->addColumn('interested', 'string', ['limit' => 255, 'null' => false, 'comment' => '兴趣(感兴趣的产品品类)']) ->addColumn('interested', 'string', ['limit' => 255, 'null' => false, 'comment' => '兴趣(感兴趣的产品品类)'])
->addColumn('url', 'string', ['limit' => 255, 'null' => true, 'comment' => '感兴趣产品所在官网URL']) ->addColumn('url', 'string', ['limit' => 255, 'null' => true, 'comment' => '感兴趣产品所在官网URL'])
->addColumn('referer_url', 'string', ['limit' => 255, 'null' => true, 'comment' => '来源URL']) ->addColumn('referer_url', 'string', ['limit' => 255, 'null' => true, 'comment' => '来源URL'])

View File

@@ -31,14 +31,15 @@ class CreateSysConfig extends Migrator
$table->addColumn('group_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '分组ID']) $table->addColumn('group_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '分组ID'])
->addColumn('title', 'string', ['limit' => 64, 'null' => false, 'comment' => '配置标题']) ->addColumn('title', 'string', ['limit' => 64, 'null' => false, 'comment' => '配置标题'])
->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '配置名称']) ->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '配置名称'])
->addColumn('value', 'string', ['limit' => 512, 'null' => true, 'default' => null, 'comment' => '配置值']) ->addColumn('value', 'string', ['limit' => 4096, 'null' => true, 'default' => null, 'comment' => '配置值'])
->addColumn('extra', 'string', ['limit' => 512, 'null' => true, 'default' => null, 'comment' => '配置额外信息']) ->addColumn('extra', 'string', ['limit' => 4096, 'null' => true, 'default' => null, 'comment' => '配置额外信息'])
->addColumn('type', 'string', ['limit' => 64, 'null' => false, 'comment' => '配置类型: text, textarea, number, select, checkbox, radio, date, time, datetime']) ->addColumn('type', 'string', ['limit' => 64, 'null' => false, 'comment' => '配置类型: text, textarea, number, select, checkbox, radio, date, time, datetime'])
->addColumn('sort', 'integer', ['limit' => 11, 'null' => false, 'default' => 0, 'comment' => '排序']) ->addColumn('sort', 'integer', ['limit' => 11, 'null' => false, 'default' => 0, 'comment' => '排序'])
->addColumn('remark', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '备注']) ->addColumn('remark', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '备注'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间'])
->addIndex(['name'], ['unique' => true, 'name' => 'unique_idx_name']) ->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null, 'comment' => '删除时间'])
->addIndex(['group_id', 'name'], ['unique' => true, 'name' => 'idx_unique_group_id_name'])
->create(); ->create();
} }
} }

View File

@@ -29,12 +29,13 @@ class CreateSysConfigGroup extends Migrator
{ {
$table = $this->table('sys_config_group', ['engine' => 'InnoDB', 'comment' => '系统配置分组表']); $table = $this->table('sys_config_group', ['engine' => 'InnoDB', 'comment' => '系统配置分组表']);
$table->addColumn('language_id', 'integer', ['null' => false, 'comment' => '语言ID']) $table->addColumn('language_id', 'integer', ['null' => false, 'comment' => '语言ID'])
->addColumn('unique_label', 'string', ['32' => 64, 'null' => true, 'default' => 'null', 'comment' => '唯一标识']) ->addColumn('unique_label', 'string', ['limit' => 64, 'null' => true, 'default' => null, 'comment' => '唯一标识'])
->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '分组名称']) ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '分组名称'])
->addColumn('sort', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '排序']) ->addColumn('sort', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '排序'])
->addColumn('status', 'boolean', ['limit' => 1, 'default' => 1, 'comment' => '状态 -1禁用, 1启用']) ->addColumn('status', 'boolean', ['limit' => 1, 'default' => 1, 'comment' => '状态 -1禁用, 1启用'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间'])
->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null, 'comment' => '删除时间'])
->create(); ->create();
} }
} }

View File

@@ -42,6 +42,7 @@ class CreateSysOperateLog extends Migrator
->addColumn('status', MysqlAdapter::PHINX_TYPE_SMALL_INTEGER, ['limit' => 5, 'default' => 200, 'comment' => '状态码']) ->addColumn('status', MysqlAdapter::PHINX_TYPE_SMALL_INTEGER, ['limit' => 5, 'default' => 200, 'comment' => '状态码'])
->addColumn('message', MysqlAdapter::PHINX_TYPE_TEXT, ['default' => null, 'comment' => '消息']) ->addColumn('message', MysqlAdapter::PHINX_TYPE_TEXT, ['default' => null, 'comment' => '消息'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addIndex(['user_id'], ['name' => 'idx_user_id'])
->create(); ->create();
} }
} }

View File

@@ -30,6 +30,7 @@ class CreateSysNavigation extends Migrator
$table = $this->table('sys_navigation', ['engine' => 'InnoDB', 'comment' => '系统导航表']); $table = $this->table('sys_navigation', ['engine' => 'InnoDB', 'comment' => '系统导航表']);
$table->addColumn('language_id', 'integer', ['null' => false, 'comment' => '语言ID']) $table->addColumn('language_id', 'integer', ['null' => false, 'comment' => '语言ID'])
->addColumn('at_page', 'string', ['limit' => 64, 'null' => true, 'comment' => '导航所在页面路径']) ->addColumn('at_page', 'string', ['limit' => 64, 'null' => true, 'comment' => '导航所在页面路径'])
->addColumn('at_platform', 'string', ['limit' => 8, 'null' => false, 'comment' => '所在平台: pc为电脑, mobile为手机'])
->addColumn('unique_label', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航唯一标识']) ->addColumn('unique_label', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航唯一标识'])
->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航名称']) ->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航名称'])
->addColumn('desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '导航描述']) ->addColumn('desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '导航描述'])
@@ -38,7 +39,7 @@ class CreateSysNavigation extends Migrator
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间'])
->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null, 'comment' => '删除时间']) ->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null, 'comment' => '删除时间'])
->addIndex(['unique_label'], ['unique' => true]) ->addIndex(['at_platform', 'language_id', 'unique_label'], ['name' => 'idx_at_platform_language_id_unique_label', 'unique' => true])
->create(); ->create();
} }
} }

View File

@@ -31,7 +31,6 @@ class CreateSysBanner extends Migrator
$table->addColumn('language_id', 'integer', ['null' => false, 'comment' => '语言ID']) $table->addColumn('language_id', 'integer', ['null' => false, 'comment' => '语言ID'])
->addColumn('at_platform', 'string', ['limit' => 8, 'null' => false, 'comment' => '所在平台: pc为电脑, mobile为手机']) ->addColumn('at_platform', 'string', ['limit' => 8, 'null' => false, 'comment' => '所在平台: pc为电脑, mobile为手机'])
->addColumn('at_page', 'string', ['limit' => 255, 'null' => true, 'comment' => '所在页面']) ->addColumn('at_page', 'string', ['limit' => 255, 'null' => true, 'comment' => '所在页面'])
->addColumn('at_position', 'string', ['limit' => 255, 'null' => true, 'comment' => '所在位置: top为顶部, footer为底部, left为左侧, right为右侧, center为中间'])
->addColumn('unique_label', 'string', ['limit' => 64, 'null' => false, 'comment' => 'banner唯一标识']) ->addColumn('unique_label', 'string', ['limit' => 64, 'null' => false, 'comment' => 'banner唯一标识'])
->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => 'banner名称']) ->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => 'banner名称'])
->addColumn('desc', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => 'banner描述']) ->addColumn('desc', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => 'banner描述'])
@@ -41,7 +40,7 @@ class CreateSysBanner extends Migrator
->addColumn('created_at', 'timestamp', ['null' => false, 'default' =>'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' =>'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' =>'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' =>'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间'])
->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null, 'comment' => '删除时间']) ->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null, 'comment' => '删除时间'])
->addIndex(['unique_label'], ['unique' => true]) ->addIndex(['at_platform', 'language_id', 'unique_label'], ['name' => 'idx_at_platform_language_id_unique_label', 'unique' => true])
->create(); ->create();
} }
} }

View File

@@ -2,7 +2,7 @@
use think\migration\Seeder; use think\migration\Seeder;
class AgentEnterpriseSizeTypeInit extends Seeder class AgentEntrypriceSizeTypeInit extends Seeder
{ {
/** /**
* Run Method. * Run Method.
@@ -25,7 +25,7 @@ class AgentEnterpriseSizeTypeInit extends Seeder
["id" => 8, "language_id" => 2, "name" => "200 Or More", "value" => "200 Or More", "desc" => null, "sort" => 4, "created_at" => "2025-03-13 17:42:20"] ["id" => 8, "language_id" => 2, "name" => "200 Or More", "value" => "200 Or More", "desc" => null, "sort" => 4, "created_at" => "2025-03-13 17:42:20"]
]; ];
$table = $this->table('agent_enterprise_size_type'); $table = $this->table('agent_entryprice_size_type');
// empty the data // empty the data
$table->truncate(); $table->truncate();

View File

@@ -0,0 +1,30 @@
<?php
use think\migration\Seeder;
class ProductAttrInit extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run(): void
{
$data = [
['id' => 1, 'language_id' => 1, 'attr_type' => 1, 'attr_name' => '颜色', 'is_system' => 1, 'created_at' => '2025-02-12 10:11:05', 'updated_at' => '2025-03-28 16:17:46', 'deleted_at' => null],
['id' => 2, 'language_id' => 2, 'attr_type' => 1, 'attr_name' => 'Color', 'is_system' => 1, 'created_at' => '2025-02-12 10:11:05', 'updated_at' => '2025-05-26 11:08:55', 'deleted_at' => null]
];
$table = $this->table('product_attr');
// empty the table
$table->truncate();
// insert data
$table->insert($data)->saveData();
}
}