FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring, source collection, LLM-based change analysis, enrichment, and account security (Turnstile, escalating lockout, email verification).
108 lines
3.7 KiB
Python
108 lines
3.7 KiB
Python
"""create detected changes
|
|
|
|
Revision ID: cb61ba9570fb
|
|
Revises: 8ceefbd0a6a5
|
|
Create Date: 2026-07-31 19:34:49.775190
|
|
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "cb61ba9570fb"
|
|
down_revision: str | None = "8ceefbd0a6a5"
|
|
branch_labels: Sequence[str] | str | None = None
|
|
depends_on: Sequence[str] | str | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table(
|
|
"detected_changes",
|
|
sa.Column("company_id", sa.Uuid(), nullable=False),
|
|
sa.Column("source_id", sa.Uuid(), nullable=False),
|
|
sa.Column("monitoring_run_id", sa.Uuid(), nullable=False),
|
|
sa.Column("previous_snapshot_id", sa.Uuid(), nullable=True),
|
|
sa.Column("current_snapshot_id", sa.Uuid(), nullable=False),
|
|
sa.Column(
|
|
"change_type",
|
|
sa.Enum(
|
|
"NEW_DOCUMENT",
|
|
"REMOVED_DOCUMENT",
|
|
"CONTENT_MODIFIED",
|
|
"PRICE_CHANGE",
|
|
"LEADERSHIP_CHANGE",
|
|
"FILING_NEW",
|
|
name="changetype",
|
|
native_enum=False,
|
|
length=30,
|
|
),
|
|
nullable=False,
|
|
),
|
|
sa.Column("raw_diff", sa.JSON(), nullable=False),
|
|
sa.Column("significance_score", sa.Float(), nullable=False),
|
|
sa.Column("confidence_score", sa.Float(), nullable=False),
|
|
sa.Column(
|
|
"severity",
|
|
sa.Enum(
|
|
"CRITICAL",
|
|
"HIGH",
|
|
"MEDIUM",
|
|
"LOW",
|
|
name="severitylevel",
|
|
native_enum=False,
|
|
length=20,
|
|
),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"status",
|
|
sa.Enum(
|
|
"NEW",
|
|
"ACKNOWLEDGED",
|
|
"DISMISSED",
|
|
name="changestatus",
|
|
native_enum=False,
|
|
length=20,
|
|
),
|
|
nullable=False,
|
|
),
|
|
sa.Column("summary", sa.String(length=500), nullable=False),
|
|
sa.Column("id", sa.Uuid(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.ForeignKeyConstraint(["company_id"], ["companies.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["current_snapshot_id"], ["snapshots.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["monitoring_run_id"], ["monitoring_runs.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["previous_snapshot_id"], ["snapshots.id"], ondelete="SET NULL"),
|
|
sa.ForeignKeyConstraint(["source_id"], ["sources.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("id"),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_detected_changes_company_id"), "detected_changes", ["company_id"], unique=False
|
|
)
|
|
op.create_index(
|
|
op.f("ix_detected_changes_monitoring_run_id"),
|
|
"detected_changes",
|
|
["monitoring_run_id"],
|
|
unique=False,
|
|
)
|
|
op.create_index(
|
|
op.f("ix_detected_changes_source_id"), "detected_changes", ["source_id"], unique=False
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_index(op.f("ix_detected_changes_source_id"), table_name="detected_changes")
|
|
op.drop_index(op.f("ix_detected_changes_monitoring_run_id"), table_name="detected_changes")
|
|
op.drop_index(op.f("ix_detected_changes_company_id"), table_name="detected_changes")
|
|
op.drop_table("detected_changes")
|
|
# ### end Alembic commands ###
|