Skip to main content

Database Schema

Terra uses PostgreSQL via Supabase with 35+ tables organized into logical domains.
This document provides a tiered reference: detailed coverage for core tables, brief listings for supporting tables.

Schema Overview


Core Tables (Detailed)

forms

The central table storing form definitions and settings.
Key columns:
  • draft_schema / published_schema — Recursive JSON form definitions
  • settings — JSONB blob for branding, deadlines, etc.
  • folder_id — Which workspace contains this form
  • submission_prefix — Custom prefix for reference IDs (e.g., “RENT-”)

form_submissions

Individual submissions with answers stored as JSONB.
Key columns:
  • answers{"full-name": "Jane Doe", "income": 45000, ...}
  • reference_id — Human-readable ID (e.g., “RENT-2024-001”)
  • statussubmitted, under_review, approved, denied, etc.
  • plaid_access_tokens — Encrypted Plaid tokens per field

user_profiles

Admin users with roles (synced from WorkOS).
Role hierarchy:
  • super_admin — Full system access
  • admin — Dashboard access, manage forms
  • user — Limited team member
  • applicant — Portal only, view own applications

applicants

Applicant identity records (separate from admin users).
Design note: Applicants and admin users are separate tables. An applicant can have a portal account (with workos_user_id) without being an admin.

folders (Workspaces)

Logical grouping for forms with optional custom domains.

async_operations

Persistent queue for background jobs.
See Queue Architecture for details.

airtable_connections

OAuth tokens and field mappings for Airtable sync.

webhook_configs

Webhook endpoints for forms.

notification_events

Log of all sent notifications.

Supporting Tables (Brief)

Agencies & Multi-tenancy

Form Features

Notifications

Applicant Data

Webhooks & Events

Audit & History

System


Row Level Security

Most tables use service role access (RLS bypassed) with application-level permission checks. RLS is enabled but permissive for background operations:

Indexes

Key indexes for query performance:

Migrations

Terra uses numbered SQL migrations in apps/terra/migrations/:
Run migrations via Supabase dashboard or CLI. Migrations are idempotent where possible.

File Storage

How files are stored securely

Encryption

PII encryption strategy