CREATE TABLE IF NOT EXISTS bd_leader_profiles (
  app_code VARCHAR(32) NOT NULL DEFAULT 'lalu' COMMENT '应用编码，用于多租户隔离',
  user_id BIGINT NOT NULL PRIMARY KEY COMMENT '用户 ID',
  status VARCHAR(32) NOT NULL COMMENT '业务状态',
  created_by_user_id BIGINT NOT NULL COMMENT '创建人用户 ID',
  created_at_ms BIGINT NOT NULL COMMENT '创建时间，UTC epoch ms',
  updated_at_ms BIGINT NOT NULL COMMENT '更新时间，UTC epoch ms'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='BD Leader资料表';

INSERT INTO bd_leader_profiles (
  app_code, user_id, status, created_by_user_id, created_at_ms, updated_at_ms
)
SELECT app_code, user_id, status, created_by_user_id, created_at_ms, updated_at_ms
FROM bd_profiles
WHERE role = 'bd_leader'
ON DUPLICATE KEY UPDATE
  status = VALUES(status),
  created_by_user_id = VALUES(created_by_user_id),
  created_at_ms = VALUES(created_at_ms),
  updated_at_ms = VALUES(updated_at_ms);

DELETE FROM bd_profiles
WHERE role = 'bd_leader';
