-- CP 关系成立飘屏需要复用申请来源送礼时的锁房快照，不能在用户同意申请时回查并改写历史房间状态。
-- 单列追加不参与索引或查询过滤；MySQL 8 使用 INSTANT 元数据变更，不扫描或重写申请表数据。
SET @room_locked_exists = (
  SELECT COUNT(*)
  FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'user_cp_applications'
    AND COLUMN_NAME = 'room_locked'
);

SET @room_locked_sql = IF(
  @room_locked_exists = 0,
  'ALTER TABLE user_cp_applications ADD COLUMN room_locked TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''触发送礼命令在 Room Cell 内固化的锁房状态'' AFTER room_region_id, ALGORITHM=INSTANT',
  'SELECT 1'
);

PREPARE room_locked_stmt FROM @room_locked_sql;
EXECUTE room_locked_stmt;
DEALLOCATE PREPARE room_locked_stmt;
