Database Migrations
Open Astra manages its schema through numbered SQL migration files in src/db/migrations/. Migrations run automatically at gateway startup in alphabetical order and are tracked in the schema_migrations table. Each migration runs exactly once.
Automatic execution
At startup, the gateway calls runMigrations() which:
- Creates the
schema_migrationstable if it does not exist - Lists all SQL files in
src/db/migrations/in alphabetical order - For each file not yet recorded in
schema_migrations, executes it in a transaction - Records the filename and execution timestamp in
schema_migrations
Migrations are idempotent by design — re-running them is safe because each is only applied once. All migrations use existence guards (IF NOT EXISTS, IF EXISTS checks via pg_class) for PG17 compatibility.
All 35 migrations
| Migration | Description |
|---|---|
001-schema-migrations.sql | Bootstrap: schema_migrations tracking table |
002-core-tables.sql | Core tables: users, workspaces, workspace_members, messages |
003-sessions.sql | sessions table with workspace, surface, and status columns |
004-memory.sql | daily_memory, user_profiles, user_notes, and procedural_memory tables (Tiers 2–5) |
005-billing.sql | billing_usage and cost_snapshots tables for token and cost tracking |
006-webhooks.sql | webhooks and webhook_deliveries tables |
007-agent-infra.sql | audit_log table for sensitive operation tracking |
008-auth.sql | refresh_tokens table for JWT rotation |
009-agent-configs.sql | agent_configs table for database-managed agent definitions |
010-memory-extensions.sql | Extends procedural_memory with type, trigger_pattern, steps, and tags columns |
011-channel-routing.sql | channel_routing table mapping channel + chat ID to a specific agent |
012-knowledge-store.sql | knowledge_store table for the durable key-value knowledge base |
013-advanced-features.sql | Tables for swarm planner, approval workflows, quotas, debate, cloning, RAG, dream mode, deep research |
014-team-features.sql | Workspace-scoped memory, knowledge, codebase index, diagnostics, and cost tables |
015-heartbeat.sql | heartbeat_configs and heartbeat_runs tables for the heartbeat daemon |
016-workspace-files.sql | workspace_files table for hot-reloaded context file tracking |
017-tool-outputs.sql | tool_outputs table for recording every tool call result per session |
018-message-archive.sql | message_archive table for long-term message storage after compaction |
019-workspace-graph-entities.sql | workspace_graph_entities table for team-scoped knowledge graph nodes |
020-tool-tasks.sql | tool_tasks table for async tool dispatch and status polling |
021-skill-metrics.sql | skill_metrics table for per-skill invocation and latency tracking |
022-graph-confidence.sql | Adds confidence column to graph_entities with a low-confidence index |
023-security-rbac.sql | Centralized security tables: audit trail, workspace_secrets, RBAC role assignments |
024-memory-improvements.sql | embedding_cache table (SHA-256 keyed) and daily_memory workspace_id index |
025-vector-indexes.sql | Optional IVFFlat indexes alongside existing HNSW indexes for large-scale deployments |
026-session-webhook.sql | Adds webhook_url to sessions for per-session output delivery |
027-scheduled-agents.sql | scheduled_agents table for DB-driven cron agent jobs |
028-workspace-model-restrictions.sql | Adds allowed_providers and allowed_models columns to workspaces |
029-workspace-agent-grants.sql | workspace_agent_grants table for cross-workspace agent sharing |
030-fix-secrets-schema.sql | Schema reconciliation for DBs that ran the superseded 023-secrets.sql; idempotent column additions and fixes |
031-agent-traces.sql | agent_traces table for the trace viewer (per-session, per-agent trace records) |
032-job-queue.sql | job_queue table for long-running background jobs |
033-agent-versions.sql | agent_config_versions table for config version history with rollback support |
034-memory-profiles.sql | memory_profiles and agent_memory_profiles tables for configurable memory behaviors per agent |
035-linear-channel.sql | linear_label_agent_mappings and linear_webhook_events tables for the Linear channel |
Adding a new migration
Create a new SQL file with the next sequential number:
bash
# Next migration is 031
touch src/db/migrations/031-my-feature.sqlsql
-- src/db/migrations/017-my-feature.sql
CREATE TABLE IF NOT EXISTS my_table (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
workspace_id UUID NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
data JSONB NOT NULL DEFAULT '{}',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX my_table_workspace_idx ON my_table(workspace_id);The migration runs automatically the next time the gateway starts.
⚠Migrations are run in a transaction but are not reversible — there is no down-migration system. Always test migrations on a staging environment before applying to production.