@davoodmehraban89 / VELYQOR / commits / 0778d51
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(db): add market schema invariant checks

davoodmehraban89 committed Oct 5, 2026 at 09:51 UTC 0778d513477c5b2e79565f8648f19929adb06120
1 file changed +27
db/tests/market_core_invariants.sql new
+27
@@ -0,0 +1,27 @@
1 +BEGIN;
2 +
3 +DO $$
4 +DECLARE instrument_count INTEGER;
5 +BEGIN
6 + SELECT count(*) INTO instrument_count FROM instruments
7 + WHERE symbol IN ('USD_IRT_FREE','GOLD18_IRT','XAU_USD','GOLD18_THEORETICAL_IRT','GOLD18_PREMIUM_IRT','GOLD18_PREMIUM_PCT');
8 + IF instrument_count <> 6 THEN
9 + RAISE EXCEPTION 'Expected 6 canonical MVP instruments, got %', instrument_count;
10 + END IF;
11 +END $$;
12 +
13 +-- Invalid candles must be rejected by constraints.
14 +DO $$
15 +DECLARE usd_id BIGINT;
16 +BEGIN
17 + SELECT id INTO usd_id FROM instruments WHERE symbol='USD_IRT_FREE';
18 + BEGIN
19 + INSERT INTO candles(instrument_id,timeframe,open_time,close_time,open,high,low,close,observation_count,quality,quality_score)
20 + VALUES(usd_id,'1m','2026-01-01T00:00:00Z','2026-01-01T00:01:00Z',100,90,80,85,2,'GOOD',100);
21 + RAISE EXCEPTION 'Invalid candle unexpectedly accepted';
22 + EXCEPTION WHEN check_violation THEN
23 + NULL;
24 + END;
25 +END $$;
26 +
27 +ROLLBACK;