First reviewable slice of workstream A: schema only, no importers, no data. - data_import_runs: lean batch-import audit (source/revision/status, row_counts_json + validation_json as Text-holding-JSON per repo convention). - fundamental_snapshots: CIK-keyed, one immutable row per accession; stores per-period raw facts (duration = cumulative YTD/FY, balance-sheet = period-end) plus period_start/period_end/fiscal_year/fiscal_period so discrete quarters, Q4, TTM and YoY are derived at read time. - earnings_events: Dolt-sourced calendar + surprise history, unique (ticker_id, announce_date). - tickers: nullable cik/sic/sic_description — the ticker<->issuer join point. fundamental_data is left untouched (cutover gated separately at A5). Models registered in app/models/__init__.py; Ticker gains an earnings_events relationship. Verified: create_all builds the tables, mappers configure, and migration 026 renders valid Postgres DDL up and down. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
2.3 KiB
Python
39 lines
2.3 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import String, DateTime
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class Ticker(Base):
|
|
__tablename__ = "tickers"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
symbol: Mapped[str] = mapped_column(String(10), unique=True, nullable=False)
|
|
# Company name (e.g. "Biogen Inc."); backfilled from Alpaca, nullable for
|
|
# symbols Alpaca doesn't know.
|
|
name: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
|
# SEC issuer identity, refreshed by the SEC fundamentals import from
|
|
# company_tickers.json / submissions. The only ticker<->issuer join point;
|
|
# multi-class tickers (GOOG/GOOGL) share these values. Nullable: not every
|
|
# symbol resolves to a CIK (e.g. ADRs, foreign issuers not in SEC data).
|
|
cik: Mapped[str | None] = mapped_column(String(10), nullable=True)
|
|
sic: Mapped[str | None] = mapped_column(String(4), nullable=True)
|
|
sic_description: Mapped[str | None] = mapped_column(String(160), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
# Relationships (cascade deletes)
|
|
ohlcv_records = relationship("OHLCVRecord", back_populates="ticker", cascade="all, delete-orphan")
|
|
sentiment_scores = relationship("SentimentScore", back_populates="ticker", cascade="all, delete-orphan")
|
|
fundamental_data = relationship("FundamentalData", back_populates="ticker", cascade="all, delete-orphan")
|
|
sr_levels = relationship("SRLevel", back_populates="ticker", cascade="all, delete-orphan")
|
|
dimension_scores = relationship("DimensionScore", back_populates="ticker", cascade="all, delete-orphan")
|
|
composite_scores = relationship("CompositeScore", back_populates="ticker", cascade="all, delete-orphan")
|
|
trade_setups = relationship("TradeSetup", back_populates="ticker", cascade="all, delete-orphan")
|
|
watchlist_entries = relationship("WatchlistEntry", back_populates="ticker", cascade="all, delete-orphan")
|
|
ingestion_progress = relationship("IngestionProgress", back_populates="ticker", cascade="all, delete-orphan", uselist=False)
|
|
earnings_events = relationship("EarningsEvent", back_populates="ticker", cascade="all, delete-orphan")
|