소스 검색

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

- 为所有迁移文件添加 declare(strict_types=1) 声明
- 移除旧版 Column 类的使用,改用数组配置方式定义字段
- 统一时间戳字段命名为 create_time 和 update_time
- 使用 addColumn 方法替代 addTimestamps 和 addSoftDelete
- 标准化字段定义参数格式,提升代码一致性
runphp 3 달 전
부모
커밋
018c652ca7

+ 15 - 15
database/migrations/20250720063342_extension_payment.php

@@ -1,7 +1,7 @@
 <?php
+declare(strict_types=1);
 
 use Phinx\Migration\AbstractMigration;
-use think\migration\db\Column;
 
 class ExtensionPayment extends AbstractMigration
 {
@@ -30,20 +30,20 @@ class ExtensionPayment extends AbstractMigration
     {
         $this->table('extension_payment')
             ->setComment('订单支付记录表')
-            ->addColumn(Column::integer('order_id')->setComment('关联订单ID'))
-            ->addColumn(Column::char('order_sn', 20)->setComment('订单编号'))
-            ->addColumn(Column::char('out_trade_no', 20)->setComment('商户支付订单号'))
-            ->addColumn(Column::tinyInteger('biz_type')->setComment('业务类型:1-商品订单支付'))
-            ->addColumn(Column::string('pay_type', 20)->setComment('支付方式:wechatpay-微信 xlpayment-信联支付'))
-            ->addColumn(Column::json('payment_param')->setComment('支付参数'))
-            ->addColumn(Column::decimal('amount', 10, 2)->setComment('支付金额(元)'))
-            ->addColumn(Column::tinyInteger('status')->setComment('支付状态:0-待支付/1-支付中/2-成功/3-失败/4-已关闭/5-退款中'))
-            ->addColumn(Column::char('transaction_id', 32)->setComment('三方支付订单号'))
-            ->addColumn(Column::integer('payment_time')->setComment('支付成功时间'))
-            ->addColumn(Column::integer('expire_time')->setComment('订单失效时间'))
-            ->addColumn(Column::json('payment_result')->setComment('查询支付结果信息'))
-            ->addColumn(Column::string('status_desc', 255)->setComment('支付状态说明'))
-            ->addTimestamps()
+            ->addColumn('order_id', 'integer', ['comment' => '关联订单ID'])
+            ->addColumn('order_sn', 'char', ['limit' => 20, 'comment' => '订单编号'])
+            ->addColumn('out_trade_no', 'char', ['limit' => 20, 'comment' => '商户支付订单号'])
+            ->addColumn('biz_type', 'tinyinteger', ['comment' => '业务类型:1-商品订单支付'])
+            ->addColumn('pay_type', 'string', ['limit' => 20, 'comment' => '支付方式:wechatpay-微信 xlpayment-信联支付'])
+            ->addColumn('payment_param', 'json', ['comment' => '支付参数'])
+            ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'comment' => '支付金额(元)'])
+            ->addColumn('status', 'tinyinteger', ['comment' => '支付状态:0-待支付/1-支付中/2-成功/3-失败/4-已关闭/5-退款中'])
+            ->addColumn('transaction_id', 'char', ['limit' => 32, 'comment' => '三方支付订单号'])
+            ->addColumn('payment_time', 'integer', ['comment' => '支付成功时间'])
+            ->addColumn('expire_time', 'integer', ['comment' => '订单失效时间'])
+            ->addColumn('payment_result', 'json', ['comment' => '查询支付结果信息'])
+            ->addColumn('status_desc', 'string', ['limit' => 255, 'comment' => '支付状态说明'])
+            ->addTimestamps('create_time', 'update_time')
             ->addIndex(['order_id', 'biz_type'])
             ->addIndex(['transaction_id'])
             ->addIndex(['out_trade_no'], ['unique' => true])

+ 3 - 2
database/migrations/20250731075545_extension_payment_user_id.php

@@ -1,7 +1,8 @@
 <?php
 
+declare(strict_types=1);
+
 use Phinx\Migration\AbstractMigration;
-use think\migration\db\Column;
 
 class ExtensionPaymentUserId extends AbstractMigration
 {
@@ -29,7 +30,7 @@ class ExtensionPaymentUserId extends AbstractMigration
     public function change()
     {
         $this->table('extension_payment')
-            ->addColumn(Column::integer('user_id')->setUnsigned()->setDefault(0)->setAfter('id')->setComment('用户ID'))
+            ->addColumn('user_id', 'integer', ['signed' => false, 'default' => 0, 'after' => 'id', 'comment' => '用户ID'])
             ->update();
     }
 }

+ 14 - 13
database/migrations/20250905165126_extension_refund.php

@@ -1,6 +1,7 @@
 <?php
 
-use think\migration\db\Column;
+declare(strict_types=1);
+
 use Phinx\Migration\AbstractMigration;
 
 class ExtensionRefund extends AbstractMigration
@@ -30,18 +31,18 @@ class ExtensionRefund extends AbstractMigration
     {
         $this->table('extension_refund')
             ->setComment('支付退款记录表')
-            ->addColumn(Column::integer('payment_id')->setComment('关联支付记录ID'))
-            ->addColumn(Column::char('order_sn', 20)->setComment('支付订单编号'))
-            ->addColumn(Column::char('out_refund_no', 20)->setComment('商户退款单号'))
-            ->addColumn(Column::string('reason'))->setComment('退款原因')
-            ->addColumn(Column::decimal('amount', 10, 2)->setComment('退款金额(元)'))
-            ->addColumn(Column::tinyInteger('status')->setComment('退款状态:0-待退款/1-退款中/2-成功/3-失败'))
-            ->addColumn(Column::char('refund_id', 32)->setComment('三方退款唯一订单号'))
-            ->addColumn(Column::integer('success_time')->setComment('退款成功时间'))
-            ->addColumn(Column::json('refund_param')->setComment('退款参数'))
-            ->addColumn(Column::json('refund_result')->setComment('查询退款结果信息'))
-            ->addColumn(Column::string('status_desc')->setComment('退款状态说明'))
-            ->addTimestamps()
+            ->addColumn('payment_id', 'integer', ['comment' => '关联支付记录ID'])
+            ->addColumn('order_sn', 'char', ['limit' => 20, 'comment' => '支付订单编号'])
+            ->addColumn('out_refund_no', 'char', ['limit' => 20, 'comment' => '商户退款单号'])
+            ->addColumn('reason', 'string', ['comment' => '退款原因'])
+            ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'comment' => '退款金额(元)'])
+            ->addColumn('status', 'tinyinteger', ['comment' => '退款状态:0-待退款/1-退款中/2-成功/3-失败'])
+            ->addColumn('refund_id', 'char', ['limit' => 32, 'comment' => '三方退款唯一订单号'])
+            ->addColumn('success_time', 'integer', ['comment' => '退款成功时间'])
+            ->addColumn('refund_param', 'json', ['comment' => '退款参数'])
+            ->addColumn('refund_result', 'json', ['comment' => '查询退款结果信息'])
+            ->addColumn('status_desc', 'string', ['comment' => '退款状态说明'])
+            ->addTimestamps('create_time', 'update_time')
             ->addIndex(['refund_id'])
             ->addIndex(['out_refund_no'], ['unique' => true])
             ->addIndex(['order_sn'])