| 1 | """initial schema |
| 2 | |
| 3 | Revision ID: 0001_initial |
| 4 | Revises: |
| 5 | Create Date: 2026-06-11 |
| 6 | |
| 7 | Builds the full schema from the SQLAlchemy metadata and adds ALPR-specific performance |
| 8 | indexes (trigram for partial-plate search, time+camera composite) and optional extensions. |
| 9 | Using metadata.create_all keeps the migration in lock-step with the models for the MVP; later |
| 10 | schema changes are authored as incremental, reversible revisions. |
| 11 | """ |
| 12 | from alembic import op |
| 13 | from sqlalchemy import text |
| 14 | |
| 15 | from app.db.base import Base |
| 16 | import app.models |
| 17 | |
| 18 | revision = "0001_initial" |
| 19 | down_revision = None |
| 20 | branch_labels = None |
| 21 | depends_on = None |
| 22 | |
| 23 | |
| 24 | def upgrade() -> None: |
| 25 | bind = op.get_bind() |
| 26 | try: |
| 27 | bind.execute(text("CREATE EXTENSION IF NOT EXISTS pg_trgm")) |
| 28 | except Exception: |
| 29 | pass |
| 30 | |
| 31 | Base.metadata.create_all(bind=bind) |
| 32 | |
| 33 | try: |
| 34 | bind.execute(text( |
| 35 | "CREATE INDEX IF NOT EXISTS ix_plates_norm_trgm " |
| 36 | "ON license_plates USING gin (plate_norm gin_trgm_ops)")) |
| 37 | bind.execute(text( |
| 38 | "CREATE INDEX IF NOT EXISTS ix_reads_norm_trgm " |
| 39 | "ON plate_reads USING gin (plate_norm gin_trgm_ops)")) |
| 40 | except Exception: |
| 41 | pass |
| 42 | |
| 43 | |
| 44 | def downgrade() -> None: |
| 45 | bind = op.get_bind() |
| 46 | Base.metadata.drop_all(bind=bind) |