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

  timestamp BIGINT NOT NULL,

  long_short_ratio NUMERIC(36, 18) NOT NULL,
  long_value NUMERIC(36, 18),
  short_value NUMERIC(36, 18),

  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),

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

CREATE INDEX IF NOT EXISTS idx_long_short_ratio_symbol_period_time
ON long_short_ratio(symbol, period, ratio_type, timestamp DESC);

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