CREATE TABLE IF NOT EXISTS funding_rates (
  source TEXT NOT NULL,
  symbol TEXT NOT NULL,

  funding_time BIGINT NOT NULL,
  funding_rate NUMERIC(36, 18) NOT NULL,
  mark_price NUMERIC(36, 18),

  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),

  PRIMARY KEY (source, symbol, funding_time)
);

CREATE INDEX IF NOT EXISTS idx_funding_rates_symbol_time
ON funding_rates(symbol, funding_time DESC);

SELECT create_hypertable('funding_rates', 'funding_time',
  chunk_time_interval => 2592000000,
  if_not_exists => TRUE,
  migrate_data => TRUE);
