Deployment

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:

  1. Creates the schema_migrations table if it does not exist
  2. Lists all SQL files in src/db/migrations/ in alphabetical order
  3. For each file not yet recorded in schema_migrations, executes it in a transaction
  4. 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

MigrationDescription
001-schema-migrations.sqlBootstrap: schema_migrations tracking table
002-core-tables.sqlCore tables: users, workspaces, workspace_members, messages
003-sessions.sqlsessions table with workspace, surface, and status columns
004-memory.sqldaily_memory, user_profiles, user_notes, and procedural_memory tables (Tiers 2–5)
005-billing.sqlbilling_usage and cost_snapshots tables for token and cost tracking
006-webhooks.sqlwebhooks and webhook_deliveries tables
007-agent-infra.sqlaudit_log table for sensitive operation tracking
008-auth.sqlrefresh_tokens table for JWT rotation
009-agent-configs.sqlagent_configs table for database-managed agent definitions
010-memory-extensions.sqlExtends procedural_memory with type, trigger_pattern, steps, and tags columns
011-channel-routing.sqlchannel_routing table mapping channel + chat ID to a specific agent
012-knowledge-store.sqlknowledge_store table for the durable key-value knowledge base
013-advanced-features.sqlTables for swarm planner, approval workflows, quotas, debate, cloning, RAG, dream mode, deep research
014-team-features.sqlWorkspace-scoped memory, knowledge, codebase index, diagnostics, and cost tables
015-heartbeat.sqlheartbeat_configs and heartbeat_runs tables for the heartbeat daemon
016-workspace-files.sqlworkspace_files table for hot-reloaded context file tracking
017-tool-outputs.sqltool_outputs table for recording every tool call result per session
018-message-archive.sqlmessage_archive table for long-term message storage after compaction
019-workspace-graph-entities.sqlworkspace_graph_entities table for team-scoped knowledge graph nodes
020-tool-tasks.sqltool_tasks table for async tool dispatch and status polling
021-skill-metrics.sqlskill_metrics table for per-skill invocation and latency tracking
022-graph-confidence.sqlAdds confidence column to graph_entities with a low-confidence index
023-security-rbac.sqlCentralized security tables: audit trail, workspace_secrets, RBAC role assignments
024-memory-improvements.sqlembedding_cache table (SHA-256 keyed) and daily_memory workspace_id index
025-vector-indexes.sqlOptional IVFFlat indexes alongside existing HNSW indexes for large-scale deployments
026-session-webhook.sqlAdds webhook_url to sessions for per-session output delivery
027-scheduled-agents.sqlscheduled_agents table for DB-driven cron agent jobs
028-workspace-model-restrictions.sqlAdds allowed_providers and allowed_models columns to workspaces
029-workspace-agent-grants.sqlworkspace_agent_grants table for cross-workspace agent sharing
030-fix-secrets-schema.sqlSchema reconciliation for DBs that ran the superseded 023-secrets.sql; idempotent column additions and fixes
031-agent-traces.sqlagent_traces table for the trace viewer (per-session, per-agent trace records)
032-job-queue.sqljob_queue table for long-running background jobs
033-agent-versions.sqlagent_config_versions table for config version history with rollback support
034-memory-profiles.sqlmemory_profiles and agent_memory_profiles tables for configurable memory behaviors per agent
035-linear-channel.sqllinear_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.sql
sql
-- 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.