feat(ecom-dmb): 商品规格表添加(公司ID,规格编码)复合唯一约束,导入时自动清理重复规格数据

This commit is contained in:
小蟑螂
2026-04-18 14:14:27 +08:00
parent 2e73584a36
commit 10827e25dd
4 changed files with 75 additions and 10 deletions
@@ -0,0 +1,12 @@
-- 同一公司下规格编码唯一(与导入并发建规格一致)
SET @db := DATABASE();
SET @exists := (
SELECT COUNT(1) FROM information_schema.statistics
WHERE table_schema = @db AND table_name = 'ec_product_spec' AND index_name = 'uk_company_spec_code'
);
SET @sql := IF(@exists = 0,
'ALTER TABLE ec_product_spec ADD UNIQUE INDEX uk_company_spec_code (company_id, spec_code)',
'SELECT 1');
PREPARE s FROM @sql;
EXECUTE s;
DEALLOCATE PREPARE s;