cmvr-wms/sql/wms_optimization_20260916.sql

65 lines
3.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- WMS性能与人员账号规范化升级脚本,可在现有数据库上重复执行。
set @idx_exists = (select count(*) from information_schema.statistics
where table_schema = database() and table_name = 'sys_user' and index_name = 'idx_sys_user_user_name');
set @ddl = if(@idx_exists = 0, 'alter table sys_user add key idx_sys_user_user_name (user_name)', 'select 1');
prepare stmt from @ddl; execute stmt; deallocate prepare stmt;
set @idx_exists = (select count(*) from information_schema.statistics
where table_schema = database() and table_name = 'warehouse_area' and index_name = 'idx_warehouse_area_name');
set @ddl = if(@idx_exists = 0, 'alter table warehouse_area add key idx_warehouse_area_name (area_name)', 'select 1');
prepare stmt from @ddl; execute stmt; deallocate prepare stmt;
set @idx_exists = (select count(*) from information_schema.statistics
where table_schema = database() and table_name = 'product_info' and index_name = 'idx_product_info_identity');
set @ddl = if(@idx_exists = 0,
'alter table product_info add key idx_product_info_identity (product_name, brand, category, spec)', 'select 1');
prepare stmt from @ddl; execute stmt; deallocate prepare stmt;
set @idx_exists = (select count(*) from information_schema.statistics
where table_schema = database() and table_name = 'purchase_arrival'
and index_name = 'idx_purchase_arrival_request_status');
set @ddl = if(@idx_exists = 0,
'alter table purchase_arrival add key idx_purchase_arrival_request_status (purchase_request_id, acceptance_status)',
'select 1');
prepare stmt from @ddl; execute stmt; deallocate prepare stmt;
set @idx_exists = (select count(*) from information_schema.statistics
where table_schema = database() and table_name = 'wms_batch_item'
and index_name = 'idx_wms_batch_item_job_status');
set @ddl = if(@idx_exists = 0,
'alter table wms_batch_item add key idx_wms_batch_item_job_status (job_id, status)', 'select 1');
prepare stmt from @ddl; execute stmt; deallocate prepare stmt;
set @idx_exists = (select count(*) from information_schema.statistics
where table_schema = database() and table_name = 'wms_batch_job'
and index_name = 'idx_wms_batch_job_creator');
set @ddl = if(@idx_exists = 0,
'alter table wms_batch_job add key idx_wms_batch_job_creator (create_by, id)', 'select 1');
prepare stmt from @ddl; execute stmt; deallocate prepare stmt;
-- 仅在昵称唯一对应一个有效账号时迁移历史数据,避免同名用户被错误关联。
update in_record ir
join (
select nick_name, min(user_name) as user_name
from sys_user where del_flag = '0' and nick_name is not null and nick_name != ''
group by nick_name having count(*) = 1
) u on u.nick_name = ir.in_operator
set ir.in_operator = u.user_name;
update out_record orr
join (
select nick_name, min(user_name) as user_name
from sys_user where del_flag = '0' and nick_name is not null and nick_name != ''
group by nick_name having count(*) = 1
) u on u.nick_name = orr.out_operator
set orr.out_operator = u.user_name;
update stock_check_record scr
join (
select nick_name, min(user_name) as user_name
from sys_user where del_flag = '0' and nick_name is not null and nick_name != ''
group by nick_name having count(*) = 1
) u on u.nick_name = scr.check_user
set scr.check_user = u.user_name;