|
| 1 | +-- Data sanity constraints (additive, low-risk) |
| 2 | + |
| 3 | +-- gos.opportunities: confidence in [0,1], expected value non-negative when present |
| 4 | +alter table gos.opportunities |
| 5 | + add constraint gos_opportunities_confidence_range_chk |
| 6 | + check (confidence >= 0 and confidence <= 1) not valid; |
| 7 | + |
| 8 | +alter table gos.opportunities |
| 9 | + add constraint gos_opportunities_expected_value_nonnegative_chk |
| 10 | + check (expected_value_usd is null or expected_value_usd >= 0) not valid; |
| 11 | + |
| 12 | +-- market.bars: non-negative volume, positive prices |
| 13 | +alter table market.bars |
| 14 | + add constraint market_bars_volume_nonnegative_chk |
| 15 | + check (volume >= 0) not valid; |
| 16 | + |
| 17 | +alter table market.bars |
| 18 | + add constraint market_bars_prices_positive_chk |
| 19 | + check (open > 0 and high > 0 and low > 0 and close > 0) not valid; |
| 20 | + |
| 21 | +-- options.greeks_snapshot: sensible ranges where populated |
| 22 | +alter table options.greeks_snapshot |
| 23 | + add constraint options_greeks_iv_nonnegative_chk |
| 24 | + check (iv is null or iv >= 0) not valid; |
| 25 | + |
| 26 | +alter table options.greeks_snapshot |
| 27 | + add constraint options_greeks_delta_range_chk |
| 28 | + check (delta is null or (delta >= -1 and delta <= 1)) not valid; |
| 29 | + |
| 30 | +-- brokerage.positions/orders: quantities non-negative |
| 31 | +alter table brokerage.positions |
| 32 | + add constraint brokerage_positions_qty_nonnegative_chk |
| 33 | + check (qty >= 0) not valid; |
| 34 | + |
| 35 | +alter table brokerage.orders |
| 36 | + add constraint brokerage_orders_qty_nonnegative_chk |
| 37 | + check ((qty is null or qty >= 0) and (filled_qty is null or filled_qty >= 0)) not valid; |
| 38 | + |
| 39 | +-- Validate constraints against current data (safe after add) |
| 40 | +alter table gos.opportunities validate constraint gos_opportunities_confidence_range_chk; |
| 41 | +alter table gos.opportunities validate constraint gos_opportunities_expected_value_nonnegative_chk; |
| 42 | +alter table market.bars validate constraint market_bars_volume_nonnegative_chk; |
| 43 | +alter table market.bars validate constraint market_bars_prices_positive_chk; |
| 44 | +alter table options.greeks_snapshot validate constraint options_greeks_iv_nonnegative_chk; |
| 45 | +alter table options.greeks_snapshot validate constraint options_greeks_delta_range_chk; |
| 46 | +alter table brokerage.positions validate constraint brokerage_positions_qty_nonnegative_chk; |
| 47 | +alter table brokerage.orders validate constraint brokerage_orders_qty_nonnegative_chk; |
0 commit comments