SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

-- 老生产库曾由早期 AutoMigrate 建表，缺少当前模型依赖的描述和创建时间列。
SET @ddl := IF(
  (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_app_configs' AND COLUMN_NAME = 'description') = 0,
  'ALTER TABLE admin_app_configs ADD COLUMN description VARCHAR(255) NOT NULL DEFAULT '''' COMMENT ''描述信息'' AFTER value',
  'SELECT 1'
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @ddl := IF(
  (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_app_configs' AND COLUMN_NAME = 'created_at_ms') = 0,
  'ALTER TABLE admin_app_configs ADD COLUMN created_at_ms BIGINT NOT NULL DEFAULT 0 COMMENT ''创建时间，UTC epoch ms'' AFTER description',
  'SELECT 1'
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @ddl := IF(
  (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_app_banners' AND COLUMN_NAME = 'created_at_ms') = 0,
  'ALTER TABLE admin_app_banners ADD COLUMN created_at_ms BIGINT NOT NULL DEFAULT 0 COMMENT ''创建时间，UTC epoch ms'' AFTER ends_at_ms',
  'SELECT 1'
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @ddl := IF(
  (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_app_versions' AND COLUMN_NAME = 'created_at_ms') = 0,
  'ALTER TABLE admin_app_versions ADD COLUMN created_at_ms BIGINT NOT NULL DEFAULT 0 COMMENT ''创建时间，UTC epoch ms'' AFTER description',
  'SELECT 1'
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
