CREATE TABLE IF NOT EXISTS open_interest (
  source TEXT NOT NULL,
  symbol TEXT NOT NULL,
  period TEXT NOT NULL,

  timestamp BIGINT NOT NULL,
  open_interest NUMERIC(36, 18) NOT NULL,
  open_interest_value NUMERIC(36, 18),

  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),

  PRIMARY KEY (source, symbol, period, timestamp)
);

CREATE INDEX IF NOT EXISTS idx_open_interest_symbol_period_time
ON open_interest(symbol, period, timestamp DESC);

SELECT create_hypertable('open_interest', 'timestamp',
  chunk_time_interval => 604800000,
  if_not_exists => TRUE,
  migrate_data => TRUE);
