Guides

Migrations

Opt in to plain SQL migration files in robodev/migrations/ instead of the automatic schema sync.

By default Robodev syncs robodev/database.ts to the database on every deploy (see Database). That stays the default, for new and existing projects alike, with the same confirmation for destructive changes. If you would rather review the SQL, run data changes in the same step, or keep every schema change in git, turn migrations on for a project. Nothing changes for a project that never does.

Enable

Run robodev migrations enable in the project folder, or use Settings → General → Database migrations in the dashboard (project admins). The CLI asks first and has --yes for scripts:

terminal

robodev migrations enable
# Migrations are one-way. Auto-sync turns off for good. Continue? (y/N)
  • It is one-way. There is no command or button to switch it off.
  • The live schema must already match robodev/database.ts. If it does not, enabling stops and asks you to deploy first, so the baseline is exactly your code.
  • Starbase writes the current schema as plain SQL, robodev/migrations/0000_baseline.sql (a -- robodev:baseline header and the date), and records it as already applied. Nothing runs against your data.
  • The CLI saves the baseline file for you to commit. If you enabled it in the dashboard, run robodev migrations pull once to download it.

Day to day

Edit robodev/database.ts as you do today, then generate the next file. It is ordinary, editable SQL (the same style as drizzle migrations):

terminal

robodev migrations generate add_orders
# Wrote robodev/migrations/0003_add_orders.sql

robodev/migrations/0003_add_orders.sql

CREATE TABLE "orders" (
  "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  "total" integer DEFAULT 0
);

-- Data changes are just more SQL in the same file.
INSERT INTO "orders" ("total") VALUES (0);
  • Review and edit the file, commit it, and deploy. A deploy applies the files that are not applied yet, in order, each in its own transaction.
  • robodev migrations generate <name> --empty writes a stub for SQL you write yourself: a data change, or a rename (a rename cannot be told from a drop plus an add, so it is never generated).
  • Never edit a file that was applied; add a new one. A deploy that changes, removes or renames an applied file is refused, and so is a new file that sorts before the last applied one.
  • Files are named NNNN_name.sql with no gaps. Two branches that both add 0004 need one renumbered before merging.
  • Do not put BEGIN or COMMIT in a file. Each file already runs in one transaction, so a file that fails changes nothing.
  • Commands work from any folder of the project; they find robodev/ by walking up.

Concurrent indexes and VACUUM

CREATE INDEX CONCURRENTLY, DROP INDEX CONCURRENTLY, REINDEX … CONCURRENTLY, VACUUM, CREATE or DROP DATABASE and ALTER SYSTEM cannot run inside a transaction, so check and deploy refuse them with a message naming this line. Put it first in the file to run it outside one:

robodev/migrations/0005_orders_idx.sql

-- robodev:no-transaction
CREATE INDEX CONCURRENTLY "orders_created_idx" ON "orders" ("created_at");

