cyberhybridhub/server/migrations/010_session_half_bars.sql
2026-05-31 12:40:54 -05:00

25 lines
943 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 010_session_half_bars.sql
--
-- RTH session half bars (morning 9:3012:45 ET, afternoon 12:4516:00 ET).
-- Drops legacy 4Hour history and adds sessionHalf timeframe + index.
DELETE FROM market_data_snapshots
WHERE metric = 'bar' AND timeframe = '4Hour';
DELETE FROM market_data_archive
WHERE metric = 'bar' AND timeframe = '4Hour';
-- Idempotent: constraint may already include sessionHalf (008) or be missing after a failed run.
ALTER TABLE market_data_snapshots
DROP CONSTRAINT IF EXISTS market_data_snapshots_timeframe_check;
ALTER TABLE market_data_snapshots
ADD CONSTRAINT market_data_snapshots_timeframe_check
CHECK (timeframe IN ('tick', '1Min', '1Hour', '4Hour', '1Day', 'sessionHalf'));
DROP INDEX IF EXISTS market_data_snapshots_bar_4h_idx;
CREATE INDEX IF NOT EXISTS market_data_snapshots_bar_session_half_idx
ON market_data_snapshots (symbol, as_of DESC)
WHERE metric = 'bar' AND timeframe = 'sessionHalf';