feat: competitive intelligence & historical pattern matching layer
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
-- Global News Interpolation Layer
|
||||
-- Adds tables for macro event classification, company exposure profiles,
|
||||
-- macro impact scoring, and trend projections.
|
||||
|
||||
-- ============================================================
|
||||
-- Global Events
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE global_events (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
event_types TEXT[] NOT NULL,
|
||||
severity VARCHAR(20) NOT NULL,
|
||||
affected_regions TEXT[] NOT NULL DEFAULT '{}',
|
||||
affected_sectors TEXT[] NOT NULL DEFAULT '{}',
|
||||
affected_commodities TEXT[] NOT NULL DEFAULT '{}',
|
||||
summary TEXT NOT NULL,
|
||||
key_facts JSONB NOT NULL DEFAULT '[]',
|
||||
estimated_duration VARCHAR(20) NOT NULL,
|
||||
confidence FLOAT NOT NULL,
|
||||
source_document_id UUID REFERENCES documents(id),
|
||||
model_provider VARCHAR(100),
|
||||
model_name VARCHAR(200),
|
||||
prompt_version VARCHAR(100),
|
||||
schema_version VARCHAR(20),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_global_events_created ON global_events(created_at);
|
||||
|
||||
-- ============================================================
|
||||
-- Macro Impact Records
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE macro_impact_records (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
event_id UUID NOT NULL REFERENCES global_events(id),
|
||||
company_id UUID NOT NULL REFERENCES companies(id),
|
||||
ticker VARCHAR(20) NOT NULL,
|
||||
macro_impact_score FLOAT NOT NULL,
|
||||
impact_direction VARCHAR(20) NOT NULL,
|
||||
contributing_factors JSONB NOT NULL DEFAULT '[]',
|
||||
confidence FLOAT NOT NULL,
|
||||
computed_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_macro_impact_event ON macro_impact_records(event_id);
|
||||
CREATE INDEX idx_macro_impact_company_computed ON macro_impact_records(company_id, computed_at);
|
||||
CREATE INDEX idx_macro_impact_ticker_computed ON macro_impact_records(ticker, computed_at);
|
||||
|
||||
-- ============================================================
|
||||
-- Exposure Profiles
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE exposure_profiles (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
company_id UUID NOT NULL REFERENCES companies(id),
|
||||
geographic_revenue_mix JSONB NOT NULL DEFAULT '{}',
|
||||
supply_chain_regions TEXT[] NOT NULL DEFAULT '{}',
|
||||
key_input_commodities TEXT[] NOT NULL DEFAULT '{}',
|
||||
regulatory_jurisdictions TEXT[] NOT NULL DEFAULT '{}',
|
||||
market_position_tier VARCHAR(30) NOT NULL DEFAULT 'regional',
|
||||
export_dependency_pct FLOAT NOT NULL DEFAULT 0.0,
|
||||
source VARCHAR(20) NOT NULL DEFAULT 'manual',
|
||||
confidence FLOAT NOT NULL DEFAULT 1.0,
|
||||
version INTEGER NOT NULL DEFAULT 1,
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_exposure_profiles_company_active ON exposure_profiles(company_id, active);
|
||||
|
||||
-- ============================================================
|
||||
-- Trend Projections
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE trend_projections (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
trend_window_id UUID NOT NULL REFERENCES trend_windows(id),
|
||||
projected_direction VARCHAR(20) NOT NULL,
|
||||
projected_strength FLOAT NOT NULL,
|
||||
projected_confidence FLOAT NOT NULL,
|
||||
projection_horizon VARCHAR(10) NOT NULL,
|
||||
driving_factors JSONB NOT NULL DEFAULT '[]',
|
||||
macro_contribution_pct FLOAT NOT NULL DEFAULT 0.0,
|
||||
diverges_from_current BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
computed_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_trend_projections_window ON trend_projections(trend_window_id);
|
||||
@@ -0,0 +1,51 @@
|
||||
-- Competitive Intelligence & Historical Pattern Matching Layer
|
||||
-- Adds tables for competitor relationships and competitive signal records.
|
||||
|
||||
-- ============================================================
|
||||
-- Competitor Relationships
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE competitor_relationships (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
company_a_id UUID NOT NULL REFERENCES companies(id),
|
||||
company_b_id UUID NOT NULL REFERENCES companies(id),
|
||||
relationship_type VARCHAR(30) NOT NULL,
|
||||
strength FLOAT NOT NULL DEFAULT 0.5,
|
||||
bidirectional BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
source VARCHAR(20) NOT NULL DEFAULT 'manual',
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT chk_relationship_type CHECK (
|
||||
relationship_type IN ('direct_rival', 'same_sector', 'overlapping_products', 'supply_chain_adjacent')
|
||||
),
|
||||
CONSTRAINT chk_strength CHECK (strength >= 0 AND strength <= 1),
|
||||
CONSTRAINT chk_source CHECK (source IN ('manual', 'inferred')),
|
||||
CONSTRAINT chk_different_companies CHECK (company_a_id != company_b_id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_competitor_rel_company_a ON competitor_relationships(company_a_id) WHERE active = TRUE;
|
||||
CREATE INDEX idx_competitor_rel_company_b ON competitor_relationships(company_b_id) WHERE active = TRUE;
|
||||
CREATE UNIQUE INDEX idx_competitor_rel_unique_pair ON competitor_relationships(
|
||||
LEAST(company_a_id, company_b_id), GREATEST(company_a_id, company_b_id)
|
||||
) WHERE active = TRUE;
|
||||
|
||||
-- ============================================================
|
||||
-- Competitive Signal Records
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE competitive_signal_records (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
source_document_id UUID REFERENCES documents(id),
|
||||
source_ticker VARCHAR(20) NOT NULL,
|
||||
target_ticker VARCHAR(20) NOT NULL,
|
||||
catalyst_type VARCHAR(50) NOT NULL,
|
||||
pattern_confidence FLOAT NOT NULL,
|
||||
signal_direction VARCHAR(20) NOT NULL,
|
||||
signal_strength FLOAT NOT NULL,
|
||||
relationship_strength FLOAT NOT NULL,
|
||||
computed_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_competitive_signals_target ON competitive_signal_records(target_ticker, computed_at DESC);
|
||||
CREATE INDEX idx_competitive_signals_source ON competitive_signal_records(source_ticker, computed_at DESC);
|
||||
Reference in New Issue
Block a user