-- 1.0.341 P-022 WP-2：去掉 IPQC 归口源表 tenant_id 的 DEFAULT 1300000000001（幂等）。
SET NAMES utf8mb4;

SET @has_def := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'qms_gcjyd' AND COLUMN_NAME = 'tenant_id'
    AND COLUMN_DEFAULT IS NOT NULL);
SET @sql := IF(@has_def > 0,
  'ALTER TABLE `qms_gcjyd` ALTER COLUMN `tenant_id` DROP DEFAULT',
  'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_def := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'qms_gcjydzb' AND COLUMN_NAME = 'tenant_id'
    AND COLUMN_DEFAULT IS NOT NULL);
SET @sql := IF(@has_def > 0,
  'ALTER TABLE `qms_gcjydzb` ALTER COLUMN `tenant_id` DROP DEFAULT',
  'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
