phase 14-15: docker build validation and helm deployment
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
-- Stonks Oracle - Dedupe support indexes
|
||||
|
||||
-- Index on canonical_url for cross-source deduplication lookups.
|
||||
-- The dedupe module queries documents by canonical_url to detect
|
||||
-- the same article ingested from different source types.
|
||||
CREATE INDEX idx_documents_canonical_url ON documents(canonical_url)
|
||||
WHERE canonical_url IS NOT NULL;
|
||||
|
||||
-- Unique constraint on document_company_mentions to prevent duplicate
|
||||
-- company links when cross-source dedupe links an existing document
|
||||
-- to an additional company.
|
||||
CREATE UNIQUE INDEX idx_doc_mentions_unique
|
||||
ON document_company_mentions(document_id, company_id);
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Stonks Oracle - Add parser_output_ref to documents table
|
||||
-- Stores the MinIO reference to the structured parser output JSON
|
||||
-- (metadata, quality signals, warnings, outbound links, tags, etc.)
|
||||
|
||||
ALTER TABLE documents ADD COLUMN IF NOT EXISTS parser_output_ref VARCHAR(1000);
|
||||
@@ -0,0 +1,40 @@
|
||||
-- Stonks Oracle - Model Performance Metrics
|
||||
-- Tracks extraction success/failure rates, latency, retries, confidence,
|
||||
-- token usage estimates, and validation error distributions.
|
||||
-- Requirements: 5.2, 5.4, 12.1, 12.2
|
||||
|
||||
CREATE TABLE model_performance_metrics (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
document_id UUID REFERENCES documents(id) ON DELETE SET NULL,
|
||||
ticker VARCHAR(20),
|
||||
model_name VARCHAR(200) NOT NULL,
|
||||
prompt_version VARCHAR(100),
|
||||
schema_version VARCHAR(50),
|
||||
success BOOLEAN NOT NULL,
|
||||
attempt_count INTEGER NOT NULL DEFAULT 1,
|
||||
total_duration_ms INTEGER NOT NULL DEFAULT 0,
|
||||
first_attempt_duration_ms INTEGER DEFAULT 0,
|
||||
final_attempt_duration_ms INTEGER DEFAULT 0,
|
||||
confidence FLOAT DEFAULT 0.0,
|
||||
validation_status VARCHAR(50) NOT NULL DEFAULT 'unknown',
|
||||
validation_error_count INTEGER DEFAULT 0,
|
||||
validation_warning_count INTEGER DEFAULT 0,
|
||||
validation_errors JSONB DEFAULT '[]',
|
||||
retry_count INTEGER DEFAULT 0,
|
||||
input_token_estimate INTEGER DEFAULT 0,
|
||||
output_token_estimate INTEGER DEFAULT 0,
|
||||
company_count INTEGER DEFAULT 0,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Query by time range (dashboard primary access pattern)
|
||||
CREATE INDEX idx_model_perf_recorded ON model_performance_metrics(recorded_at DESC);
|
||||
|
||||
-- Filter by model for per-model dashboards
|
||||
CREATE INDEX idx_model_perf_model ON model_performance_metrics(model_name, recorded_at DESC);
|
||||
|
||||
-- Filter by success for failure analysis
|
||||
CREATE INDEX idx_model_perf_success ON model_performance_metrics(success, recorded_at DESC);
|
||||
|
||||
-- Filter by validation status for schema failure dashboards
|
||||
CREATE INDEX idx_model_perf_validation ON model_performance_metrics(validation_status);
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Stonks Oracle - Add disagreement details to trend windows
|
||||
-- Stores structured contradiction/disagreement representations
|
||||
-- so downstream consumers can inspect *why* signals conflict
|
||||
-- rather than relying on a single scalar contradiction_score.
|
||||
-- Requirements: 6.4
|
||||
|
||||
ALTER TABLE trend_windows
|
||||
ADD COLUMN IF NOT EXISTS disagreement_details JSONB DEFAULT '[]';
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Stonks Oracle - Trend evidence mappings
|
||||
-- Links trend_windows to the documents that contributed as evidence,
|
||||
-- storing the evidence type (supporting/opposing), rank score, and
|
||||
-- weight breakdown for explainability and drill-down queries.
|
||||
-- Requirements: 6.5, 10.4
|
||||
|
||||
CREATE TABLE trend_evidence (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
trend_window_id UUID NOT NULL REFERENCES trend_windows(id) ON DELETE CASCADE,
|
||||
document_id UUID NOT NULL,
|
||||
evidence_type VARCHAR(20) NOT NULL DEFAULT 'supporting', -- supporting | opposing
|
||||
rank_score FLOAT DEFAULT 0.0,
|
||||
weight_component FLOAT DEFAULT 0.0,
|
||||
impact_component FLOAT DEFAULT 0.0,
|
||||
recency_component FLOAT DEFAULT 0.0,
|
||||
confidence_component FLOAT DEFAULT 0.0,
|
||||
sentiment_value FLOAT DEFAULT 0.0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_trend_evidence_trend ON trend_evidence(trend_window_id);
|
||||
CREATE INDEX idx_trend_evidence_doc ON trend_evidence(document_id);
|
||||
CREATE INDEX idx_trend_evidence_type ON trend_evidence(trend_window_id, evidence_type);
|
||||
@@ -0,0 +1,15 @@
|
||||
-- Stonks Oracle - Recommendation persistence enhancements
|
||||
-- Adds full model metadata columns to recommendations table
|
||||
-- and a risk_classification column for the computed risk label.
|
||||
-- Requirements: 7.1, 7.2, 8.3
|
||||
|
||||
-- Store full model provenance on the recommendation itself
|
||||
ALTER TABLE recommendations
|
||||
ADD COLUMN IF NOT EXISTS model_provider VARCHAR(100) DEFAULT 'deterministic',
|
||||
ADD COLUMN IF NOT EXISTS prompt_version VARCHAR(100) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS schema_version VARCHAR(50) DEFAULT '1.0.0',
|
||||
ADD COLUMN IF NOT EXISTS risk_classification VARCHAR(20) DEFAULT 'moderate';
|
||||
|
||||
-- Index for querying recommendations by risk classification
|
||||
CREATE INDEX IF NOT EXISTS idx_recommendations_risk
|
||||
ON recommendations(risk_classification);
|
||||
@@ -0,0 +1,55 @@
|
||||
-- Stonks Oracle - Portfolio and account risk configuration
|
||||
-- Persists risk configuration profiles and tracks risk state snapshots.
|
||||
-- Requirements: 8.1, 8.2, 8.4
|
||||
|
||||
-- ============================================================
|
||||
-- Risk Configuration Profiles
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE risk_configs (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
name VARCHAR(200) NOT NULL DEFAULT 'default',
|
||||
trading_mode VARCHAR(20) NOT NULL DEFAULT 'paper',
|
||||
config JSONB NOT NULL DEFAULT '{}',
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_risk_configs_active_name
|
||||
ON risk_configs(name) WHERE active = TRUE;
|
||||
|
||||
-- ============================================================
|
||||
-- Symbol-level lockouts (news-shock, cooldown)
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE symbol_lockouts (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
ticker VARCHAR(20) NOT NULL,
|
||||
lockout_type VARCHAR(50) NOT NULL,
|
||||
reason TEXT DEFAULT '',
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_symbol_lockouts_ticker ON symbol_lockouts(ticker, expires_at);
|
||||
CREATE INDEX idx_symbol_lockouts_expiry ON symbol_lockouts(expires_at);
|
||||
|
||||
-- ============================================================
|
||||
-- Daily risk snapshots (for daily loss tracking)
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE daily_risk_snapshots (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
account_id VARCHAR(200) NOT NULL,
|
||||
snapshot_date DATE NOT NULL DEFAULT CURRENT_DATE,
|
||||
portfolio_value NUMERIC DEFAULT 0,
|
||||
daily_pnl NUMERIC DEFAULT 0,
|
||||
daily_trade_count INTEGER DEFAULT 0,
|
||||
positions_by_sector JSONB DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE(account_id, snapshot_date)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_daily_risk_account ON daily_risk_snapshots(account_id, snapshot_date DESC);
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Stonks Oracle - Add unique constraint for paper trading position upserts
|
||||
-- Requirements: 8.1, 8.3
|
||||
|
||||
-- The paper trading adapter needs to upsert positions by (broker_account_id, ticker).
|
||||
-- Add a unique constraint to support ON CONFLICT.
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_positions_account_ticker
|
||||
ON positions(broker_account_id, ticker);
|
||||
@@ -0,0 +1,17 @@
|
||||
-- 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);
|
||||
@@ -0,0 +1,29 @@
|
||||
-- Stonks Oracle - Operator approval workflow for live trading mode
|
||||
-- Tracks pending, approved, rejected, and expired approval requests
|
||||
-- for orders that require operator sign-off before broker submission.
|
||||
-- Requirements: 8.2
|
||||
|
||||
CREATE TABLE operator_approvals (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
order_job JSONB NOT NULL DEFAULT '{}',
|
||||
recommendation_id UUID REFERENCES recommendations(id),
|
||||
ticker VARCHAR(20) NOT NULL,
|
||||
side VARCHAR(10) NOT NULL DEFAULT 'buy',
|
||||
quantity NUMERIC NOT NULL DEFAULT 0,
|
||||
estimated_value NUMERIC NOT NULL DEFAULT 0,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'pending',
|
||||
risk_evaluation_id UUID,
|
||||
requested_by VARCHAR(200) NOT NULL DEFAULT 'system',
|
||||
reviewed_by VARCHAR(200),
|
||||
review_note TEXT,
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
requested_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
reviewed_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_operator_approvals_status ON operator_approvals(status);
|
||||
CREATE INDEX idx_operator_approvals_ticker ON operator_approvals(ticker);
|
||||
CREATE INDEX idx_operator_approvals_expires ON operator_approvals(expires_at)
|
||||
WHERE status = 'pending';
|
||||
@@ -0,0 +1,43 @@
|
||||
-- Stonks Oracle - Data retention and lifecycle policies
|
||||
-- Tracks per-bucket and per-artifact-class retention rules.
|
||||
-- Requirements: N3
|
||||
|
||||
CREATE TABLE retention_policies (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
bucket_name VARCHAR(200) NOT NULL,
|
||||
artifact_class VARCHAR(100) NOT NULL DEFAULT 'default',
|
||||
retention_days INTEGER NOT NULL DEFAULT 365,
|
||||
archive_before_delete BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE(bucket_name, artifact_class)
|
||||
);
|
||||
|
||||
-- Seed default retention policies per bucket
|
||||
INSERT INTO retention_policies (bucket_name, artifact_class, retention_days, archive_before_delete) VALUES
|
||||
('stonks-raw-market', 'default', 90, FALSE),
|
||||
('stonks-raw-news', 'default', 180, FALSE),
|
||||
('stonks-raw-filings', 'default', 365, FALSE),
|
||||
('stonks-normalized', 'default', 180, FALSE),
|
||||
('stonks-llm-prompts', 'default', 365, FALSE),
|
||||
('stonks-llm-results', 'default', 365, FALSE),
|
||||
('stonks-lakehouse', 'default', 730, FALSE),
|
||||
('stonks-audit', 'default', 730, FALSE);
|
||||
|
||||
-- Track retention cleanup runs for observability
|
||||
CREATE TABLE retention_runs (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
bucket_name VARCHAR(200) NOT NULL,
|
||||
objects_scanned INTEGER NOT NULL DEFAULT 0,
|
||||
objects_deleted INTEGER NOT NULL DEFAULT 0,
|
||||
bytes_freed BIGINT NOT NULL DEFAULT 0,
|
||||
db_rows_deleted INTEGER NOT NULL DEFAULT 0,
|
||||
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
completed_at TIMESTAMPTZ,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'running',
|
||||
error_message TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX idx_retention_runs_bucket ON retention_runs(bucket_name, started_at DESC);
|
||||
CREATE INDEX idx_retention_runs_status ON retention_runs(status);
|
||||
Reference in New Issue
Block a user