2026-10-28-inventory-transaction-stop-line.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. -- 库存流水记下装货/送货产品明细,同一产品的多段归档各自保留一条流水。
  2. -- MySQL 5.7 / utf8mb4。可重复执行。已有流水的两个字段为空,不改数量和金额。
  3. SET NAMES utf8mb4;
  4. SET @col_exists = (
  5. SELECT COUNT(*) FROM information_schema.COLUMNS
  6. WHERE TABLE_SCHEMA = DATABASE()
  7. AND TABLE_NAME = 'pl_inventory_transaction'
  8. AND COLUMN_NAME = 'stop_type'
  9. );
  10. SET @ddl = IF(
  11. @col_exists = 0,
  12. 'ALTER TABLE `pl_inventory_transaction` ADD COLUMN `stop_type` varchar(20) NOT NULL DEFAULT '''' COMMENT ''来源段类型:load装货 delivery送货,按产品归档为空'' AFTER `plan_no`',
  13. 'SELECT 1'
  14. );
  15. PREPARE stmt FROM @ddl;
  16. EXECUTE stmt;
  17. DEALLOCATE PREPARE stmt;
  18. SET @col_exists = (
  19. SELECT COUNT(*) FROM information_schema.COLUMNS
  20. WHERE TABLE_SCHEMA = DATABASE()
  21. AND TABLE_NAME = 'pl_inventory_transaction'
  22. AND COLUMN_NAME = 'stop_product_id'
  23. );
  24. SET @ddl = IF(
  25. @col_exists = 0,
  26. 'ALTER TABLE `pl_inventory_transaction` ADD COLUMN `stop_product_id` varchar(64) NOT NULL DEFAULT '''' COMMENT ''装货或送货产品明细ID,按产品归档为空'' AFTER `stop_type`',
  27. 'SELECT 1'
  28. );
  29. PREPARE stmt FROM @ddl;
  30. EXECUTE stmt;
  31. DEALLOCATE PREPARE stmt;