补建员工排班表迁移

This commit is contained in:
2026-07-01 13:11:39 +08:00
parent 5756d14fbd
commit da2c4239a0
@@ -0,0 +1,93 @@
CREATE DATABASE IF NOT EXISTS jayu_cloud DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
use jayu_cloud;
DROP PROCEDURE IF EXISTS sp_jy_add_index_if_not_exists;
DELIMITER $$
CREATE PROCEDURE sp_jy_add_index_if_not_exists(
IN p_table_name varchar(128),
IN p_index_name varchar(128),
IN p_index_sql varchar(1000)
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = p_table_name
AND index_name = p_index_name
) THEN
SET @jy_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD INDEX ', p_index_name, ' ', p_index_sql);
PREPARE jy_stmt FROM @jy_sql;
EXECUTE jy_stmt;
DEALLOCATE PREPARE jy_stmt;
END IF;
END$$
DELIMITER ;
DROP PROCEDURE IF EXISTS sp_jy_add_unique_index_if_not_exists;
DELIMITER $$
CREATE PROCEDURE sp_jy_add_unique_index_if_not_exists(
IN p_table_name varchar(128),
IN p_index_name varchar(128),
IN p_index_sql varchar(1000)
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = p_table_name
AND index_name = p_index_name
) THEN
SET @jy_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD UNIQUE INDEX ', p_index_name, ' ', p_index_sql);
PREPARE jy_stmt FROM @jy_sql;
EXECUTE jy_stmt;
DEALLOCATE PREPARE jy_stmt;
END IF;
END$$
DELIMITER ;
CREATE TABLE IF NOT EXISTS t_artist_schedule_rule
(
id bigint unsigned NOT NULL COMMENT '排班规则ID',
shop_id bigint unsigned NOT NULL COMMENT '店铺ID',
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID',
preset_type varchar(32) NOT NULL COMMENT '预设类型',
work_days varchar(32) NOT NULL COMMENT '工作星期,1-7逗号分隔',
start_time time NOT NULL COMMENT '常规开始时间',
end_time time NOT NULL COMMENT '常规结束时间',
slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟',
capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量',
status tinyint NOT NULL DEFAULT 1 COMMENT '状态:1启用,0停用',
remark varchar(255) NULL COMMENT '备注',
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='美甲师常规排班规则表';
CREATE TABLE IF NOT EXISTS t_artist_schedule_exception
(
id bigint unsigned NOT NULL COMMENT '排班例外ID',
shop_id bigint unsigned NOT NULL COMMENT '店铺ID',
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID',
work_date date NOT NULL COMMENT '例外日期',
exception_type varchar(32) NOT NULL COMMENT '例外类型:REST/EXTRA_WORK/CHANGE_SHIFT',
start_time time NULL COMMENT '例外开始时间',
end_time time NULL COMMENT '例外结束时间',
slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟',
capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量',
remark varchar(255) NULL COMMENT '备注',
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='美甲师排班例外表';
CALL sp_jy_add_unique_index_if_not_exists('t_artist_schedule_rule', 'uk_artist_schedule_rule_artist', '(`shop_id`, `artist_id`, `is_delete`)');
CALL sp_jy_add_index_if_not_exists('t_artist_schedule_rule', 'idx_artist_schedule_rule_shop_status', '(`shop_id`, `status`, `is_delete`)');
CALL sp_jy_add_unique_index_if_not_exists('t_artist_schedule_exception', 'uk_artist_schedule_exception_date', '(`shop_id`, `artist_id`, `work_date`, `is_delete`)');
CALL sp_jy_add_index_if_not_exists('t_artist_schedule_exception', 'idx_artist_schedule_exception_artist_date', '(`artist_id`, `work_date`, `is_delete`)');
DROP PROCEDURE IF EXISTS sp_jy_add_index_if_not_exists;
DROP PROCEDURE IF EXISTS sp_jy_add_unique_index_if_not_exists;