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.draft_schema/published_schema— Recursive JSON form definitionssettings— JSONB blob for branding, deadlines, etc.folder_id— Which workspace contains this formsubmission_prefix— Custom prefix for reference IDs (e.g., “RENT-”)
form_submissions
Individual submissions with answers stored as JSONB.answers—{"full-name": "Jane Doe", "income": 45000, ...}reference_id— Human-readable ID (e.g., “RENT-2024-001”)status—submitted,under_review,approved,denied, etc.plaid_access_tokens— Encrypted Plaid tokens per field
user_profiles
Admin users with roles (synced from WorkOS).super_admin— Full system accessadmin— Dashboard access, manage formsuser— Limited team memberapplicant— Portal only, view own applications
applicants
Applicant identity records (separate from admin users).workos_user_id) without being an admin.
folders (Workspaces)
Logical grouping for forms with optional custom domains.async_operations
Persistent queue for background jobs.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 inapps/terra/migrations/:
Related
File Storage
How files are stored securely
Encryption
PII encryption strategy