Skip to main content
Migrations live in db/migrations/. Run them in filename order for a fresh project. The onboarding wizard can apply them automatically via one-click schema install.

Migration files

FileDomain
001_extensions.sqlPostgres extensions (pgvector, pg_cron, pgcrypto)
002_enums.sqlShared enum types
003_shared_functions.sqlCommon trigger functions and schema version tracking
004_tenants.sqlTenant registry, default tenant, JWT signup trigger
005_workspace.sqlWorkspace settings, pipeline stages, field definitions
006_crm.sqlContacts, organizations, campaigns, templates, draft sets
007_gateways.sqlGateway registry, registration tokens, consume_gateway_token() RPC
008_agents.sqlAgent metadata, org chart, agent_reports_chain() RPC
009_interactions.sqlContact interaction timeline and sync triggers
010_tasks_streams.sqlStreams, tasks, recurring task series, and scheduling
011_comments.sqlPolymorphic comments with @-mention triggers
012_knowledge.sqlKnowledge items, chunks, semantic/full-text search RPCs
013_audit_notifications.sqlAudit log and notification tables
014_agent_inbox.sqlAgent inbox queue, lease RPCs, and task/comment triggers
015_agent_commands.sqlCommand queue and lifecycle RPCs
016_usage_budgets.sqlLLM usage logging, per-agent budgets, and enforcement
017_rls_realtime_storage.sqlStorage bucket setup
018_setup_wizard.sqlcomplete_setup() RPC for the first-run wizard
019_entity_links.sqlUniversal polymorphic entity linking
020_routines.sqlRoutines (scheduled and event-driven agent workflows)
021_collections.sqlCustom collections, fields, records, and views
022_file_processing.sqlFile processing pipeline for knowledge items
023_source_connections.sqlExternal source connections (Notion, Google Drive)
024_routines_extension.sqlEvent triggers for collections, knowledge, and tasks
025_modular_workspace.sqlModular workspace onboarding
026_secrets.sqlEncrypted secrets (AES-256-GCM), agent/gateway scoping, Realtime, source_connections.secret_id FK
027_plugins.sqlPlugin system: hq_plugins, hq_plugin_events, hq_plugin_state, hq_plugin_event_queue, event triggers, pg_cron cleanup
028_task_relations.sqlTask dependencies (task_relations), get_task_relations() RPC, notify_blocker_resolved trigger
029_labels.sqlManaged labels with color/description, task_labels junction table
030_task_templates.sqlReusable task group templates with dependency graphs (JSONB items)
031_overdue_escalation.sqlpg_cron job to mark overdue tasks missed, inbox notification for assigned agents
032_notification_gaps.sqlNotifications for deliverable submissions and overdue task events
033_knowledge_chunk_pipeline.sqlKnowledge chunk creation, embedding pipeline, and source item indexing fixes
034_crm_search_index.sqlFull-text search index on CRM contacts and organizations
035_interactions_nullable_contact.sqlAllow interactions without a linked contact
036_collection_agent_commands.sqlAgent commands for collection record operations
037_source_plugin_support.sqlExtended source connector plugin support

Migration CLI

The @yourhq/migrate package provides a CLI for applying schema migrations directly against Postgres (session mode, port 5432).
cd apps/migrate && npm install

npx yourhq-migrate --list
npx yourhq-migrate --dry-run --connection-string "postgres://postgres:[email protected]:5432/postgres"
npx yourhq-migrate --connection-string "postgres://postgres:[email protected]:5432/postgres"
npx yourhq-migrate --bundle > schema.sql
The runner tracks applied migrations in a _yourhq_migrations table (version, checksum, applied_at). It verifies checksums on already-applied migrations to detect drift. Each migration runs in a transaction — if one fails, it rolls back and stops. For Cloud Supabase users who can’t access port 5432, the onboarding wizard provides a “Copy SQL → Open SQL Editor” manual flow.

Applying migrations

Run every .sql file in order from the Supabase SQL Editor, or use the onboarding wizard which concatenates them into a single copy-paste blob.
Always include explicit GRANT statements for authenticated and service_role in any new migrations. Supabase does not grant these by default.