-- Persist exchange account snapshots so the live-trading console reads DB state
-- instead of blocking page load on exchange API calls.

CREATE TABLE IF NOT EXISTS live_account_snapshots (
    account_id INTEGER PRIMARY KEY REFERENCES live_trade_accounts(id) ON DELETE CASCADE,
    status TEXT NOT NULL DEFAULT 'ok',
    error_message TEXT NOT NULL DEFAULT '',
    snapshot_json TEXT NOT NULL DEFAULT '{}',
    synced_at TEXT NOT NULL DEFAULT '',
    created_at TEXT NOT NULL DEFAULT '',
    updated_at TEXT NOT NULL DEFAULT ''
);

CREATE INDEX IF NOT EXISTS idx_live_account_snapshots_synced_at
    ON live_account_snapshots(synced_at DESC);
