PRAGMA journal_mode = PERSIST;
PRAGMA user_version = 1;

CREATE TABLE IF NOT EXISTS statistics (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  binpath TEXT NOT NULL,
  received BIGINT,
  sent BIGINT,
  time_stamp BIGINT,
  iftype INT,
  is_roaming INT,
  hw_net_protocol_type INT,
  ifname TEXT,
  subscriber_id TEXT,
  ground INT
);

CREATE TABLE IF NOT EXISTS restrictions (
  restriction_id INTEGER PRIMARY KEY AUTOINCREMENT,
  binpath TEXT,
  iftype INT,
  ifname TEXT,
  rstn_type INT,
  roaming INT,
  subscriber_id TEXT NOT NULL,
  data_limit BIGINT,
  data_warn_limit BIGINT,
  monthly_limit BIGINT,
  weekly_limit BIGINT,
  daily_limit BIGINT,
  month_start_date INT
);

CREATE INDEX IF NOT EXISTS restrictions_index ON restrictions (binpath, iftype, ifname);

CREATE TABLE IF NOT EXISTS counters (
  restriction_id INTEGER NOT NULL,
  data_counter BIGINT,
  warn_counter BIGINT,
  monthly_counter BIGINT,
  weekly_counter BIGINT,
  daily_counter BIGINT,
  month_start_date INT,
  month_start_ts BIGINT,
  week_start_ts BIGINT,
  day_start_ts BIGINT,
  PRIMARY KEY (restriction_id)
);
