Skip to content

Add v1 contract DB models and migration (#544)#594

Merged
marcvergees merged 1 commit into
fireform-core:developmentfrom
abhishek-8081:issue-544-models
Jun 26, 2026
Merged

Add v1 contract DB models and migration (#544)#594
marcvergees merged 1 commit into
fireform-core:developmentfrom
abhishek-8081:issue-544-models

Conversation

@abhishek-8081

Copy link
Copy Markdown
Collaborator

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_at timestamps, 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 an InputType (voice/text) enum to enums.py — the one enum the contract referenced inline without a named entry.

Two deliberate decisions worth flagging for review:

  • Job FK: Form.job_id and Report.job_id are 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_id does get a proper FK to incidents.

  • JSON vs JSONB: all JSON columns use sa.JSON (Postgres json, not jsonb) for consistency with migration 001 and SQLite test compatibility. If we later need containment operators or GIN indexing on the blobs — especially incident_contract — a follow-up can switch via with_variant().

Migration 002 was autogenerated then hand-checked; downgrade() drops tables in reverse dependency order. The new models are registered in alembic/env.py and conftest.py so autogenerate and the test harness pick them up.

Tests: 112 passing. test_migrations.py asserts the table/column sets and FK constraints (including that job_id has no FK); test_v1_models.py adds direct ORM round-trip tests covering JSON fields, soft-delete, all 20 form types, and enum status persistence.

@marcvergees marcvergees merged commit 7224f68 into fireform-core:development Jun 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

models for v1 API contract

2 participants