CREATE TABLE IF NOT EXISTS role_scope_policies (
  app_code VARCHAR(32) NOT NULL COMMENT '应用编码，用于多租户隔离',
  scene VARCHAR(64) NOT NULL COMMENT '角色范围业务场景',
  base_scope VARCHAR(16) NOT NULL COMMENT '默认范围：country/region/global',
  expanded_scope VARCHAR(16) NOT NULL COMMENT '扩展开关开启后的范围',
  region_expansion_configurable BOOLEAN NOT NULL DEFAULT FALSE COMMENT '是否允许经理个人扩区开关改变范围',
  created_at_ms BIGINT NOT NULL COMMENT '创建时间，UTC epoch ms',
  updated_at_ms BIGINT NOT NULL COMMENT '更新时间，UTC epoch ms',
  PRIMARY KEY (app_code, scene)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='App 角色范围 owner 配置';

SET @now_ms = CAST(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000 AS UNSIGNED);

-- INSERT IGNORE 只把旧运行时行为固化成初值；迁移重放不会覆盖已经由后台修改过的 owner 配置。
INSERT IGNORE INTO role_scope_policies (
  app_code, scene, base_scope, expanded_scope,
  region_expansion_configurable, created_at_ms, updated_at_ms
) VALUES
  ('huwaa', 'organization_role_expansion', 'global', 'global', FALSE, @now_ms, @now_ms),
  ('huwaa', 'manager_operations', 'global', 'global', FALSE, @now_ms, @now_ms);
