CREATE TABLE IF NOT EXISTS Event_List (
  id INTEGER PRIMARY KEY,
  device_name TEXT,
  type TEXT,
  cond TEXT,
  value REAL,
  datetime TIMESTAMP,
  tag TEXT,
  stroke_number INTEGER
);

CREATE TABLE IF NOT EXISTS Hist_Day (
  id INTEGER PRIMARY KEY,
  gauge_date TIMESTAMP,
  percent_run REAL,
  kWh REAL,
  kWh_regen REAL,
  electricity_cost REAL,
  peak_load REAL,
  min_load REAL,
  average_SPM REAL,
  production_calculated REAL,
  full_card_production REAL,
  polished_rod_HP REAL,
  lifting_cost REAL,
  fluid_above_pump REAL,
  pump_intake_pressure REAL,
  inflow_rate REAL
);

CREATE TABLE IF NOT EXISTS Well_Test (
  id INTEGER PRIMARY KEY,
  test_date TIMESTAMP,
  test_volume_oil REAL,
  test_volume_water REAL,
  test_volume_gas REAL,
  k_factor REAL,
  projected_volume_oil REAL,
  projected_volume_water REAL,
  api_gravity_oil REAL,
  sg_oil REAL,
  sg_water REAL,
  test_hours REAL,
  deleted INTEGER DEFAULT 0
);

CREATE TABLE IF NOT EXISTS config (
  id INTEGER PRIMARY KEY,
  device_type TEXT,
  ip_address TEXT,
  dateChanged TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS Notes (
  id INTEGER PRIMARY KEY,
  author TEXT,
  note TEXT,
  datetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  type INTEGER,
  associated_stroke INTEGER,
  deleted INTEGER DEFAULT 0
);

CREATE TABLE IF NOT EXISTS note_types(
  id INTEGER PRIMARY KEY,
  type TEXT,
  deleted INTEGER DEFAULT 0
);


INSERT INTO note_types (id, type) VALUES ('1', 'Downtime Explanation');
INSERT INTO note_types (id, type) VALUES ('2', 'Configuration Change');
INSERT INTO note_types (id, type) VALUES ('3', 'Info');
INSERT INTO note_types (id, type) VALUES ('4', 'Other');


CREATE TABLE IF NOT EXISTS fluid_shot(
  id INTEGER PRIMARY KEY,
  shot_datetime TIMESTAMP,
  taken_by TEXT,
  pump_intake_pressure REAL,
  fluid_gradient REAL,
  friction REAL,
  deleted INTEGER DEFAULT 0
);

CREATE TABLE IF NOT EXISTS card_history(
  id INTEGER PRIMARY KEY,
  Stroke_Time TIMESTAMP,
  Card_ID INTEGER,
  Card_Type TEXT,
  Surface_Position BLOB,
  Surface_Load BLOB,
  Downhole_Position BLOB,
  Downhole_Load BLOB
);

CREATE TABLE IF NOT EXISTS card_history_dates(
  id INTEGER PRIMARY KEY,
  year INTEGER,
  month INTEGER,
  day INTEGER,
  first_id INTEGER
);

CREATE TABLE IF NOT EXISTS tag_vals(
  id INTEGER PRIMARY KEY,
  dtime TIMESTAMP,
  name TEXT,
  val TEXT
);

CREATE TABLE IF NOT EXISTS well_config(
  id INTEGER PRIMARY KEY,
  tstamp TIMESTAMP,
  type TEXT,
  val TEXT
);
