SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'wh_stock_lot' AND COLUMN_NAME = 'logistics_waybill_no') = 0,
  'ALTER TABLE wh_stock_lot ADD COLUMN logistics_waybill_no VARCHAR(100) NULL COMMENT ''运单号'' AFTER source_material_summary',
  'SELECT ''wh_stock_lot.logistics_waybill_no already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'wh_stock_lot' AND COLUMN_NAME = 'logistics_freight_amount') = 0,
  'ALTER TABLE wh_stock_lot ADD COLUMN logistics_freight_amount DECIMAL(18,2) NULL COMMENT ''运费'' AFTER logistics_waybill_no',
  'SELECT ''wh_stock_lot.logistics_freight_amount already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'wh_stock_lot' AND COLUMN_NAME = 'logistics_photo_url') = 0,
  'ALTER TABLE wh_stock_lot ADD COLUMN logistics_photo_url VARCHAR(255) NULL COMMENT ''订单照片路径'' AFTER logistics_freight_amount',
  'SELECT ''wh_stock_lot.logistics_photo_url already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'wh_inventory_txn' AND COLUMN_NAME = 'logistics_waybill_no') = 0,
  'ALTER TABLE wh_inventory_txn ADD COLUMN logistics_waybill_no VARCHAR(100) NULL COMMENT ''运单号'' AFTER source_line_id',
  'SELECT ''wh_inventory_txn.logistics_waybill_no already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'wh_inventory_txn' AND COLUMN_NAME = 'logistics_freight_amount') = 0,
  'ALTER TABLE wh_inventory_txn ADD COLUMN logistics_freight_amount DECIMAL(18,2) NULL COMMENT ''运费'' AFTER logistics_waybill_no',
  'SELECT ''wh_inventory_txn.logistics_freight_amount already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'wh_inventory_txn' AND COLUMN_NAME = 'logistics_photo_url') = 0,
  'ALTER TABLE wh_inventory_txn ADD COLUMN logistics_photo_url VARCHAR(255) NULL COMMENT ''订单照片路径'' AFTER logistics_freight_amount',
  'SELECT ''wh_inventory_txn.logistics_photo_url already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'so_delivery' AND COLUMN_NAME = 'logistics_waybill_no') = 0,
  'ALTER TABLE so_delivery ADD COLUMN logistics_waybill_no VARCHAR(100) NULL COMMENT ''运单号'' AFTER delivery_address',
  'SELECT ''so_delivery.logistics_waybill_no already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'so_delivery' AND COLUMN_NAME = 'logistics_freight_amount') = 0,
  'ALTER TABLE so_delivery ADD COLUMN logistics_freight_amount DECIMAL(18,2) NULL COMMENT ''运费'' AFTER logistics_waybill_no',
  'SELECT ''so_delivery.logistics_freight_amount already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'so_delivery' AND COLUMN_NAME = 'logistics_photo_url') = 0,
  'ALTER TABLE so_delivery ADD COLUMN logistics_photo_url VARCHAR(255) NULL COMMENT ''订单照片路径'' AFTER logistics_freight_amount',
  'SELECT ''so_delivery.logistics_photo_url already exists'''
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
