feat: integrate required mobile market backend dependencies.
This commit is contained in:
1 parent
7e930c77fd
commit
337d31bbe8
30 files changed
+10951
-125
No files matched your search
@@ -0,0 +1,125 @@
|
||||
-- 移动市场现场 scope 查询复合索引
|
||||
-- MySQL 5.7;通过 information_schema + PREPARE 保证重复执行安全。
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET @db := DATABASE();
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_collection_region_staff'
|
||||
AND INDEX_NAME = 'idx_crs_market_leader_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_collection_region_staff` ADD INDEX `idx_crs_market_leader_scope` (`tenant_no`,`user_id`,`is_leader`,`del_flag`,`region_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_presign_order'
|
||||
AND INDEX_NAME = 'idx_po_market_sales_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_presign_order` ADD INDEX `idx_po_market_sales_scope` (`tenant_no`,`del_flag`,`sales_user_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_presign_order'
|
||||
AND INDEX_NAME = 'idx_po_market_region_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_presign_order` ADD INDEX `idx_po_market_region_scope` (`tenant_no`,`del_flag`,`region_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_presign_order'
|
||||
AND INDEX_NAME = 'idx_po_market_manager_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_presign_order` ADD INDEX `idx_po_market_manager_scope` (`tenant_no`,`del_flag`,`region_manager_user_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_protocol_collection_info'
|
||||
AND INDEX_NAME = 'idx_pci_market_parent_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_protocol_collection_info` ADD INDEX `idx_pci_market_parent_scope` (`tenant_no`,`del_flag`,`collection_protocol_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_protocol_collection_info'
|
||||
AND INDEX_NAME = 'idx_pci_market_sales_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_protocol_collection_info` ADD INDEX `idx_pci_market_sales_scope` (`tenant_no`,`del_flag`,`sales_user_id`,`collection_protocol_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_protocol_collection_info'
|
||||
AND INDEX_NAME = 'idx_pci_market_region_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_protocol_collection_info` ADD INDEX `idx_pci_market_region_scope` (`tenant_no`,`del_flag`,`region_id`,`collection_protocol_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_protocol_collection_info'
|
||||
AND INDEX_NAME = 'idx_pci_market_manager_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_protocol_collection_info` ADD INDEX `idx_pci_market_manager_scope` (`tenant_no`,`del_flag`,`region_manager_user_id`,`collection_protocol_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_research_donation_collection'
|
||||
AND INDEX_NAME = 'idx_rdc_market_parent_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_research_donation_collection` ADD INDEX `idx_rdc_market_parent_scope` (`tenant_no`,`del_flag`,`research_donation_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_research_donation_collection'
|
||||
AND INDEX_NAME = 'idx_rdc_market_sales_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_research_donation_collection` ADD INDEX `idx_rdc_market_sales_scope` (`tenant_no`,`del_flag`,`sales_user_id`,`research_donation_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_research_donation_collection'
|
||||
AND INDEX_NAME = 'idx_rdc_market_region_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_research_donation_collection` ADD INDEX `idx_rdc_market_region_scope` (`tenant_no`,`del_flag`,`region_id`,`research_donation_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @idx_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'biz_research_donation_collection'
|
||||
AND INDEX_NAME = 'idx_rdc_market_manager_scope'
|
||||
);
|
||||
SET @sql := IF(@idx_exists = 0,
|
||||
'ALTER TABLE `biz_research_donation_collection` ADD INDEX `idx_rdc_market_manager_scope` (`tenant_no`,`del_flag`,`region_manager_user_id`,`research_donation_id`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
@@ -0,0 +1,243 @@
|
||||
-- =============================================================================
|
||||
-- 小程序市场现场菜单:市场专员 / 地区经理两套目录与十二个业务叶子
|
||||
--
|
||||
-- 说明:
|
||||
-- 1. 面向每个租户已有的「移动端菜单」根生成菜单,不写死租户编号。
|
||||
-- 2. 目录仅用于角色授权分组,path 为空;首页只展示叶子。
|
||||
-- 3. 不在此处写入 sys_role_menu;由管理员在 Web 角色管理中手工勾选。
|
||||
-- 4. MySQL 5.7 可执行;所有 INSERT 均以 NOT EXISTS 保证幂等。
|
||||
-- =============================================================================
|
||||
|
||||
-- 市场专员目录
|
||||
INSERT INTO sys_menu (
|
||||
id, menu_name, parent_id, menu_type, path, component, perms,
|
||||
is_frame, visible, status, tenant_no, order_num, remark,
|
||||
create_by, create_dept_id, create_time, update_by, update_time, del_flag
|
||||
)
|
||||
SELECT
|
||||
MD5(CONCAT(
|
||||
'mobile-market-directory|', root.tenant_no, '|', root.id, '|M||市场专员'
|
||||
)),
|
||||
'市场专员',
|
||||
root.id,
|
||||
'M',
|
||||
'',
|
||||
NULL,
|
||||
NULL,
|
||||
1,
|
||||
'1',
|
||||
'1',
|
||||
root.tenant_no,
|
||||
10,
|
||||
'小程序市场现场:市场专员菜单目录',
|
||||
NULL,
|
||||
'',
|
||||
NOW(),
|
||||
NULL,
|
||||
NOW(),
|
||||
0
|
||||
FROM sys_menu root
|
||||
WHERE root.parent_id = '0'
|
||||
AND root.menu_name = '移动端菜单'
|
||||
AND root.del_flag = 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_menu existing
|
||||
WHERE existing.tenant_no = root.tenant_no
|
||||
AND existing.parent_id = root.id
|
||||
AND existing.menu_name = '市场专员'
|
||||
AND existing.menu_type = 'M'
|
||||
AND existing.path = ''
|
||||
AND existing.del_flag = 0
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
tenant_no = VALUES(tenant_no),
|
||||
parent_id = VALUES(parent_id),
|
||||
menu_name = VALUES(menu_name),
|
||||
menu_type = VALUES(menu_type),
|
||||
path = VALUES(path),
|
||||
component = VALUES(component),
|
||||
perms = VALUES(perms),
|
||||
is_frame = VALUES(is_frame),
|
||||
visible = VALUES(visible),
|
||||
status = VALUES(status),
|
||||
order_num = VALUES(order_num),
|
||||
remark = VALUES(remark),
|
||||
update_time = VALUES(update_time),
|
||||
del_flag = VALUES(del_flag);
|
||||
|
||||
-- 地区经理目录
|
||||
INSERT INTO sys_menu (
|
||||
id, menu_name, parent_id, menu_type, path, component, perms,
|
||||
is_frame, visible, status, tenant_no, order_num, remark,
|
||||
create_by, create_dept_id, create_time, update_by, update_time, del_flag
|
||||
)
|
||||
SELECT
|
||||
MD5(CONCAT(
|
||||
'mobile-market-directory|', root.tenant_no, '|', root.id, '|M||地区经理'
|
||||
)),
|
||||
'地区经理',
|
||||
root.id,
|
||||
'M',
|
||||
'',
|
||||
NULL,
|
||||
NULL,
|
||||
1,
|
||||
'1',
|
||||
'1',
|
||||
root.tenant_no,
|
||||
20,
|
||||
'小程序市场现场:地区经理菜单目录',
|
||||
NULL,
|
||||
'',
|
||||
NOW(),
|
||||
NULL,
|
||||
NOW(),
|
||||
0
|
||||
FROM sys_menu root
|
||||
WHERE root.parent_id = '0'
|
||||
AND root.menu_name = '移动端菜单'
|
||||
AND root.del_flag = 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_menu existing
|
||||
WHERE existing.tenant_no = root.tenant_no
|
||||
AND existing.parent_id = root.id
|
||||
AND existing.menu_name = '地区经理'
|
||||
AND existing.menu_type = 'M'
|
||||
AND existing.path = ''
|
||||
AND existing.del_flag = 0
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
tenant_no = VALUES(tenant_no),
|
||||
parent_id = VALUES(parent_id),
|
||||
menu_name = VALUES(menu_name),
|
||||
menu_type = VALUES(menu_type),
|
||||
path = VALUES(path),
|
||||
component = VALUES(component),
|
||||
perms = VALUES(perms),
|
||||
is_frame = VALUES(is_frame),
|
||||
visible = VALUES(visible),
|
||||
status = VALUES(status),
|
||||
order_num = VALUES(order_num),
|
||||
remark = VALUES(remark),
|
||||
update_time = VALUES(update_time),
|
||||
del_flag = VALUES(del_flag);
|
||||
|
||||
-- 十二个业务叶子:每个角色目录各六个,均进入小程序受控 web-view。
|
||||
INSERT INTO sys_menu (
|
||||
id, menu_name, parent_id, menu_type, path, component, perms,
|
||||
is_frame, visible, status, tenant_no, order_num, remark,
|
||||
create_by, create_dept_id, create_time, update_by, update_time, del_flag
|
||||
)
|
||||
SELECT
|
||||
MD5(CONCAT(
|
||||
'mobile-market-leaf|', root.tenant_no, '|', root.id, '|', directory.id,
|
||||
'|', entry.path, '|', entry.perms
|
||||
)),
|
||||
entry.menu_name,
|
||||
directory.id,
|
||||
'C',
|
||||
entry.path,
|
||||
NULL,
|
||||
entry.perms,
|
||||
1,
|
||||
'1',
|
||||
'1',
|
||||
root.tenant_no,
|
||||
entry.order_num,
|
||||
CONCAT('小程序市场现场:', entry.role_name, ' / ', entry.menu_name),
|
||||
NULL,
|
||||
'',
|
||||
NOW(),
|
||||
NULL,
|
||||
NOW(),
|
||||
0
|
||||
FROM sys_menu root
|
||||
INNER JOIN (
|
||||
SELECT 'specialist' AS role_code, '市场专员' AS role_name,
|
||||
'presign' AS module_code, '预签约订单' AS menu_name,
|
||||
'/pages/market/webview/index?entry=specialist-presign' AS path,
|
||||
'mini:market:specialist:presign' AS perms, 10 AS order_num
|
||||
UNION ALL
|
||||
SELECT 'specialist', '市场专员', 'protocol', '协议单',
|
||||
'/pages/market/webview/index?entry=specialist-protocol',
|
||||
'mini:market:specialist:protocol', 20
|
||||
UNION ALL
|
||||
SELECT 'specialist', '市场专员', 'payment-chase', '催缴信息',
|
||||
'/pages/market/webview/index?entry=specialist-payment-chase',
|
||||
'mini:market:specialist:payment-chase', 30
|
||||
UNION ALL
|
||||
SELECT 'specialist', '市场专员', 'payment', '缴费信息',
|
||||
'/pages/market/webview/index?entry=specialist-payment',
|
||||
'mini:market:specialist:payment', 40
|
||||
UNION ALL
|
||||
SELECT 'specialist', '市场专员', 'sample', '样本信息',
|
||||
'/pages/market/webview/index?entry=specialist-sample',
|
||||
'mini:market:specialist:sample', 50
|
||||
UNION ALL
|
||||
SELECT 'specialist', '市场专员', 'freight', '运费信息',
|
||||
'/pages/market/webview/index?entry=specialist-freight',
|
||||
'mini:market:specialist:freight', 60
|
||||
UNION ALL
|
||||
SELECT 'manager', '地区经理', 'presign', '预签约订单',
|
||||
'/pages/market/webview/index?entry=manager-presign',
|
||||
'mini:market:manager:presign', 10
|
||||
UNION ALL
|
||||
SELECT 'manager', '地区经理', 'protocol', '协议单',
|
||||
'/pages/market/webview/index?entry=manager-protocol',
|
||||
'mini:market:manager:protocol', 20
|
||||
UNION ALL
|
||||
SELECT 'manager', '地区经理', 'payment-chase', '催缴信息',
|
||||
'/pages/market/webview/index?entry=manager-payment-chase',
|
||||
'mini:market:manager:payment-chase', 30
|
||||
UNION ALL
|
||||
SELECT 'manager', '地区经理', 'payment', '缴费信息',
|
||||
'/pages/market/webview/index?entry=manager-payment',
|
||||
'mini:market:manager:payment', 40
|
||||
UNION ALL
|
||||
SELECT 'manager', '地区经理', 'sample', '样本信息',
|
||||
'/pages/market/webview/index?entry=manager-sample',
|
||||
'mini:market:manager:sample', 50
|
||||
UNION ALL
|
||||
SELECT 'manager', '地区经理', 'freight', '运费信息',
|
||||
'/pages/market/webview/index?entry=manager-freight',
|
||||
'mini:market:manager:freight', 60
|
||||
) entry
|
||||
ON 1 = 1
|
||||
INNER JOIN sys_menu directory
|
||||
ON directory.tenant_no = root.tenant_no
|
||||
AND directory.parent_id = root.id
|
||||
AND directory.menu_name = entry.role_name
|
||||
AND directory.menu_type = 'M'
|
||||
AND directory.path = ''
|
||||
AND directory.del_flag = 0
|
||||
WHERE root.parent_id = '0'
|
||||
AND root.menu_name = '移动端菜单'
|
||||
AND root.del_flag = 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_menu existing
|
||||
WHERE existing.tenant_no = root.tenant_no
|
||||
AND existing.parent_id = directory.id
|
||||
AND existing.menu_name = entry.menu_name
|
||||
AND existing.perms = entry.perms
|
||||
AND existing.path = entry.path
|
||||
AND existing.menu_type = 'C'
|
||||
AND existing.del_flag = 0
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
tenant_no = VALUES(tenant_no),
|
||||
parent_id = VALUES(parent_id),
|
||||
menu_name = VALUES(menu_name),
|
||||
menu_type = VALUES(menu_type),
|
||||
path = VALUES(path),
|
||||
component = VALUES(component),
|
||||
perms = VALUES(perms),
|
||||
is_frame = VALUES(is_frame),
|
||||
visible = VALUES(visible),
|
||||
status = VALUES(status),
|
||||
order_num = VALUES(order_num),
|
||||
remark = VALUES(remark),
|
||||
update_time = VALUES(update_time),
|
||||
del_flag = VALUES(del_flag);
|
||||
@@ -0,0 +1,56 @@
|
||||
-- 预签约订单转正式协议唯一约束
|
||||
-- MySQL 5.7;重复执行安全。历史重复或错误同名索引会给出明确修复提示。
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
DROP PROCEDURE IF EXISTS `ensure_presign_convert_unique`$$
|
||||
CREATE PROCEDURE `ensure_presign_convert_unique`()
|
||||
BEGIN
|
||||
DECLARE duplicate_sources INT DEFAULT 0;
|
||||
DECLARE idx_entries INT DEFAULT 0;
|
||||
DECLARE idx_non_unique INT DEFAULT 1;
|
||||
DECLARE idx_columns VARCHAR(512) DEFAULT '';
|
||||
|
||||
SELECT COUNT(*) INTO duplicate_sources
|
||||
FROM (
|
||||
SELECT `tenant_no`, `source_presign_order_id`
|
||||
FROM `biz_collection_protocol`
|
||||
WHERE `source_presign_order_id` IS NOT NULL
|
||||
AND `source_presign_order_id` <> ''
|
||||
GROUP BY `tenant_no`, `source_presign_order_id`
|
||||
HAVING COUNT(*) > 1
|
||||
) duplicate_rows;
|
||||
|
||||
IF duplicate_sources > 0 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'duplicate presign conversions found; remediation: reconcile duplicate formal protocols before rerunning migration';
|
||||
END IF;
|
||||
|
||||
SELECT
|
||||
COUNT(*),
|
||||
COALESCE(MIN(NON_UNIQUE), 1),
|
||||
COALESCE(GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX SEPARATOR ','), '')
|
||||
INTO idx_entries, idx_non_unique, idx_columns
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_collection_protocol'
|
||||
AND INDEX_NAME = 'uk_collection_protocol_presign_source';
|
||||
|
||||
IF idx_entries = 0 THEN
|
||||
ALTER TABLE `biz_collection_protocol`
|
||||
ADD UNIQUE INDEX `uk_collection_protocol_presign_source`
|
||||
(`tenant_no`, `source_presign_order_id`);
|
||||
ELSEIF idx_entries <> 2
|
||||
OR idx_non_unique <> 0
|
||||
OR idx_columns <> 'tenant_no,source_presign_order_id' THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'wrong index uk_collection_protocol_presign_source; remediation: drop or rename it, then rerun migration';
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
CALL `ensure_presign_convert_unique`()$$
|
||||
DROP PROCEDURE `ensure_presign_convert_unique`$$
|
||||
|
||||
DELIMITER ;
|
||||
@@ -0,0 +1,192 @@
|
||||
-- 市场移动端运费批次查询与并发关联约束(MySQL 5.7,幂等)。
|
||||
-- 若存量数据冲突或同名对象定义错误则明确中止,不静默移动/删除数据。
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
DROP PROCEDURE IF EXISTS `ensure_market_freight_indexes`$$
|
||||
CREATE PROCEDURE `ensure_market_freight_indexes`()
|
||||
BEGIN
|
||||
DECLARE duplicate_rows INT DEFAULT 0;
|
||||
DECLARE object_count INT DEFAULT 0;
|
||||
DECLARE index_non_unique INT DEFAULT 1;
|
||||
DECLARE index_columns VARCHAR(512) DEFAULT '';
|
||||
DECLARE index_prefix_count INT DEFAULT 0;
|
||||
DECLARE index_type_count INT DEFAULT 0;
|
||||
DECLARE index_type_name VARCHAR(32) DEFAULT '';
|
||||
DECLARE generated_extra VARCHAR(255) DEFAULT '';
|
||||
DECLARE generated_expression TEXT;
|
||||
DECLARE normalized_generation_expression TEXT;
|
||||
DECLARE generated_data_type VARCHAR(64) DEFAULT '';
|
||||
DECLARE generated_length BIGINT DEFAULT 0;
|
||||
DECLARE generated_nullable VARCHAR(3) DEFAULT '';
|
||||
DECLARE exact_freight_unique_indexes INT DEFAULT 0;
|
||||
|
||||
SELECT COUNT(*) INTO duplicate_rows
|
||||
FROM (
|
||||
SELECT tenant_no, freight_no
|
||||
FROM biz_sample_freight
|
||||
GROUP BY tenant_no, freight_no
|
||||
HAVING COUNT(*) > 1
|
||||
) duplicate_freights;
|
||||
IF duplicate_rows > 0 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'duplicate freight numbers found; reconcile them before rerunning migration';
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO duplicate_rows
|
||||
FROM (
|
||||
SELECT tenant_no, sample_source, sample_id
|
||||
FROM biz_sample_freight_item
|
||||
WHERE del_flag = 0
|
||||
GROUP BY tenant_no, sample_source, sample_id
|
||||
HAVING COUNT(*) > 1
|
||||
) duplicate_active_links;
|
||||
IF duplicate_rows > 0 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'duplicate active sample freight links found; reconcile them before rerunning migration';
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO object_count
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_sample_freight_item'
|
||||
AND COLUMN_NAME = 'active_sample_key';
|
||||
IF object_count = 0 THEN
|
||||
ALTER TABLE biz_sample_freight_item
|
||||
ADD COLUMN active_sample_key VARCHAR(170)
|
||||
GENERATED ALWAYS AS (
|
||||
IF(del_flag = 0, CONCAT(tenant_no, '#', sample_source, '#', sample_id), NULL)
|
||||
) STORED;
|
||||
ELSE
|
||||
SELECT EXTRA, GENERATION_EXPRESSION, DATA_TYPE,
|
||||
CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE
|
||||
INTO generated_extra, generated_expression, generated_data_type,
|
||||
generated_length, generated_nullable
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_sample_freight_item'
|
||||
AND COLUMN_NAME = 'active_sample_key';
|
||||
SET normalized_generation_expression = LOWER(
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
COALESCE(generated_expression, ''),
|
||||
'`', ''), ' ', ''), CHAR(9), ''), CHAR(10), ''), '(', ''), ')', '')
|
||||
);
|
||||
IF UPPER(COALESCE(generated_extra, '')) NOT LIKE '%STORED GENERATED%'
|
||||
OR LOWER(COALESCE(generated_data_type, '')) <> 'varchar'
|
||||
OR COALESCE(generated_length, 0) <> 170
|
||||
OR UPPER(COALESCE(generated_nullable, '')) <> 'YES'
|
||||
OR normalized_generation_expression <>
|
||||
'ifdel_flag=0,concattenant_no,''#'',sample_source,''#'',sample_id,null' THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'wrong active_sample_key type/expression; drop column and dependent index, then rerun migration';
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*), COALESCE(MIN(NON_UNIQUE), 1),
|
||||
COALESCE(GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX SEPARATOR ','), ''),
|
||||
SUM(CASE WHEN SUB_PART IS NOT NULL THEN 1 ELSE 0 END),
|
||||
COUNT(DISTINCT INDEX_TYPE), COALESCE(MIN(INDEX_TYPE), '')
|
||||
INTO object_count, index_non_unique, index_columns,
|
||||
index_prefix_count, index_type_count, index_type_name
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_sample_freight_item'
|
||||
AND INDEX_NAME = 'uk_bsfi_active_sample';
|
||||
IF object_count = 0 THEN
|
||||
ALTER TABLE biz_sample_freight_item
|
||||
ADD UNIQUE INDEX uk_bsfi_active_sample (active_sample_key);
|
||||
ELSEIF object_count <> 1 OR index_non_unique <> 0
|
||||
OR index_columns <> 'active_sample_key' OR index_prefix_count <> 0
|
||||
OR index_type_count <> 1 OR index_type_name <> 'BTREE' THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'wrong index uk_bsfi_active_sample; drop it and rerun migration';
|
||||
END IF;
|
||||
|
||||
-- 旧迁移已创建 uk_sample_freight_tenant_no;任何名称的等价精确唯一索引均复用。
|
||||
-- 但若本迁移预留名称已存在且定义错误,必须先修复,不能静默绕过。
|
||||
SELECT COUNT(*), COALESCE(MIN(NON_UNIQUE), 1),
|
||||
COALESCE(GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX SEPARATOR ','), ''),
|
||||
SUM(CASE WHEN SUB_PART IS NOT NULL THEN 1 ELSE 0 END),
|
||||
COUNT(DISTINCT INDEX_TYPE), COALESCE(MIN(INDEX_TYPE), '')
|
||||
INTO object_count, index_non_unique, index_columns,
|
||||
index_prefix_count, index_type_count, index_type_name
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_sample_freight'
|
||||
AND INDEX_NAME = 'uk_bsf_tenant_freight_no';
|
||||
IF object_count > 0 AND (object_count <> 2 OR index_non_unique <> 0
|
||||
OR index_columns <> 'tenant_no,freight_no' OR index_prefix_count <> 0
|
||||
OR index_type_count <> 1 OR index_type_name <> 'BTREE') THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'wrong index uk_bsf_tenant_freight_no; drop it and rerun migration';
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO exact_freight_unique_indexes
|
||||
FROM (
|
||||
SELECT INDEX_NAME
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_sample_freight'
|
||||
GROUP BY INDEX_NAME
|
||||
HAVING MIN(NON_UNIQUE) = 0
|
||||
AND MAX(NON_UNIQUE) = 0
|
||||
AND GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX SEPARATOR ',') =
|
||||
'tenant_no,freight_no'
|
||||
AND SUM(CASE WHEN SUB_PART IS NOT NULL THEN 1 ELSE 0 END) = 0
|
||||
AND COUNT(DISTINCT INDEX_TYPE) = 1
|
||||
AND MIN(INDEX_TYPE) = 'BTREE'
|
||||
) exact_freight_unique_index_definitions;
|
||||
IF exact_freight_unique_indexes = 0 THEN
|
||||
ALTER TABLE biz_sample_freight
|
||||
ADD UNIQUE INDEX uk_bsf_tenant_freight_no (tenant_no, freight_no);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*), COALESCE(MIN(NON_UNIQUE), 1),
|
||||
COALESCE(GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX SEPARATOR ','), ''),
|
||||
SUM(CASE WHEN SUB_PART IS NOT NULL THEN 1 ELSE 0 END),
|
||||
COUNT(DISTINCT INDEX_TYPE), COALESCE(MIN(INDEX_TYPE), '')
|
||||
INTO object_count, index_non_unique, index_columns,
|
||||
index_prefix_count, index_type_count, index_type_name
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_sample_freight'
|
||||
AND INDEX_NAME = 'idx_bsf_market_list';
|
||||
IF object_count = 0 THEN
|
||||
ALTER TABLE biz_sample_freight
|
||||
ADD INDEX idx_bsf_market_list (tenant_no, del_flag, create_time, id);
|
||||
ELSEIF object_count <> 4 OR index_non_unique <> 1
|
||||
OR index_columns <> 'tenant_no,del_flag,create_time,id'
|
||||
OR index_prefix_count <> 0 OR index_type_count <> 1
|
||||
OR index_type_name <> 'BTREE' THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'wrong index idx_bsf_market_list; drop it and rerun migration';
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*), COALESCE(MIN(NON_UNIQUE), 1),
|
||||
COALESCE(GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX SEPARATOR ','), ''),
|
||||
SUM(CASE WHEN SUB_PART IS NOT NULL THEN 1 ELSE 0 END),
|
||||
COUNT(DISTINCT INDEX_TYPE), COALESCE(MIN(INDEX_TYPE), '')
|
||||
INTO object_count, index_non_unique, index_columns,
|
||||
index_prefix_count, index_type_count, index_type_name
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_sample_freight_item'
|
||||
AND INDEX_NAME = 'idx_bsfi_market_batch';
|
||||
IF object_count = 0 THEN
|
||||
ALTER TABLE biz_sample_freight_item
|
||||
ADD INDEX idx_bsfi_market_batch (tenant_no, freight_id, del_flag, create_time, id);
|
||||
ELSEIF object_count <> 5 OR index_non_unique <> 1
|
||||
OR index_columns <> 'tenant_no,freight_id,del_flag,create_time,id'
|
||||
OR index_prefix_count <> 0 OR index_type_count <> 1
|
||||
OR index_type_name <> 'BTREE' THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'wrong index idx_bsfi_market_batch; drop it and rerun migration';
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
CALL `ensure_market_freight_indexes`()$$
|
||||
DROP PROCEDURE `ensure_market_freight_indexes`$$
|
||||
|
||||
DELIMITER ;
|
||||
@@ -0,0 +1,70 @@
|
||||
-- 市场移动端催缴/缴费查询索引(MySQL 5.7)。
|
||||
-- 同名索引定义不一致时重建,重复执行保持幂等。
|
||||
|
||||
SET @schema_name = DATABASE();
|
||||
|
||||
SET @index_name = 'idx_biz_protocol_payment_schedule_market_scope';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','),
|
||||
MIN(non_unique),
|
||||
MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END),
|
||||
COUNT(DISTINCT index_type),
|
||||
MIN(index_type)
|
||||
INTO @index_columns,
|
||||
@index_non_unique_min,
|
||||
@index_non_unique_max,
|
||||
@index_prefix_columns,
|
||||
@index_type_count,
|
||||
@index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name
|
||||
AND table_name = 'biz_protocol_payment_schedule'
|
||||
AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,sample_payment_id,del_flag'
|
||||
AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1
|
||||
AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1
|
||||
AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_protocol_payment_schedule ADD INDEX idx_biz_protocol_payment_schedule_market_scope (tenant_no, sample_payment_id, del_flag)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_protocol_payment_schedule DROP INDEX idx_biz_protocol_payment_schedule_market_scope, ADD INDEX idx_biz_protocol_payment_schedule_market_scope (tenant_no, sample_payment_id, del_flag)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @index_name = 'idx_biz_protocol_payment_transfer_market_scope';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','),
|
||||
MIN(non_unique),
|
||||
MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END),
|
||||
COUNT(DISTINCT index_type),
|
||||
MIN(index_type)
|
||||
INTO @index_columns,
|
||||
@index_non_unique_min,
|
||||
@index_non_unique_max,
|
||||
@index_prefix_columns,
|
||||
@index_type_count,
|
||||
@index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name
|
||||
AND table_name = 'biz_protocol_payment_transfer'
|
||||
AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,schedule_id,del_flag'
|
||||
AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1
|
||||
AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1
|
||||
AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_protocol_payment_transfer ADD INDEX idx_biz_protocol_payment_transfer_market_scope (tenant_no, schedule_id, del_flag)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_protocol_payment_transfer DROP INDEX idx_biz_protocol_payment_transfer_market_scope, ADD INDEX idx_biz_protocol_payment_transfer_market_scope (tenant_no, schedule_id, del_flag)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
@@ -0,0 +1,175 @@
|
||||
-- 市场移动端样本统一列表、进度与轻量办理索引(MySQL 5.7)。
|
||||
-- 同名索引的列顺序、唯一性、前缀或类型不一致时重建;重复执行保持幂等。
|
||||
|
||||
SET @schema_name = DATABASE();
|
||||
|
||||
SET @table_name = 'biz_protocol_sample';
|
||||
SET @index_name = 'idx_bps_market_sample_code';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,del_flag,sample_code' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_protocol_sample ADD INDEX idx_bps_market_sample_code (tenant_no, del_flag, sample_code)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_protocol_sample DROP INDEX idx_bps_market_sample_code, ADD INDEX idx_bps_market_sample_code (tenant_no, del_flag, sample_code)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_protocol_sample';
|
||||
SET @index_name = 'idx_bps_market_parent';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,del_flag,collection_protocol_id' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_protocol_sample ADD INDEX idx_bps_market_parent (tenant_no, del_flag, collection_protocol_id)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_protocol_sample DROP INDEX idx_bps_market_parent, ADD INDEX idx_bps_market_parent (tenant_no, del_flag, collection_protocol_id)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_research_donation_sample';
|
||||
SET @index_name = 'idx_brds_market_sample_code';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,del_flag,sample_code' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_research_donation_sample ADD INDEX idx_brds_market_sample_code (tenant_no, del_flag, sample_code)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_research_donation_sample DROP INDEX idx_brds_market_sample_code, ADD INDEX idx_brds_market_sample_code (tenant_no, del_flag, sample_code)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_research_donation_sample';
|
||||
SET @index_name = 'idx_brds_market_parent';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,del_flag,research_donation_id' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_research_donation_sample ADD INDEX idx_brds_market_parent (tenant_no, del_flag, research_donation_id)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_research_donation_sample DROP INDEX idx_brds_market_parent, ADD INDEX idx_brds_market_parent (tenant_no, del_flag, research_donation_id)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_sample_reception';
|
||||
SET @index_name = 'idx_bsr_market_sample_progress';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,reception_source,sample_code,del_flag,reception_time' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_sample_reception ADD INDEX idx_bsr_market_sample_progress (tenant_no, reception_source, sample_code, del_flag, reception_time)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_sample_reception DROP INDEX idx_bsr_market_sample_progress, ADD INDEX idx_bsr_market_sample_progress (tenant_no, reception_source, sample_code, del_flag, reception_time)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_qc_work_order';
|
||||
SET @index_name = 'idx_bqwo_market_sample_progress';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,reception_source,trigger_source,sample_code,del_flag' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_qc_work_order ADD INDEX idx_bqwo_market_sample_progress (tenant_no, reception_source, trigger_source, sample_code, del_flag)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_qc_work_order DROP INDEX idx_bqwo_market_sample_progress, ADD INDEX idx_bqwo_market_sample_progress (tenant_no, reception_source, trigger_source, sample_code, del_flag)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_storage_release_review';
|
||||
SET @index_name = 'idx_bsrr_market_sample_progress';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,reception_source,sample_code,del_flag,storage_time' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_storage_release_review ADD INDEX idx_bsrr_market_sample_progress (tenant_no, reception_source, sample_code, del_flag, storage_time)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_storage_release_review DROP INDEX idx_bsrr_market_sample_progress, ADD INDEX idx_bsrr_market_sample_progress (tenant_no, reception_source, sample_code, del_flag, storage_time)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_protocol_storage_cert';
|
||||
SET @index_name = 'idx_bpsc_market_parent';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,collection_protocol_id,del_flag' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_protocol_storage_cert ADD INDEX idx_bpsc_market_parent (tenant_no, collection_protocol_id, del_flag)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_protocol_storage_cert DROP INDEX idx_bpsc_market_parent, ADD INDEX idx_bpsc_market_parent (tenant_no, collection_protocol_id, del_flag)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @table_name = 'biz_protocol_fullmoon_todo';
|
||||
SET @index_name = 'idx_bpft_market_parent';
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index SEPARATOR ','), MIN(non_unique), MAX(non_unique),
|
||||
SUM(CASE WHEN sub_part IS NOT NULL THEN 1 ELSE 0 END), COUNT(DISTINCT index_type), MIN(index_type)
|
||||
INTO @index_columns, @index_non_unique_min, @index_non_unique_max,
|
||||
@index_prefix_columns, @index_type_count, @index_type
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name AND table_name = @table_name AND index_name = @index_name;
|
||||
SET @ddl = CASE
|
||||
WHEN @index_columns = 'tenant_no,collection_protocol_id,del_flag' AND @index_non_unique_min = 1
|
||||
AND @index_non_unique_max = 1 AND @index_prefix_columns = 0
|
||||
AND @index_type_count = 1 AND @index_type = 'BTREE' THEN 'SELECT 1'
|
||||
WHEN @index_columns IS NULL THEN
|
||||
'ALTER TABLE biz_protocol_fullmoon_todo ADD INDEX idx_bpft_market_parent (tenant_no, collection_protocol_id, del_flag)'
|
||||
ELSE
|
||||
'ALTER TABLE biz_protocol_fullmoon_todo DROP INDEX idx_bpft_market_parent, ADD INDEX idx_bpft_market_parent (tenant_no, collection_protocol_id, del_flag)'
|
||||
END;
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
Reference in new issue
Block a user