CREATE TABLE IF NOT EXISTS coinglass_liq_heatmap (
  source TEXT NOT NULL,
  symbol TEXT NOT NULL,
  interval TEXT NOT NULL,

  timestamp BIGINT NOT NULL,

  price_min NUMERIC(36, 18),
  price_max NUMERIC(36, 18),
  raw_grid JSONB NOT NULL,

  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),

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

CREATE INDEX IF NOT EXISTS idx_coinglass_liq_heatmap_symbol_interval_time
ON coinglass_liq_heatmap(symbol, interval, timestamp DESC);

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