Database Schema¶
Purpose¶
This document records the initial PostgreSQL schema boundary for the TRAQ server. The goal is to move metadata and workflow state into PostgreSQL while keeping binary artifacts on disk.
Design rules¶
PostgreSQL is the intended runtime target.
SQLAlchemy models define the application schema.
Filesystem storage remains in place for:
uploaded audio
uploaded images
generated PDFs
generated DOCX
exported GeoJSON
Working round data may be pruned after archive if final snapshots and audit history are preserved.
Model modules¶
app/db.py: engine/session bootstrap, declarative base, and the local schema creation helper.app/db_models.py: ORM tables for devices, jobs, rounds, media metadata, finals, artifacts, and events.
Core tables¶
Permanent records:
devicesdevice_tokenscustomersbilling_profilesoperatorstreesjobsjob_assignmentsjob_finalsjob_geojson_exportsartifactsjob_events
Working records:
job_roundsround_recordingsround_images
Intent by table¶
devicesRegistered devices and their approval/role state.
device_tokensIssued bearer tokens for approved devices.
jobsTop-level job record, job number, current status, and archived final snapshots. Jobs reference reusable customer, billing, and operator rows while keeping job-specific work fields locally on the job row.
customersReusable customer/contact identity imported from
job_record.json.billing_profilesReusable billing/contact identity imported from
job_record.json.operatorsReusable assessor/operator identity derived from archived final provenance.
treesReusable customer-scoped tree identities. A tree number is unique within a customer and may be referenced by multiple jobs over time.
job_assignmentsCurrent one-device-at-a-time assignment mapping.
job_roundsWorking review rounds and cached review payload/manifests.
round_recordings/round_imagesUploaded media metadata and artifact paths.
job_finalsFinal or correction snapshots retained after working rounds may be pruned.
job_geojson_exportsStored GeoJSON export objects linked to the job and export kind. The raw GeoJSON payload is kept in PostgreSQL as JSONB while file exports remain on disk.
artifactsFile references for generated and uploaded non-database artifacts.
job_eventsAppend-only audit trail for status, assignment, and finalization events.
Operational direction¶
Migration order should be:
device auth and token state
jobs and assignments
round metadata and manifests
media metadata
final/correction metadata
audit trail
The runtime storage migration is complete for operational state. The filesystem remains for artifact bytes and exported debug/compatibility copies.
See also:
docs/runtime_export_boundary.rst