CREATE TABLE IF NOT EXISTS market_snapshots (
    id BIGSERIAL PRIMARY KEY,
    snapshot_type TEXT NOT NULL DEFAULT 'crypto_market',
    source TEXT NOT NULL DEFAULT 'binance_spot_usdt_market',
    snapshot_time TEXT NOT NULL,
    data_json TEXT NOT NULL DEFAULT '{}',
    status TEXT NOT NULL DEFAULT 'success',
    error_message TEXT DEFAULT '',
    created_at TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_market_snapshots_type_time
    ON market_snapshots(snapshot_type, snapshot_time DESC, id DESC);

