杂务:同步主初始化SQL标签店铺唯一约束
This commit is contained in:
@@ -399,8 +399,8 @@ create table t_tag
|
|||||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||||
shop_id bigint null comment '店铺ID',
|
shop_id bigint null comment '店铺ID',
|
||||||
constraint uk_tag_name
|
constraint uk_tag_shop_name
|
||||||
unique (tag_name) comment '标签名称唯一索引'
|
unique (shop_id, tag_name) comment '店铺内标签名称唯一索引'
|
||||||
)
|
)
|
||||||
comment '系统标签信息表';
|
comment '系统标签信息表';
|
||||||
|
|
||||||
@@ -697,6 +697,25 @@ CALL sp_add_index_if_not_exists('t_order', 'idx_t_order_coupon_source_type', '(`
|
|||||||
CALL sp_add_column_if_not_exists('t_order_item', 'appointment_time', 'datetime NULL COMMENT ''预约开始时间''');
|
CALL sp_add_column_if_not_exists('t_order_item', 'appointment_time', 'datetime NULL COMMENT ''预约开始时间''');
|
||||||
CALL sp_add_index_if_not_exists('t_order_item', 'idx_t_order_item_artist_appointment_time', '(`artist_id`, `appointment_time`)');
|
CALL sp_add_index_if_not_exists('t_order_item', 'idx_t_order_item_artist_appointment_time', '(`artist_id`, `appointment_time`)');
|
||||||
|
|
||||||
|
SET @drop_old_tag_unique_sql = (
|
||||||
|
SELECT IF(
|
||||||
|
EXISTS(
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.STATISTICS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
|
AND TABLE_NAME = 't_tag'
|
||||||
|
AND INDEX_NAME = 'uk_tag_name'
|
||||||
|
),
|
||||||
|
'ALTER TABLE `t_tag` DROP INDEX `uk_tag_name`',
|
||||||
|
'SELECT 1'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
PREPARE stmt FROM @drop_old_tag_unique_sql;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
CALL sp_add_unique_index_if_not_exists('t_tag', 'uk_tag_shop_name', '(`shop_id`, `tag_name`)');
|
||||||
|
|
||||||
CALL sp_add_column_if_not_exists('t_coupon', 'coupon_scene', 'varchar(32) NOT NULL DEFAULT ''NORMAL'' COMMENT ''优惠券场景''');
|
CALL sp_add_column_if_not_exists('t_coupon', 'coupon_scene', 'varchar(32) NOT NULL DEFAULT ''NORMAL'' COMMENT ''优惠券场景''');
|
||||||
CALL sp_add_column_if_not_exists('t_coupon', 'required_vip_level', 'varchar(20) NULL COMMENT ''要求的VIP等级''');
|
CALL sp_add_column_if_not_exists('t_coupon', 'required_vip_level', 'varchar(20) NULL COMMENT ''要求的VIP等级''');
|
||||||
CALL sp_add_column_if_not_exists('t_coupon', 'auto_match', 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''是否自动匹配''');
|
CALL sp_add_column_if_not_exists('t_coupon', 'auto_match', 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''是否自动匹配''');
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# 2026-03-27 YumiNail 主 SQL 同步标签店铺唯一约束
|
||||||
|
|
||||||
|
## 背景
|
||||||
|
|
||||||
|
- 上一轮已经补了 `t_tag` 的增量 SQL:
|
||||||
|
- `docs/changes/2026-03-27_tag_shop_unique_patch.sql`
|
||||||
|
- 但主初始化脚本 `YumiNail.sql` 里仍然保留旧的全局唯一约束:
|
||||||
|
- `uk_tag_name(tag_name)`
|
||||||
|
- 这会导致:
|
||||||
|
- 空库首次执行 `YumiNail.sql` 后,标签仍然是“全局唯一”
|
||||||
|
- 与当前代码里“按店铺允许重名标签”的业务规则不一致
|
||||||
|
|
||||||
|
## 本次同步
|
||||||
|
|
||||||
|
- 文件:`YumiNail-Core/src/main/resources/files/YumiNail.sql`
|
||||||
|
|
||||||
|
### 1. 建表定义同步
|
||||||
|
|
||||||
|
- 将 `t_tag` 的唯一约束从:
|
||||||
|
- `uk_tag_name(tag_name)`
|
||||||
|
- 同步为:
|
||||||
|
- `uk_tag_shop_name(shop_id, tag_name)`
|
||||||
|
|
||||||
|
### 2. 主脚本补丁段同步
|
||||||
|
|
||||||
|
- 在 `YumiNail.sql` 的整合补丁区增加旧索引切换逻辑:
|
||||||
|
- 若旧索引 `uk_tag_name` 存在,则先删除
|
||||||
|
- 再确保新索引 `uk_tag_shop_name(shop_id, tag_name)` 存在
|
||||||
|
|
||||||
|
## 结果
|
||||||
|
|
||||||
|
- 现在空库首次部署执行 `YumiNail.sql`,标签唯一性规则就是正确的“店铺内唯一”。
|
||||||
|
- 现有数据库仍可继续使用:
|
||||||
|
- `docs/changes/2026-03-27_tag_shop_unique_patch.sql`
|
||||||
|
进行手工升级。
|
||||||
|
- 主初始化脚本与增量补丁脚本的口径已保持一致,不再漂移。
|
||||||
|
|
||||||
|
## SQL 说明
|
||||||
|
|
||||||
|
- 本次没有新增新的独立 SQL 文件。
|
||||||
|
- 已有升级补丁文件保留:
|
||||||
|
- `docs/changes/2026-03-27_tag_shop_unique_patch.sql`
|
||||||
|
|
||||||
|
## 验证
|
||||||
|
|
||||||
|
- 本次仅同步 SQL 脚本与变更记录,未涉及 Java / 前端代码逻辑变更。
|
||||||
Reference in New Issue
Block a user