add order item constraint to order parse
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Hyperf\Database\Schema\Schema;
|
||||
use Hyperf\Database\Schema\Blueprint;
|
||||
use Hyperf\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('order_items', function (Blueprint $table) {
|
||||
// 索引1:基于数据库 ID 的唯一性(用于外键关联和基于 order_id 的查询)
|
||||
$table->unique(['order_id', 'sub_order_id'], 'order_items_order_sub_order_unique');
|
||||
|
||||
// 索引2:基于业务键的唯一性(用于 upsert 操作,无需先查询 order_id)
|
||||
// 与 orders 表的 (store_id, platform_order_id) 唯一索引配合使用
|
||||
$table->unique(
|
||||
['store_id', 'platform_order_id', 'sub_order_id'],
|
||||
'order_items_store_platform_sub_unique'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('order_items', function (Blueprint $table) {
|
||||
// 删除两个唯一索引
|
||||
$table->dropUnique('order_items_order_sub_order_unique');
|
||||
$table->dropUnique('order_items_store_platform_sub_unique');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user