Files
CIAgent/apps/api/migrations/versions/8ceefbd0a6a5_create_monitoring_runs.py
saksham 1a4c80958f Initial commit: CI Agent competitive-intelligence monitoring app
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).
2026-08-05 10:48:20 -04:00

97 lines
3.4 KiB
Python

"""create monitoring runs
Revision ID: 8ceefbd0a6a5
Revises: 484419ccd357
Create Date: 2026-07-31 19:10:32.580895
"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "8ceefbd0a6a5"
down_revision: str | None = "484419ccd357"
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(
"monitoring_runs",
sa.Column("company_id", sa.Uuid(), nullable=False),
sa.Column(
"trigger_type",
sa.Enum(
"SCHEDULED",
"MANUAL",
"INITIAL",
"RETRY",
name="monitoringruntrigger",
native_enum=False,
length=20,
),
nullable=False,
),
sa.Column(
"status",
sa.Enum(
"QUEUED",
"RUNNING",
"SUCCESSFUL",
"PARTIAL",
"FAILED",
name="monitoringrunstatus",
native_enum=False,
length=20,
),
nullable=False,
),
sa.Column("started_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("sources_attempted", sa.Integer(), nullable=False),
sa.Column("sources_successful", sa.Integer(), nullable=False),
sa.Column("sources_failed", sa.Integer(), nullable=False),
sa.Column("items_collected", sa.Integer(), nullable=False),
sa.Column("changes_detected", sa.Integer(), nullable=False),
sa.Column("error_summary", sa.Text(), nullable=True),
sa.Column("worker_task_id", sa.String(length=255), nullable=True),
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.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("id"),
)
op.create_index(
op.f("ix_monitoring_runs_company_id"), "monitoring_runs", ["company_id"], unique=False
)
# ### end Alembic commands ###
# snapshots.monitoring_run_id was added in the previous migration without
# a FK constraint, since monitoring_runs didn't exist yet - add it now
# that the table this phase creates exists. batch_alter_table so this
# also works on SQLite (which can't ALTER TABLE ADD CONSTRAINT directly).
with op.batch_alter_table("snapshots") as batch_op:
batch_op.create_foreign_key(
"fk_snapshots_monitoring_run_id",
"monitoring_runs",
["monitoring_run_id"],
["id"],
ondelete="SET NULL",
)
def downgrade() -> None:
with op.batch_alter_table("snapshots") as batch_op:
batch_op.drop_constraint("fk_snapshots_monitoring_run_id", type_="foreignkey")
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_monitoring_runs_company_id"), table_name="monitoring_runs")
op.drop_table("monitoring_runs")
# ### end Alembic commands ###