CREATE TABLE IF NOT EXISTS admin_data_scopes (
  id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
  role_id BIGINT UNSIGNED NOT NULL,
  scope_type VARCHAR(40) NOT NULL,
  scope_value VARCHAR(120) NOT NULL,
  created_at_ms BIGINT NOT NULL,
  updated_at_ms BIGINT NOT NULL,
  UNIQUE KEY uk_admin_data_scopes_role_scope (role_id, scope_type, scope_value),
  INDEX idx_admin_data_scopes_role_id (role_id),
  INDEX idx_admin_data_scopes_scope (scope_type, scope_value)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS admin_jobs (
  id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
  type VARCHAR(80) NOT NULL,
  status VARCHAR(32) NOT NULL,
  payload_json TEXT,
  result_json TEXT,
  error TEXT,
  created_by BIGINT UNSIGNED NOT NULL,
  created_by_name VARCHAR(64) NOT NULL,
  started_at_ms BIGINT NULL,
  finished_at_ms BIGINT NULL,
  created_at_ms BIGINT NOT NULL,
  updated_at_ms BIGINT NOT NULL,
  INDEX idx_admin_jobs_type (type),
  INDEX idx_admin_jobs_status (status),
  INDEX idx_admin_jobs_created_by (created_by),
  INDEX idx_admin_jobs_created_by_name (created_by_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
