/*
服务IP与端口
邮件发送方式(SMTP|sendmail)
SMTP ACCOUNT
SMTP PWD
SMTP USER
SMTP SERVER
SMTP TIMEOUT
*/

CREATE TABLE IF NOT EXISTS syscfg (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  cfg_key TEXT UNIQUE,
  cfg_value TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS accounts (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  account TEXT UNIQUE,
  name TEXT NOT NULL,
  password TEXT NOT NULL,
  last_login INTEGER NOT NULL DEFAULT 0,
  is_super INTEGER NOT NULL DEFAULT 0,
  disabled INTEGER NOT NULL DEFAULT 0
);

CREATE TABLE IF NOT EXISTS rediscfg (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  address TEXT UNIQUE,
  remark TEXT NOT NULL DEFAULT '',
  password TEXT NOT NULL DEFAULT '',
  max_connect_wait INTEGER NOT NULL DEFAULT 5,
  max_status_failed INTEGER NOT NULL DEFAULT 1,
  min_memory_free INTEGER NOT NULL DEFAULT 0,
  min_memory_free_pc INTEGER NOT NULL DEFAULT 0,
  max_memory_usage INTEGER NOT NULL DEFAULT 16000000000,
  max_connection INTEGER NOT NULL DEFAULT 1000,
  max_evi_increased INTEGER NOT NULL DEFAULT 1,
  max_qps INTEGER NOT NULL DEFAULT 50000,
  mail_list TEXT NOT NULL DEFAULT '',
  disabled INTEGER NOT NULL DEFAULT 0
);

CREATE TABLE IF NOT EXISTS syslog (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  account_id INTEGER NOT NULL,
  log_time INTEGER NOT NULL,
  log_msg TEXT COMMENT NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_account ON syslog(account_id);

CREATE TABLE IF NOT EXISTS statuslog (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  redis_id INTEGER NOT NULL,
  check_time INTEGER NOT NULL,
  status INTEGER NOT NULL DEFAULT 0,
  info TEXT NOT NULL DEFAULT '',
  memory_usage INTEGER NOT NULL DEFAULT 0,
  memory_usage_pc INTEGER NOT NULL DEFAULT 0,
  connection INTEGER NOT NULL DEFAULT 0,
  qps INTEGER NOT NULL DEFAULT 0,
  evi_increased INTEGER NOT NULL DEFAULT 0,
  UNIQUE (redis_id, check_time)
);

CREATE TABLE IF NOT EXISTS warnlog (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  redis_id INTEGER NOT NULL,
  warn_time INTEGER NOT NULL,
  warn_msg TEXT NOT NULL,
  warn_status INTEGER NOT NULL DEFAULT 0,
  UNIQUE (redis_id, warn_time)
);

CREATE TABLE IF NOT EXISTS processlog (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  redis_id INTEGER NOT NULL,
  process_time INTEGER NOT NULL,
  process_info TEXT NOT NULL DEFAULT '',
  process_status INTEGER NOT NULL DEFAULT 0,
  UNIQUE (redis_id, process_time)
);