create table if not exists decision_packets ( id bigserial primary key, instrument_id bigint not null references instruments(id), trading_plan_id bigint references trading_plans(id), candidate_id bigint references trade_plan_candidates(id), signal_id bigint references trade_signals(id), execution_ticket_id bigint references execution_tickets(id), packet_ts timestamptz not null, status text not null, action_recommendation text not null, quality_score numeric, ai_explanation text, payload jsonb not null default '{}'::jsonb, created_at timestamptz not null default now() ); create index if not exists idx_decision_packets_instrument_ts_desc on decision_packets (instrument_id, packet_ts desc, id desc); create table if not exists decision_alerts ( id bigserial primary key, instrument_id bigint not null references instruments(id), decision_packet_id bigint references decision_packets(id), alert_key text not null unique, alert_type text not null, status text not null, channel text not null default 'workbench', message text not null, payload jsonb not null default '{}'::jsonb, created_ts timestamptz not null, delivered_ts timestamptz ); create index if not exists idx_decision_alerts_instrument_ts_desc on decision_alerts (instrument_id, created_ts desc, id desc);