GeoIntel release gates / Compile, test, contracts and builds (push) Successful in 1m49s
GeoIntel release gates / Python and npm vulnerability policy (push) Successful in 21s
GeoIntel release gates / Production AI image, SBOM and container scan (push) Successful in 5m39s
GeoIntel release gates / Deploy exact gated revision to Unraid (push) Failing after 58m43s
60 lines
3.3 KiB
Python
60 lines
3.3 KiB
Python
"""Add Sprint 8 detection foundation."""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from geoalchemy2 import Geometry
|
|
|
|
|
|
revision = "202606120800"
|
|
down_revision = "202606120700"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column("analysis_runs", sa.Column("dataset_id", sa.UUID(as_uuid=True), sa.ForeignKey("datasets.id", ondelete="SET NULL"), nullable=True))
|
|
op.add_column("analysis_runs", sa.Column("job_id", sa.UUID(as_uuid=True), sa.ForeignKey("jobs.id", ondelete="SET NULL"), nullable=True))
|
|
op.add_column("analysis_runs", sa.Column("model_name", sa.String(length=255), nullable=True))
|
|
op.add_column("analysis_runs", sa.Column("model_version", sa.String(length=120), nullable=True))
|
|
op.add_column("analysis_runs", sa.Column("result_json", sa.JSON(), nullable=True))
|
|
op.add_column("analysis_runs", sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("NOW()"), nullable=False))
|
|
|
|
op.create_table(
|
|
"detections",
|
|
sa.Column("id", sa.UUID(as_uuid=True), primary_key=True),
|
|
sa.Column("project_id", sa.UUID(as_uuid=True), sa.ForeignKey("projects.id", ondelete="CASCADE"), nullable=False),
|
|
sa.Column("dataset_id", sa.UUID(as_uuid=True), sa.ForeignKey("datasets.id", ondelete="SET NULL"), nullable=True),
|
|
sa.Column("analysis_run_id", sa.UUID(as_uuid=True), sa.ForeignKey("analysis_runs.id", ondelete="SET NULL"), nullable=True),
|
|
sa.Column("job_id", sa.UUID(as_uuid=True), sa.ForeignKey("jobs.id", ondelete="SET NULL"), nullable=True),
|
|
sa.Column("model_name", sa.String(length=255), nullable=False),
|
|
sa.Column("model_version", sa.String(length=120), nullable=True),
|
|
sa.Column("class_name", sa.String(length=120), nullable=False),
|
|
sa.Column("confidence", sa.Float(), nullable=False),
|
|
sa.Column("geometry", Geometry("GEOMETRY", srid=4326, spatial_index=False), nullable=False),
|
|
sa.Column("bbox_json", sa.JSON(), nullable=True),
|
|
sa.Column("source_tile_path", sa.String(length=500), nullable=True),
|
|
sa.Column("properties_json", sa.JSON(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("NOW()"), nullable=False),
|
|
)
|
|
op.create_index("ix_detections_project_id", "detections", ["project_id"])
|
|
op.create_index("ix_detections_dataset_id", "detections", ["dataset_id"])
|
|
op.create_index("ix_detections_analysis_run_id", "detections", ["analysis_run_id"])
|
|
op.create_index("ix_detections_class_name", "detections", ["class_name"])
|
|
op.create_index("ix_detections_geometry", "detections", ["geometry"], postgresql_using="gist")
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_detections_geometry", table_name="detections", postgresql_using="gist")
|
|
op.drop_index("ix_detections_class_name", table_name="detections")
|
|
op.drop_index("ix_detections_analysis_run_id", table_name="detections")
|
|
op.drop_index("ix_detections_dataset_id", table_name="detections")
|
|
op.drop_index("ix_detections_project_id", table_name="detections")
|
|
op.drop_table("detections")
|
|
|
|
op.drop_column("analysis_runs", "created_at")
|
|
op.drop_column("analysis_runs", "result_json")
|
|
op.drop_column("analysis_runs", "model_version")
|
|
op.drop_column("analysis_runs", "model_name")
|
|
op.drop_column("analysis_runs", "job_id")
|
|
op.drop_column("analysis_runs", "dataset_id")
|