Such a file runs statement by statement and is recorded after the last one succeeds. Its statements get a longer limit than other files (30 minutes instead of 60 s, the self-hosted server's ROBODEV_MIGRATION_NO_TRANSACTION_TIMEOUT), so a long index build is not cut off but a runaway statement cannot hold the deploy forever. If a statement fails part-way, the earlier ones stay applied and the file is not recorded, so write it to run again and deploy again. A CREATE INDEX CONCURRENTLY that fails leaves an invalid index behind, which IF NOT EXISTS would then skip: drop it first (DROP INDEX CONCURRENTLY IF EXISTS …, in the same file) before building it again.

Destructive statements

robodev migrations generate is where a change that can lose data is confirmed. When the file it would write drops a table or a column, changes a column type or otherwise loses data, it lists those statements (marked !) and asks before writing the file; without a terminal (CI, scripts) it writes nothing unless you pass --allow-destructive. robodev deploy, CI and dashboard deploys do not look for destructive statements: a migration file in git is your own SQL, and it runs as written. Agent publishes are the exception, because no generate asked: over MCP (publish_backend_file, publish_backend_files) or POST /v1/projects/:id/deploy/backend, a new migration file that drops a table, column, schema or type, changes a column type, truncates, or updates or deletes every row is refused with destructive_migration and the statements listed, until it is published again with force: true after the human confirms. Files that still start with the old -- robodev:allow-destructive line are fine; it is only a comment now.

terminal

robodev migrations generate drop_legacy_note
#   ! ALTER TABLE "orders" DROP COLUMN "legacy_note";
# This migration can lose data (the lines marked !). Write it? (y/N)

Check

robodev migrations check is for you, your CI and robodev deploy (which runs it before uploading, then prints ✓ Migrations match robodev/database.ts). It fails, with a non-zero exit, when the files are not numbered in order, a file has BEGIN or COMMIT or needs -- robodev:no-transaction, a file does not apply, or database.ts declares something no migration file creates. Indexes, constraints or tables the files create beyond database.ts (a hand-written index, say) are a warning, not a failure:

terminal

robodev migrations check
# ✗ robodev/database.ts has changes with no migration file: add_column orders.total. Run robodev migrations generate <name>.

check and generate build a throwaway Postgres (the same embedded one robodev dev uses), apply every file to it, and compare the result with database.ts. Both work offline. On a CI runner without the embedded binary, pass --database-url <url> (or set ROBODEV_MIGRATIONS_DATABASE_URL) to a Postgres the command may create and drop databases on, for example a service container. That server must be a throwaway: your migration SQL runs on it as its superuser (as it does in the embedded Postgres), so never point it at a shared or production database.

CI

GitHub Actions

- uses: actions/setup-node@v4
  with:
    node-version: 22
- run: npm i -g robodev
- run: robodev migrations check   # every pull request
- run: robodev deploy              # on the deploy branch
  env:
    ROBODEV_DEPLOY_KEY: ${{ secrets.ROBODEV_DEPLOY_KEY }}

What a deploy does

  • database.ts is not pushed. The schema changes only through the files.
  • Your SQL runs as your project's own database role, on its own connection, never as the platform's admin role. It can create and alter your tables but not create roles, run COPY … PROGRAM, read server files, or touch the robodev_migrations schema. CREATE EXTENSION works only for extensions Postgres marks trusted.
  • If a deploy has no robodev/migrations/0000_baseline.sql (a branch from before you enabled migrations, an environment's first deploy, an agent publish over MCP), Starbase supplies the stored baseline, so a new environment never deploys onto an empty database. A baseline that differs from the stored one is refused.
  • The files already applied (recorded with a sha256 each in a reserved robodev_migrations schema your app role cannot touch) must be unchanged and none removed. New files must come after the last applied one.
  • The pending files run in order under the project's deploy lock. A file that fails is rolled back, the deploy stops, and the version that was serving keeps serving. Files before it stay applied. Starbase keeps the files a failed deploy applied, so an agent publish (which starts from the live deployment) still sends them; your next robodev deploy must include them too. The file name and the Postgres error appear in the deploy log, robodev migrations status and Settings → General. A deploy that is refused before any file runs (an applied file edited or missing, BEGIN or COMMIT in a file, a numbering gap, a missing baseline) shows there too, with the file when there is one.
  • Before the first migration runs, the tables, views, sequences and enum types in public are handed to that role, so a migration can ALTER tables auto-sync created. That role is also the one your app connects as, so from then on your app's database login owns its tables: app code (or a SQL injection) could DROP, ALTER or TRUNCATE them, not only read and write rows. Switching migrations off does not hand them back.
  • Table privileges are re-applied afterwards, as for a push.
  • Environments follow the project: a new environment or preview of a project with migrations on applies the files too (a preview starts from its source's applied list and gets its own tracking schema, not a copy of the source's). Environments that existed before you enabled migrations keep auto-sync: their Settings page says so and has no Enable button, because migrations are switched on for the whole project from production.
  • Before any file runs on your database, every migration file runs on a new empty database on the same server (as your project role), and database.ts is compared with the result. A file that does not apply there, or a table, column, type, default or index that database.ts declares and no file creates, refuses the deploy with nothing applied, and shows in Settings → General. Indexes, constraints and tables the migrations make beyond database.ts are listed in the deploy log, not refused. Deploy with --force (or force: true over MCP) to go on without the file; the deploy log then warns and database.ts is still not pushed. A frontend-only publish (publish_frontend_files) cannot add a migration file, so it only warns.
  • Each file gets a lock timeout of 10 s and a statement timeout of 60 s (the self-hosted server's ROBODEV_MIGRATION_LOCK_TIMEOUT and ROBODEV_MIGRATION_STATEMENT_TIMEOUT, in milliseconds; 0 turns one off). A migration that waits longer for a lock than that (a long query or an open transaction in your app holding the table) fails with a message saying so, and the deploy stops with the old version still serving. Files marked -- robodev:no-transaction get 30 minutes per statement instead (ROBODEV_MIGRATION_NO_TRANSACTION_TIMEOUT); in the dry run before a deploy, on an empty database, they get the normal 60 s. A file can raise its own limits with SET (SET statement_timeout = 0 for one long statement you expect); otherwise keep long backfills in batches.
  • Every file runs on its own database connection, so a SET in one file never carries over to the next.
  • The robodev_migrations schema is Robodev's own. If it was created by the app before migrations were enabled, enabling and deploying are refused with migrations_tracking_unsafe instead of trusting it; a platform admin has to remove it. Restoring a backup of a project with migrations on gives a copy with migrations on: the applied list is read from the restored database and written into a fresh robodev_migrations schema, and the redeploy after the restore applies files instead of pushing database.ts.
  • A platform admin can switch migrations off again after a mistaken enable (POST /v1/admin/projects/:id/migrations/disable, audited). On production it switches off every environment and preview that follows it too; on one environment, only that environment. Auto-sync resumes on the next deploy; the migration files and the robodev_migrations record are left in place, and enabling again starts from a fresh baseline. That first auto-sync deploy drops indexes and constraints that migrations created but database.ts does not declare, without asking for --force.
  • Each environment keeps its own list of applied files. If a branch deployed to a long-lived environment (staging, say) applied 0005_a.sql and the deploy branch later gets a different 0005_b.sql, every later deploy to that environment is refused (an applied file is missing). Keep migration files on one line: merge or rebase before deploying a branch with new files to a shared environment, and renumber before merging. An environment that is already stuck can be recreated, or a platform admin can switch migrations off for that environment alone.

Status

terminal

robodev migrations status
#   0000_baseline.sql  applied  2026-11-26T10:00:00.000Z
#   0001_add_orders.sql  pending

robodev dev

robodev dev prints which mode it runs in: Database: migrations (robodev/migrations) or Database: auto-sync. For a linked project it asks Starbase (2.5 s timeout) whether migrations are on, and falls back to the local files when it is offline, signed out or unlinked, saying so. Without an answer from Starbase only a robodev/migrations/0000_baseline.sql that starts with -- robodev:baseline turns migrations on, so stray .sql files (drizzle-kit output) never silently switch auto-sync off. When migrations are on, robodev dev applies the files to the local database (as your local superuser) and records them in the same table. It warns when database.ts has changes no file covers. A local database that auto-sync built before you enabled migrations adopts the baseline without running it. If you edit a file that was already applied locally, delete .robodev/dev/pg to rebuild it.

Coding agents

If the project has migrations on (robodev migrations status, or get_migrations over MCP), after editing robodev/database.ts run robodev migrations generate <name>, read the SQL, then robodev migrations check. Never edit a migration file that has been applied or committed to the deploy branch. Without a terminal there is no generate or check: call the get_migrations MCP tool (state, applied files, last failure, baseline SQL), write the next robodev/migrations/NNNN_name.sql yourself, and publish it with database.ts; Starbase validates numbering, applied files and the baseline on publish, and get_migrations shows why a publish was refused. Without generate, Starbase asks instead: a new file that can lose data is refused until it is published again with force: true, which an agent passes only after the human confirms. The bundled database-migrations skill (robodev skills install database-migrations) teaches the same.