-- 项目令号：金蝶生产/采购订单状态（0待建 1已建）
-- 若报 1060 Duplicate column name，说明列已存在，可忽略或只执行下方「仅改注释」段

-- ========== 首次加列（列已存在时会 1060，跳过即可）==========
ALTER TABLE `process_order_pro`
    ADD COLUMN `need_kingdee_prd_mo` tinyint(1) NOT NULL DEFAULT 0 COMMENT '金蝶生产订单：0待建 1已建' AFTER `source`,
    ADD COLUMN `need_kingdee_purchase_order` tinyint(1) NOT NULL DEFAULT 0 COMMENT '金蝶采购订单：0待建 1已建' AFTER `need_kingdee_prd_mo`;

-- ========== 幂等版（列不存在才 ADD，可整段单独执行）==========
/*
SET @db = DATABASE();

SET @sql = IF(
    (SELECT COUNT(*) FROM information_schema.COLUMNS
     WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'process_order_pro' AND COLUMN_NAME = 'need_kingdee_prd_mo') = 0,
    'ALTER TABLE `process_order_pro` ADD COLUMN `need_kingdee_prd_mo` tinyint(1) NOT NULL DEFAULT 0 COMMENT ''金蝶生产订单：0待建 1已建'' AFTER `source`',
    'SELECT ''need_kingdee_prd_mo already exists'' AS msg');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @sql = IF(
    (SELECT COUNT(*) FROM information_schema.COLUMNS
     WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'process_order_pro' AND COLUMN_NAME = 'need_kingdee_purchase_order') = 0,
    'ALTER TABLE `process_order_pro` ADD COLUMN `need_kingdee_purchase_order` tinyint(1) NOT NULL DEFAULT 0 COMMENT ''金蝶采购订单：0待建 1已建'' AFTER `need_kingdee_prd_mo`',
    'SELECT ''need_kingdee_purchase_order already exists'' AS msg');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
*/

-- ========== 验证 ==========
-- SHOW COLUMNS FROM process_order_pro LIKE 'need_kingdee%';
