Welcome back

Sign in to your Fakebase account.

or

Don't have an account? Create one

CLI

Migrations

Create, check, and apply plain-SQL migrations with the Fakebase CLI.

View as markdown

Every schema change is a SQL file in your migrations/ folder. The files are the source of truth, and the database records which of them it has applied.

Create a migration

fakebase migrate create add_users

This creates a file like migrations/20261106_143000_add_users.sql. The timestamp keeps migrations in order. Write any SQL PostgreSQL accepts in it:

create table users (
  id bigint generated always as identity primary key,
  email text not null unique,
  created_at timestamptz not null default now()
);

Check before you apply

fakebase migrate validate

Checks your migration files for mistakes, like bad file names or two files with the same timestamp. With a database running, it also flags risky statements in pending migrations.

fakebase migrate diff

Runs pending migrations in a transaction that is rolled back, then shows the schema changes, anything risky, and errors with line numbers. Nothing is applied.

Apply migrations

fakebase migrate up

Shows the same preview as migrate diff, asks you to confirm, then applies each pending migration in order. Each migration runs in its own transaction, so a failing migration leaves nothing half-applied. Running it again with nothing pending does nothing.

Use --to with a migration ID to apply only up to that migration.

Destructive changes

Migrations that drop or truncate tables, delete rows, or change column types can lose data. migrate up refuses to apply them unless you add --allow-destructive:

fakebase migrate up --allow-destructive

--yes alone is never enough for these, so a script or agent can't lose data by accident.

See where you are

fakebase migrate status

Lists every migration with its state:

StateMeaning
appliedApplied to the database
pendingNot applied yet
modifiedThe file changed after it was applied. Later migrations are blocked.
missingApplied, but the file is gone. Later migrations are blocked.

Never edit or delete a migration that has been applied. Restore it from git and put the change in a new migration.

fakebase migrate history

Lists applied migrations, when they ran, and how long they took.

To open a single migration in Fakebase Studio, the desktop app, give its ID, its file name, or a unique part of the ID:

fakebase studio add_users

Drift

Drift is a change in the database that no migration describes, usually SQL someone ran by hand. migrate status, migrate up, and fakebase doctor warn you when they find it.

To keep the change, turn it into a migration:

fakebase migrate create keep_manual_changes --from-diff

This writes the change to a new migration file and records it as applied, because the database already has it.

Don't run migration files with psql or another database client. Fakebase can't see that they ran, so they stay pending and show up as drift. Use fakebase migrate up.

Import older migrations

Projects from the older Fakebase format have numbered files like 0001_create_users.sql and a meta/journal.json. Convert them to the current format with:

fakebase migrate import

It converts the files, updates the matching history in the database, and asks you to confirm first.

Add --help to any command for its flags.


Next steps