Files
stonks-oracle/infra/migrations/012_audit_trail_indexes.sql
T

18 lines
727 B
SQL

-- Stonks Oracle - Execution audit trail indexes
-- Supports efficient querying of the full decision chain from
-- recommendation through risk evaluation to broker execution.
-- Requirements: 8.3, 11.3
-- GIN index on audit_events.data for JSONB key lookups
-- (e.g. data->>'recommendation_id', data->>'order_id')
CREATE INDEX IF NOT EXISTS idx_audit_events_data_gin
ON audit_events USING gin (data);
-- Index for chronological audit trail queries by entity
CREATE INDEX IF NOT EXISTS idx_audit_events_entity_created
ON audit_events (entity_id, created_at ASC);
-- Index for filtering by event_type + entity_type
CREATE INDEX IF NOT EXISTS idx_audit_events_type_entity
ON audit_events (event_type, entity_type);