Files
datahub/backend/migrations/2025_11_13_068522_create_skus_mapping.php
T

47 lines
1.8 KiB
PHP
Raw Normal View History

2025-11-13 16:27:32 +08:00
<?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::create('skus_mapping', function (Blueprint $table) {
$table->comment('存储 业务侧 SKU 到 客户原始 SKU 的映射信息, 当平台绑定异常时使用');
$table->bigIncrements('id')->primary()->comment('主键');
$table->integer('company_id')->comment('公司 ID 与 Tools 保持一致');
$table->integer('platform_id')->comment('平台 ID 与 Tools 保持一致');
$table->text('platform_product_id')->comment('平台 商品 ID 与 电商平台 保持一致');
$table->text('origin_sku')->comment('客户侧匹配的 SKU 编码, 组合商品需要拆分');
$table->integer('store_id')->nullable()->comment('店铺 ID 与 Tools 保持一致, 建议填写以方便核对');
$table->integer('warehouse_id')->nullable()->comment('店铺绑定仓库 ID 与 Tools 保持一致,建议填写,建议填写以方便核对');
$table->boolean('enabled')->default(true)->comment('是否启用映射规则,默认为启用');
$table->text('note')->nullable()->default(null)->comment('备注信息');
$table->timestampsTz();
2025-11-13 16:41:56 +08:00
// 创建联合唯一索引:确保同一平台的同一产品只能有一条映射记录
// 原始 SKU 的约束由业务侧实现
$table->unique(['platform_id', 'platform_product_id'], 'uk_platform_product');
2025-11-13 16:27:32 +08:00
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('skus_mapping');
}
};