Add v1 contract DB models and migration (#544)#594
Merged
marcvergees merged 1 commit intoJun 26, 2026
Conversation
marcvergees
approved these changes
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #544.
Adds the five v1 contract DB models — Input, Extraction, Incident, Form, Report — plus migration 002 and tests. The existing Template, FormSubmission, and Job models are left untouched.
Each model uses a UUID primary key via
sa.Uuid()(a real UUID type on Postgres, CHAR(32) on SQLite so the migration tests pass),created_at/updated_attimestamps, and the status enums from #543. The IncidentContract superset lives as a single JSON blob on Extraction rather than separate tables, matching the contract structure. Added anInputType(voice/text) enum toenums.py— the one enum the contract referenced inline without a named entry.Two deliberate decisions worth flagging for review:
Job FK:
Form.job_idandReport.job_idare plain UUID columns with no FK constraint. The contract's Job entity is UUID/enum-typed, but the existing Job model (from the async work) is int-PK and celery-shaped, so a real FK isn't possible yet. The columns exist with the right type and name so the route layer can use them; a follow-up adds the constraint once the contract Job is resolved.Form.incident_iddoes get a proper FK toincidents.JSON vs JSONB: all JSON columns use
sa.JSON(Postgresjson, notjsonb) for consistency with migration 001 and SQLite test compatibility. If we later need containment operators or GIN indexing on the blobs — especiallyincident_contract— a follow-up can switch viawith_variant().Migration 002 was autogenerated then hand-checked;
downgrade()drops tables in reverse dependency order. The new models are registered inalembic/env.pyandconftest.pyso autogenerate and the test harness pick them up.Tests: 112 passing.
test_migrations.pyasserts the table/column sets and FK constraints (including thatjob_idhas no FK);test_v1_models.pyadds direct ORM round-trip tests covering JSON fields, soft-delete, all 20 form types, and enum status persistence.