This page covers the database migration system used in Sim, which manages schema evolution for the PostgreSQL database using Drizzle ORM. Database migrations ensure that schema changes are applied consistently across all deployment environments, from local development to production clusters.
Sim uses Drizzle ORM for database schema management and migrations. The migration system handles:
pgTable definitions packages/db/schema.ts32-180Sources: packages/db/migrations/meta/_journal.json1-20 packages/db/schema.ts1-20
Description: Migration execution workflow. The drizzle-kit utility compares the current state of schema.ts against the migration journal to ensure the physical database matches the code definitions.
Sources: packages/db/schema.ts1-180 packages/db/migrations/meta/_journal.json1-315
Sim maintains a rigorous history of schema changes in the _journal.json file. Each migration is tagged with a unique identifier and a timestamp to ensure linear progression.
The journal tracks every incremental change to the database:
| Index | Tag | Version | When (Timestamp) |
|---|---|---|---|
| 0 | 0000_careless_black_knight | 7 | 1739697832964 |
| 1 | 0001_foamy_dakota_north | 7 | 1739773751302 |
| ... | ... | ... | ... |
| 44 | 0044_uneven_killer_shrike | 7 | 1750369626350 |
Sources: packages/db/migrations/meta/_journal.json4-312
The migration system evolves several critical entities defined in the Drizzle schema.
Description: Association between high-level system concepts and their underlying Drizzle ORM table definitions.
| Code Entity | File Path | Role |
|---|---|---|
user | packages/db/schema.ts32 | Core user profile, email verification, and RBAC roles |
session | packages/db/schema.ts48 | Active user sessions, tokens, and organization context |
workflow | packages/db/schema.ts144 | Workflow metadata, deployment status, and variable definitions |
workflowBlocks | packages/db/schema.ts180 | Canvas elements, logic configuration, and execution outputs |
account | packages/db/schema.ts72 | OAuth connections, access/refresh tokens, and provider IDs |
Sources: packages/db/schema.ts32-205
| Command | Description |
|---|---|
bunx drizzle-kit generate | Compares packages/db/schema.ts against the latest migration in _journal.json and generates a new SQL file. |
bunx drizzle-kit migrate | Executes pending SQL migrations against the target database. |
The migration system supports specialized PostgreSQL types required for the platform's advanced features:
vector type packages/db/schema.ts19-20subBlocks and outputs packages/db/schema.ts202-203Sources: packages/db/schema.ts19-30 packages/db/schema.ts202-203
Migrations directly impact how the API layer queries data. For example, the LogsAPI performs complex joins across tables managed by the migration system to provide execution history.
Description: The LogsAPI apps/sim/app/api/logs/route.ts124-135 relies on the relational integrity established by migrations between execution logs, workflows, and deployment versions.
Sources: apps/sim/app/api/logs/route.ts124-143 packages/db/schema.ts144-177
packages/db/schema.ts.bunx drizzle-kit generate. This adds a new entry to _journal.json packages/db/migrations/meta/_journal.json309-311bun run db:migrate to update your local PostgreSQL instance.Sources: packages/db/schema.ts1-205 packages/db/migrations/meta/_journal.json1-315
Refresh this wiki