-- 0006_dvol_history_multi_asset.sql — promote dvol_history to multi-asset
--
-- Original schema (0001_init.sql) treated dvol_history as ETH-only:
-- PRIMARY KEY (timestamp) and a column named eth_spot. With the
-- orchestrator now snapshotting BTC in addition to ETH (commit
-- e978a44), the table needs an asset dimension so we can store a
-- DVOL/spot sample per asset per tick.
--
-- Forward-only. The 1028 existing rows are all ETH (the only writer
-- was the ETH branch of market_snapshot_cycle) so we backfill
-- asset='ETH' before swapping the table in place.

CREATE TABLE dvol_history_v2 (
    timestamp TEXT    NOT NULL,
    asset     TEXT    NOT NULL,
    dvol      NUMERIC NOT NULL,
    spot      NUMERIC NOT NULL,
    PRIMARY KEY (timestamp, asset)
);

INSERT INTO dvol_history_v2(timestamp, asset, dvol, spot)
SELECT timestamp, 'ETH', dvol, eth_spot FROM dvol_history;

DROP TABLE dvol_history;
ALTER TABLE dvol_history_v2 RENAME TO dvol_history;

CREATE INDEX idx_dvol_history_asset_ts
    ON dvol_history(asset, timestamp DESC);

PRAGMA user_version = 6;
