merge: integrate alpha management with main and sequence migration 0005

This commit is contained in:
yuxuanhui
2026-09-08 10:45:00 +08:00
56 changed files with 7453 additions and 55 deletions
+177
View File
@@ -208,3 +208,180 @@ class AIToolCall(Base):
status: Mapped[str] = mapped_column(String(30), default="pending")
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
__table_args__ = (UniqueConstraint("run_id", "call_id"),)
class BacktestConfig(Base):
__tablename__ = "backtest_config"
id: Mapped[int] = mapped_column(primary_key=True, default=1)
concurrency: Mapped[int] = mapped_column(Integer, default=3)
batch_size: Mapped[int] = mapped_column(Integer, default=8)
version: Mapped[int] = mapped_column(Integer, default=1)
blocked_reason: Mapped[str | None] = mapped_column(Text)
blocked_until: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
class BacktestDraft(Base):
__tablename__ = "backtest_drafts"
id: Mapped[str] = mapped_column(String(36), primary_key=True)
version: Mapped[int] = mapped_column(Integer, default=1)
name: Mapped[str] = mapped_column(String(200))
source: Mapped[dict] = mapped_column(JSON)
candidates: Mapped[list] = mapped_column(JSON)
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
class BacktestPreview(Base):
__tablename__ = "backtest_previews"
id: Mapped[str] = mapped_column(String(36), primary_key=True)
version: Mapped[int] = mapped_column(Integer, default=1)
name: Mapped[str] = mapped_column(String(200))
source: Mapped[dict] = mapped_column(JSON)
candidates: Mapped[list] = mapped_column(JSON)
batches: Mapped[list] = mapped_column(JSON)
batch_size: Mapped[int] = mapped_column(Integer)
digest: Mapped[str] = mapped_column(String(64))
duplicates: Mapped[list] = mapped_column(JSON)
ai_context: Mapped[dict] = mapped_column(JSON, default=dict)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
class BacktestRun(Base):
__tablename__ = "backtest_runs"
id: Mapped[str] = mapped_column(String(36), primary_key=True)
preview_id: Mapped[str] = mapped_column(ForeignKey("backtest_previews.id"), unique=True)
idempotency_key: Mapped[str] = mapped_column(String(100), unique=True)
name: Mapped[str] = mapped_column(String(200))
source: Mapped[dict] = mapped_column(JSON)
ai_context: Mapped[dict] = mapped_column(JSON, default=dict)
control: Mapped[str] = mapped_column(String(20), default="active")
status: Mapped[str] = mapped_column(String(30), default="queued", index=True)
version: Mapped[int] = mapped_column(Integer, default=1)
event_seq: Mapped[int] = mapped_column(Integer, default=0)
total: Mapped[int] = mapped_column(Integer)
batch_size: Mapped[int] = mapped_column(Integer)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
class SimulationAttempt(Base):
__tablename__ = "simulation_attempts"
id: Mapped[str] = mapped_column(String(36), primary_key=True)
run_id: Mapped[str] = mapped_column(ForeignKey("backtest_runs.id"), index=True)
ordinal: Mapped[int] = mapped_column(Integer)
state: Mapped[str] = mapped_column(String(30), default="queued", index=True)
payload: Mapped[list] = mapped_column(JSON)
progress_url: Mapped[str | None] = mapped_column(Text)
remote_complete: Mapped[bool] = mapped_column(Boolean, default=False)
children: Mapped[list] = mapped_column(JSON, default=list)
receipts: Mapped[dict] = mapped_column(JSON, default=dict)
poll_count: Mapped[int] = mapped_column(Integer, default=0)
submit_count: Mapped[int] = mapped_column(Integer, default=0)
next_poll_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
error: Mapped[str | None] = mapped_column(Text)
error_code: Mapped[str | None] = mapped_column(String(50))
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
__table_args__ = (UniqueConstraint("run_id", "ordinal"),)
class BacktestItem(Base):
__tablename__ = "backtest_items"
id: Mapped[str] = mapped_column(String(36), primary_key=True)
run_id: Mapped[str] = mapped_column(ForeignKey("backtest_runs.id"), index=True)
attempt_id: Mapped[str] = mapped_column(ForeignKey("simulation_attempts.id"), index=True)
client_item_id: Mapped[str] = mapped_column(String(100))
ordinal: Mapped[int] = mapped_column(Integer)
expression: Mapped[str] = mapped_column(Text)
settings: Mapped[dict] = mapped_column(JSON)
fingerprint: Mapped[str] = mapped_column(String(64), index=True)
platform_status: Mapped[str] = mapped_column(String(30), default="pending")
collection_status: Mapped[str] = mapped_column(String(30), default="pending")
persistence_status: Mapped[str] = mapped_column(String(30), default="pending")
simulation_id: Mapped[str | None] = mapped_column(String(100))
alpha_id: Mapped[str | None] = mapped_column(String(100))
error: Mapped[str | None] = mapped_column(Text)
__table_args__ = (UniqueConstraint("run_id", "client_item_id"),)
class BacktestResult(Base):
__tablename__ = "backtest_results"
item_id: Mapped[str] = mapped_column(ForeignKey("backtest_items.id"), primary_key=True)
attempt_id: Mapped[str] = mapped_column(ForeignKey("simulation_attempts.id"))
alpha_id: Mapped[str] = mapped_column(ForeignKey("alphas.id"), index=True)
snapshot: Mapped[dict] = mapped_column(JSON)
observed_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
complete: Mapped[bool] = mapped_column(Boolean, default=True)
class BacktestEvent(Base):
__tablename__ = "backtest_events"
run_id: Mapped[str] = mapped_column(ForeignKey("backtest_runs.id"), primary_key=True)
seq: Mapped[int] = mapped_column(Integer, primary_key=True)
kind: Mapped[str] = mapped_column(String(50))
payload: Mapped[dict] = mapped_column(JSON)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
class CatalogScope(Base):
__tablename__ = "catalog_scopes"
key: Mapped[str] = mapped_column(String(200), primary_key=True)
scope: Mapped[dict] = mapped_column(JSON)
catalog_version: Mapped[str | None] = mapped_column(String(36))
synced_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
class CatalogBatch(Base):
__tablename__ = "catalog_batches"
id: Mapped[str] = mapped_column(ForeignKey("sync_jobs.id"), primary_key=True)
scope_key: Mapped[str] = mapped_column(ForeignKey("catalog_scopes.key"), index=True)
dataset_id: Mapped[str | None] = mapped_column(String(200))
complete: Mapped[bool] = mapped_column(Boolean, default=False)
count: Mapped[int] = mapped_column(Integer, default=0)
completed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
class CatalogDataset(Base):
__tablename__ = "catalog_datasets"
scope_key: Mapped[str] = mapped_column(ForeignKey("catalog_scopes.key"), primary_key=True)
id: Mapped[str] = mapped_column(String(200), primary_key=True)
field_version: Mapped[str | None] = mapped_column(ForeignKey("catalog_batches.id"))
class CatalogEntry(Base):
"""Immutable published snapshots; staging rows remain invisible until batch completion."""
__tablename__ = "catalog_entries"
batch_id: Mapped[str] = mapped_column(ForeignKey("catalog_batches.id"), primary_key=True)
id: Mapped[str] = mapped_column(String(200), primary_key=True)
name: Mapped[str | None] = mapped_column(Text)
category: Mapped[str | None] = mapped_column(String(200))
subcategory: Mapped[str | None] = mapped_column(String(200))
field_type: Mapped[str | None] = mapped_column(String(100))
coverage: Mapped[float | None] = mapped_column(Float)
user_count: Mapped[int | None] = mapped_column(Integer)
alpha_count: Mapped[int | None] = mapped_column(Integer)
field_count: Mapped[int | None] = mapped_column(Integer)
description: Mapped[str | None] = mapped_column(Text)
unit: Mapped[str | None] = mapped_column(Text)
synced_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
class CatalogNote(Base):
__tablename__ = "catalog_notes"
scope_key: Mapped[str] = mapped_column(ForeignKey("catalog_scopes.key"), primary_key=True)
dataset_id: Mapped[str] = mapped_column(String(200), primary_key=True)
# Empty field_id denotes the dataset; platform identifiers cannot be empty.
field_id: Mapped[str] = mapped_column(String(200), primary_key=True, default="")
note: Mapped[str] = mapped_column(Text, default="")
version: Mapped[int] = mapped_column(Integer, default=1)
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)
class TemplateInput(Base):
__tablename__ = "template_inputs"
id: Mapped[str] = mapped_column(String(36), primary_key=True)
scope_key: Mapped[str] = mapped_column(ForeignKey("catalog_scopes.key"), index=True)
dataset_id: Mapped[str] = mapped_column(String(200))
collection_version: Mapped[str] = mapped_column(ForeignKey("catalog_batches.id"))
selection: Mapped[str] = mapped_column(String(20))
field_ids: Mapped[list] = mapped_column(JSON)
field_types: Mapped[dict] = mapped_column(JSON)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=now)