3 天以前 93327134ed36b2b514ce12af9a5f6b0e773718ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- =============================================
-- M4:SN 单品库存轻量闭环
-- 1. mes_wm_sn 增加在库库位维度列(status/batch_id/remark 表中已存在)
-- 2. mes_wm_transaction 增加 sn_code 列
-- 目标库:mom-xgdl(local profile)
-- =============================================
 
-- 1. mes_wm_sn.warehouse_id(在库仓库 ID)
SET @exists = (SELECT COUNT(*) FROM information_schema.columns
               WHERE table_schema = DATABASE() AND table_name = 'mes_wm_sn' AND column_name = 'warehouse_id');
SET @sql = IF(@exists = 0,
              'ALTER TABLE mes_wm_sn ADD COLUMN warehouse_id BIGINT NULL COMMENT ''在库仓库 ID'' AFTER batch_id',
              'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
 
-- 2. mes_wm_sn.location_id(在库库区 ID)
SET @exists = (SELECT COUNT(*) FROM information_schema.columns
               WHERE table_schema = DATABASE() AND table_name = 'mes_wm_sn' AND column_name = 'location_id');
SET @sql = IF(@exists = 0,
              'ALTER TABLE mes_wm_sn ADD COLUMN location_id BIGINT NULL COMMENT ''在库库区 ID'' AFTER warehouse_id',
              'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
 
-- 3. mes_wm_sn.area_id(在库库位 ID)
SET @exists = (SELECT COUNT(*) FROM information_schema.columns
               WHERE table_schema = DATABASE() AND table_name = 'mes_wm_sn' AND column_name = 'area_id');
SET @sql = IF(@exists = 0,
              'ALTER TABLE mes_wm_sn ADD COLUMN area_id BIGINT NULL COMMENT ''在库库位 ID'' AFTER location_id',
              'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
 
-- 4. mes_wm_transaction.sn_code(SN 码)
SET @exists = (SELECT COUNT(*) FROM information_schema.columns
               WHERE table_schema = DATABASE() AND table_name = 'mes_wm_transaction' AND column_name = 'sn_code');
SET @sql = IF(@exists = 0,
              'ALTER TABLE mes_wm_transaction ADD COLUMN sn_code VARCHAR(100) NULL COMMENT ''SN 码'' AFTER batch_code',
              'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;