CREATE TABLE IF NOT EXISTS bot_users (
  user_id VARCHAR(32) NOT NULL PRIMARY KEY,
  username VARCHAR(191) NULL,
  first_name VARCHAR(191) NULL,
  step VARCHAR(191) NULL,
  points INT NOT NULL DEFAULT 0,
  referrer_id VARCHAR(32) NULL,
  data_json LONGTEXT NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_points (points),
  KEY idx_step (step),
  KEY idx_referrer (referrer_id),
  KEY idx_users_updated (updated_at),
  KEY idx_users_created (created_at),
  KEY idx_users_step_updated (step, updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_orders (
  order_id VARCHAR(64) NOT NULL PRIMARY KEY,
  owner_id VARCHAR(32) NULL,
  channel_username VARCHAR(191) NULL,
  channel_chat_id VARCHAR(64) NULL,
  target_count INT NOT NULL DEFAULT 0,
  reward_per_member INT NOT NULL DEFAULT 0,
  received_count INT NOT NULL DEFAULT 0,
  left_count INT NOT NULL DEFAULT 0,
  status VARCHAR(100) NULL,
  post_chat_id VARCHAR(64) NULL,
  post_message_id VARCHAR(64) NULL,
  created_ts BIGINT NULL,
  data_json LONGTEXT NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_owner (owner_id),
  KEY idx_owner_created (owner_id, created_ts),
  KEY idx_channel (channel_username),
  KEY idx_status (status),
  KEY idx_created_ts (created_ts),
  KEY idx_orders_status_created (status, created_ts),
  KEY idx_orders_post (post_chat_id, post_message_id),
  KEY idx_orders_channel_chat (channel_chat_id),
  KEY idx_orders_updated (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_order_members (
  order_id VARCHAR(64) NOT NULL,
  user_id VARCHAR(32) NOT NULL,
  joined_ts BIGINT NULL,
  left_ts BIGINT NULL,
  penalized TINYINT(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (order_id, user_id),
  KEY idx_member_user (user_id),
  KEY idx_left (left_ts),
  KEY idx_order_members_user_left (user_id, left_ts),
  KEY idx_order_members_order_penalized (order_id, penalized),
  KEY idx_order_members_joined (joined_ts),
  CONSTRAINT fk_order_members_order FOREIGN KEY (order_id) REFERENCES bot_orders(order_id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_settings (
  setting_key VARCHAR(191) NOT NULL PRIMARY KEY,
  storage_type ENUM('json','text','raw') NOT NULL DEFAULT 'raw',
  storage_value LONGTEXT NULL,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_settings_updated (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_channel_rewards (
  user_id VARCHAR(32) NOT NULL,
  channel_key VARCHAR(191) NOT NULL,
  last_order_id VARCHAR(64) NULL,
  channel_chat_id VARCHAR(64) NULL,
  last_reward_ts BIGINT NULL,
  data_json LONGTEXT NULL,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (user_id, channel_key),
  KEY idx_channel_reward (channel_key),
  KEY idx_reward_ts (last_reward_ts)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_spam (
  user_id VARCHAR(32) NOT NULL PRIMARY KEY,
  data_json LONGTEXT NOT NULL,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_order_reports (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  order_id VARCHAR(64) NOT NULL,
  reporter_id VARCHAR(32) NOT NULL,
  report_source VARCHAR(30) NOT NULL DEFAULT 'user',
  status VARCHAR(30) NOT NULL DEFAULT 'open',
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_order_reporter (order_id, reporter_id),
  KEY idx_order_status (order_id, status),
  KEY idx_reporter (reporter_id),
  KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_order_moderation_actions (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  order_id VARCHAR(64) NOT NULL,
  actor_id VARCHAR(32) NULL,
  action_type VARCHAR(40) NOT NULL,
  reason VARCHAR(191) NULL,
  report_count INT NOT NULL DEFAULT 0,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_order_action (order_id, action_type),
  KEY idx_actor (actor_id),
  KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_anti_spam (
  user_id VARCHAR(32) NOT NULL PRIMARY KEY,
  window_start BIGINT NOT NULL DEFAULT 0,
  message_count INT NOT NULL DEFAULT 0,
  blocked_until BIGINT NOT NULL DEFAULT 0,
  last_notice_at BIGINT NOT NULL DEFAULT 0,
  data_json LONGTEXT NULL,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_blocked_until (blocked_until),
  KEY idx_updated (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_order_cancel_actions (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  order_id VARCHAR(64) NOT NULL,
  owner_id VARCHAR(32) NULL,
  actor_id VARCHAR(32) NULL,
  cancel_type VARCHAR(30) NOT NULL DEFAULT 'user',
  refund_amount INT NOT NULL DEFAULT 0,
  remaining_count INT NOT NULL DEFAULT 0,
  reason VARCHAR(191) NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_order_cancel (order_id),
  KEY idx_owner_cancel (owner_id),
  KEY idx_actor_cancel (actor_id),
  KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_referrals (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  referrer_id VARCHAR(32) NOT NULL,
  referred_id VARCHAR(32) NOT NULL,
  status VARCHAR(32) NOT NULL DEFAULT 'started',
  signup_reward_mode VARCHAR(20) NOT NULL DEFAULT 'diamond',
  signup_reward_amount INT NOT NULL DEFAULT 0,
  signup_reward_applied TINYINT(1) NOT NULL DEFAULT 0,
  active_required_count INT NOT NULL DEFAULT 0,
  active_reward_mode VARCHAR(20) NOT NULL DEFAULT 'diamond',
  active_reward_amount INT NOT NULL DEFAULT 0,
  active_reward_applied TINYINT(1) NOT NULL DEFAULT 0,
  referred_join_count INT NOT NULL DEFAULT 0,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_referred (referred_id),
  KEY idx_referrer (referrer_id),
  KEY idx_status (status),
  KEY idx_referrer_created (referrer_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_referral_events (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  referrer_id VARCHAR(32) NOT NULL,
  referred_id VARCHAR(32) NOT NULL,
  event_type VARCHAR(40) NOT NULL,
  reward_mode VARCHAR(20) NULL,
  amount INT NOT NULL DEFAULT 0,
  before_balance INT NULL,
  after_balance INT NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_referrer (referrer_id),
  KEY idx_referred (referred_id),
  KEY idx_event_type (event_type),
  KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_daily_rewards (
  user_id VARCHAR(32) NOT NULL PRIMARY KEY,
  last_claim_ts BIGINT NOT NULL DEFAULT 0,
  next_claim_ts BIGINT NOT NULL DEFAULT 0,
  claim_count INT NOT NULL DEFAULT 0,
  total_amount INT NOT NULL DEFAULT 0,
  data_json LONGTEXT NULL,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_next_claim (next_claim_ts),
  KEY idx_updated (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_daily_reward_events (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  user_id VARCHAR(32) NOT NULL,
  amount INT NOT NULL DEFAULT 0,
  before_balance INT NULL,
  after_balance INT NULL,
  status VARCHAR(30) NOT NULL DEFAULT 'claimed',
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_user_created (user_id, created_at),
  KEY idx_status (status),
  KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_daily_notify_jobs (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  job_key VARCHAR(80) NOT NULL,
  source VARCHAR(20) NOT NULL DEFAULT 'auto',
  status VARCHAR(20) NOT NULL DEFAULT 'queued',
  message_text LONGTEXT NULL,
  total INT NOT NULL DEFAULT 0,
  processed INT NOT NULL DEFAULT 0,
  success INT NOT NULL DEFAULT 0,
  failed INT NOT NULL DEFAULT 0,
  last_user_id VARCHAR(32) NOT NULL DEFAULT '0',
  last_error VARCHAR(255) NULL,
  created_ts BIGINT NOT NULL DEFAULT 0,
  started_ts BIGINT NOT NULL DEFAULT 0,
  finished_ts BIGINT NOT NULL DEFAULT 0,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_daily_job_key (job_key),
  KEY idx_daily_status (status, id),
  KEY idx_daily_source_created (source, created_ts),
  KEY idx_daily_updated (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_gift_codes (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  code VARCHAR(128) NOT NULL,
  amount INT NOT NULL DEFAULT 0,
  status VARCHAR(24) NOT NULL DEFAULT 'active',
  created_by VARCHAR(32) NULL,
  used_by VARCHAR(32) NULL,
  used_at TIMESTAMP NULL DEFAULT NULL,
  channel_ref VARCHAR(191) NULL,
  channel_message_id VARCHAR(64) NULL,
  published_at TIMESTAMP NULL DEFAULT NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_gift_code (code),
  KEY idx_gift_status (status),
  KEY idx_gift_used_by (used_by),
  KEY idx_gift_created (created_at),
  KEY idx_gift_status_created (status, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_gift_code_events (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  gift_id BIGINT UNSIGNED NULL,
  code VARCHAR(128) NOT NULL,
  actor_id VARCHAR(32) NULL,
  event_type VARCHAR(40) NOT NULL,
  amount INT NOT NULL DEFAULT 0,
  before_balance INT NULL,
  after_balance INT NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_gift_event_code (code),
  KEY idx_gift_event_actor (actor_id),
  KEY idx_gift_event_type (event_type),
  KEY idx_gift_event_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS bot_admin_logs (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  actor_id VARCHAR(32) NULL,
  action_type VARCHAR(80) NOT NULL,
  target_type VARCHAR(80) NULL,
  target_id VARCHAR(191) NULL,
  description TEXT NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_actor_created (actor_id, created_at),
  KEY idx_action_created (action_type, created_at),
  KEY idx_target (target_type, target_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_wallet_ledger (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  user_id VARCHAR(32) NOT NULL,
  asset_type VARCHAR(30) NOT NULL DEFAULT 'diamond',
  delta_amount INT NOT NULL DEFAULT 0,
  balance_before INT NULL,
  balance_after INT NULL,
  reason VARCHAR(100) NULL,
  ref_type VARCHAR(80) NULL,
  ref_id VARCHAR(191) NULL,
  actor_id VARCHAR(32) NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_user_created (user_id, created_at),
  KEY idx_reason_created (reason, created_at),
  KEY idx_actor_created (actor_id, created_at),
  KEY idx_ref (ref_type, ref_id),
  KEY idx_wallet_asset_created (asset_type, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_cron_runs (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  task_name VARCHAR(80) NOT NULL,
  status VARCHAR(30) NOT NULL DEFAULT 'ok',
  result_json LONGTEXT NULL,
  started_ts BIGINT NOT NULL DEFAULT 0,
  finished_ts BIGINT NOT NULL DEFAULT 0,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_task_created (task_name, created_at),
  KEY idx_status_created (status, created_at),
  KEY idx_cron_task_status (task_name, status, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_support_tickets (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  ticket_code VARCHAR(32) NOT NULL,
  user_id VARCHAR(32) NOT NULL,
  status VARCHAR(32) NOT NULL DEFAULT 'open',
  priority VARCHAR(20) NOT NULL DEFAULT 'normal',
  subject VARCHAR(191) NULL,
  last_message TEXT NULL,
  last_admin_id VARCHAR(32) NULL,
  last_user_seen_at TIMESTAMP NULL DEFAULT NULL,
  last_admin_seen_at TIMESTAMP NULL DEFAULT NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_ticket_code (ticket_code),
  KEY idx_ticket_user (user_id, created_at),
  KEY idx_ticket_status (status, updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_support_messages (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  ticket_id BIGINT UNSIGNED NOT NULL,
  sender_id VARCHAR(32) NOT NULL,
  sender_role VARCHAR(20) NOT NULL DEFAULT 'user',
  message_text LONGTEXT NOT NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_ticket_created (ticket_id, created_at),
  KEY idx_sender_created (sender_id, created_at),
  CONSTRAINT fk_support_messages_ticket FOREIGN KEY (ticket_id) REFERENCES bot_support_tickets(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_user_levels (
  user_id VARCHAR(32) NOT NULL PRIMARY KEY,
  level_key VARCHAR(30) NOT NULL DEFAULT 'normal',
  daily_order_limit INT NOT NULL DEFAULT 0,
  note VARCHAR(191) NULL,
  data_json LONGTEXT NULL,
  updated_by VARCHAR(32) NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_level (level_key),
  KEY idx_updated (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_notices (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(191) NOT NULL,
  body LONGTEXT NOT NULL,
  status VARCHAR(24) NOT NULL DEFAULT 'active',
  show_once TINYINT(1) NOT NULL DEFAULT 1,
  target_level VARCHAR(30) NULL,
  start_ts BIGINT NOT NULL DEFAULT 0,
  end_ts BIGINT NOT NULL DEFAULT 0,
  created_by VARCHAR(32) NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_notice_status (status, start_ts, end_ts),
  KEY idx_notice_level (target_level)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_notice_views (
  notice_id BIGINT UNSIGNED NOT NULL,
  user_id VARCHAR(32) NOT NULL,
  viewed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (notice_id, user_id),
  KEY idx_user_notice (user_id, viewed_at),
  CONSTRAINT fk_notice_views_notice FOREIGN KEY (notice_id) REFERENCES bot_notices(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_order_status_log (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  order_id VARCHAR(64) NOT NULL,
  old_status VARCHAR(100) NULL,
  new_status VARCHAR(100) NOT NULL,
  actor_id VARCHAR(32) NULL,
  note VARCHAR(191) NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_order_status_log (order_id, created_at),
  KEY idx_actor_status_log (actor_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS bot_install_checks (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  check_key VARCHAR(80) NOT NULL,
  status VARCHAR(20) NOT NULL,
  message VARCHAR(255) NULL,
  data_json LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_check_created (check_key, created_at),
  KEY idx_check_status (status, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
