将历史补单字段合并到初始化SQL
发布 Nacos 配置 / publish (push) Successful in 32s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 1s

This commit is contained in:
2026-10-13 14:37:54 +08:00
parent 5145dc44c6
commit 4101ab3408
5 changed files with 32 additions and 48 deletions
+29 -2
View File
@@ -336,14 +336,18 @@ create table t_order
id bigint unsigned auto_increment comment '订单主键索引'
primary key,
order_no varchar(50) not null comment '订单编号',
user_id bigint unsigned not null comment '关联用户表主键',
user_id bigint unsigned null comment '关联用户表主键,历史补单可为空',
shop_id bigint unsigned null comment '所属店铺ID',
total_amount decimal(10, 2) not null comment '订单总金额',
actual_amount decimal(10, 2) not null comment '实际支付金额',
coupon_id bigint unsigned default 0 null comment '使用的优惠券ID',
user_coupon_id bigint unsigned null comment '用户券ID',
coupon_source_type varchar(32) null comment '优惠来源类型',
status tinyint unsigned default 1 not null comment '订单状态:1-待使用,2-已完成,3-已取消',
customer_remark varchar(500) null comment '用户询价预约备注',
customer_name_snapshot varchar(100) null comment '补单客户名称快照',
customer_phone_snapshot varchar(32) null comment '补单客户手机号快照',
order_source varchar(32) default 'NORMAL_APPOINTMENT' not null comment '订单来源:NORMAL_APPOINTMENT/HISTORICAL_BACKFILL',
status tinyint unsigned default 1 not null comment '订单状态:0-价格确认中,1-待服务,2-已完成,3-已取消,4-服务中',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
@@ -360,6 +364,10 @@ create index idx_user_id
on t_order (user_id)
comment '按用户查询订单的索引';
create index idx_order_source_status_delete
on t_order (order_source, status, is_delete)
comment '按订单来源和状态查询的索引';
-- auto-generated definition
create table t_order_item
(
@@ -371,6 +379,7 @@ create table t_order_item
price decimal(10, 2) not null comment '商品单价',
artist_id bigint unsigned null comment '关联美甲师ID',
appointment_time datetime null comment '预约开始时间',
service_date date null comment '业务服务日期,历史补单无具体时间时使用',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
@@ -381,6 +390,10 @@ create index idx_order_id
on t_order_item (order_id)
comment '按订单查询商品的索引';
create index idx_order_item_artist_service_date
on t_order_item (artist_id, service_date, is_delete)
comment '按员工和业务服务日期查询的索引';
CREATE TABLE IF NOT EXISTS t_order_artist_review
(
id bigint unsigned auto_increment comment '评价任务ID'
@@ -1050,8 +1063,22 @@ CALL sp_add_index_if_not_exists('t_balance_change_detail', 'idx_balance_detail_o
CALL sp_add_column_if_not_exists('t_order', 'shop_id', 'bigint unsigned NULL COMMENT ''所属店铺ID''');
CALL sp_add_column_if_not_exists('t_order', 'user_coupon_id', 'bigint unsigned NULL COMMENT ''用户券ID''');
SET @sql = (SELECT IF(COUNT(*) = 0,
'ALTER TABLE t_order MODIFY COLUMN user_id BIGINT UNSIGNED NULL COMMENT ''关联用户表主键,历史补单可为空''',
'SELECT 1') FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 't_order' AND column_name = 'user_id' AND is_nullable = 'YES');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
CALL sp_add_column_if_not_exists('t_order', 'customer_remark', 'varchar(500) NULL COMMENT ''用户询价预约备注''');
CALL sp_add_column_if_not_exists('t_order', 'customer_name_snapshot', 'varchar(100) NULL COMMENT ''补单客户名称快照''');
CALL sp_add_column_if_not_exists('t_order', 'customer_phone_snapshot', 'varchar(32) NULL COMMENT ''补单客户手机号快照''');
CALL sp_add_column_if_not_exists('t_order', 'order_source', 'varchar(32) NOT NULL DEFAULT ''NORMAL_APPOINTMENT'' COMMENT ''订单来源:NORMAL_APPOINTMENT/HISTORICAL_BACKFILL''');
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', 'service_date', 'date 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', 'idx_order_source_status_delete', '(`order_source`, `status`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_order_item', 'idx_order_item_artist_service_date', '(`artist_id`, `service_date`, `is_delete`)');
SET @drop_old_tag_unique_sql = (
SELECT IF(