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,
  imsi TEXT,
  ground INT
);

CREATE TABLE IF NOT EXISTS restrictions (
  restriction_id INTEGER PRIMARY KEY AUTOINCREMENT,
  binpath TEXT,
  iftype INT,
  ifname TEXT,
  rst_state INT,
  roaming INT,
  imsi TEXT NOT NULL,
  rcv_limit BIGINT,
  send_limit BIGINT,
  rcv_warn_limit BIGINT,
  send_warn_limit BIGINT
);

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

CREATE TABLE IF NOT EXISTS counters (
  restriction_id INTEGER NOT NULL,
  sent_bytes BIGINT,
  rcv_bytes BIGINT,
  PRIMARY KEY (restriction_id)
);

