On a live database, a Supabase rollback is a new forward migration that reverses the change. supabase migration down runs no reverse script: it drops the target’s user schemas and data, then rebuilds from local files. Locally, supabase db reset --last 1 takes back the last migration. Deleted or overwritten rows come back only from a backup or point-in-time restore.

Supabase rollback: four ways back from a bad migration, and what each one reverses

Supabase rollback takes one of four paths: a transaction rollback before commit, a new forward migration after it, a reset on a local or preview database, and a backup or point-in-time restore when rows are gone. Only the restore brings back deleted data, and an in-place restore also discards every write made after its recovery point.

A Supabase rollback migration is one more file in supabase/migrations, named on the <timestamp>_<name>.sql pattern the CLI requires; neither the CLI reference nor the migrations guide describes a down file to pair with it. Which schema changes belong in ordered, committed files at all is covered by the database migration checklist; this page starts from the moment one of those files has gone wrong.

Way backWhat it reversesWhat it cannot reverseWhere it is safe
Transaction rollbackEvery update the current, uncommitted transaction madeAnything already committed, including an earlier migrationAnywhere, but only before COMMIT
Forward correction (a new migration)The schema change, applied as new SQL from the current stateValues the database no longer holdsThe default on a live database
supabase db reset or supabase migration downThe whole schema, rebuilt from local migration files and the seedData on the target: its user-created schemas and data are droppedA local database or a project you can throw away
Backup or point-in-time restoreThe whole database, back to a recovery pointWrites made after that point, and Storage objectsProduction, with downtime: the project is inaccessible during an in-place restore

Our default reading of that table: fix forward on a live database, restore only when information is gone, and reset only where nothing real lives.

What to do in the first minutes after a migration fails

A failed migration needs a state check before any second command: stop the release job, save the error, compare supabase migration list --linked with the files in the repository, and read the real schema and a few rows. Whether to roll back, fix forward or restore comes from what that check shows.

  1. 01 Stop automated retries and any second deploy that carries another migration, so nothing new runs against the database while you look.
  2. 02 Save the CLI output, the migration file, the app commit, the time it ran and the exact database target. Keep them in one note.
  3. 03 Run supabase migration list --linked against the project you meant to change and compare the local and remote versions. Keep the output.
  4. 04 Read the real schema and a few affected rows. A history entry proves the runner recorded a version, not that the app works.
  5. 05 Keep or redeploy an app version that works with the schema that is actually there, not the one the migration intended.
  6. 06 Pick transaction rollback, a forward fix or a restore from what steps 3 and 4 showed, and try the pick on a staging copy first.

When the migration dropped every table rather than one column, the first hour looks different; that case is covered under when the production database is deleted.

If the migration has committed on a database with paying customers and nobody on the team can yet say which of the four paths applies, that is the point to bring in outside help: on a free audit, AxonBuild weighs up with you which way back is safe for the data you hold, before anyone runs a second command. In the Production Hardening Sprint, documenting and rehearsing release rollback, including how database changes are handled safely, is one of the 123 deliverables.

What goes wrong without these controls

Each of the four failures below is the one a control further down prevents.

Among the 21 third-party apps we audited in June and July 2026, one medical app with real patient records had no staging environment: changes were tried against the production database, the schema was a drop-then-create script, and each deploy pruned the single image tag, leaving nothing to roll back to. Those 21 apps were chosen for audit rather than drawn at random, so this is one app’s story and says nothing about how common it is.

These controls sit inside the release path one app can trust, next to the other release controls a small team runs.

Running supabase migration down on a live project deletes its data

supabase migration down does not look for a reverse script. Supabase’s CLI side-effects note for the command says it drops every user schema and object on the target, then reapplies the local migrations up to the chosen version plus the seed files. Before it runs, the CLI asks “Do you want to revert the following migrations?” with a warning line and a default of no; --yes skips the question. The flags decide which database loses its data, as the CLI reference for migration down lists them:

FlagWhat it targets
--localThe local database, the default
--linkedThe linked project, which is production if production is what the folder is linked to
--db-urlWhatever database the connection string points at
--last <n>How many applied versions to reset, 1 by default

A discussion in Supabase’s GitHub organization is titled “Lost entire database after running migration down --last 1 command” (#43997). supabase db reset --linked and --db-url are no gentler: the reference says a SQL script finds and drops all user-created entities in the remote database. Before typing any of them, read supabase/.temp/project-ref, the file the CLI uses to find the linked project, and match that ref against supabase projects list, which lists every project your login can reach.

Create index concurrently fails inside a Supabase migration transaction

PostgreSQL lets a plain CREATE INDEX run inside a transaction block, but not CREATE INDEX CONCURRENTLY, as PostgreSQL’s CREATE INDEX reference states. The Supabase CLI’s migration up and migration down apply each migration file inside BEGIN and COMMIT, where that statement cannot run (SQLSTATE 25001), so on some older CLI versions a create index concurrently statement in a Supabase migration fails inside that transaction. An issue on the CLI repository (#5139) reproduced that failure on v2.92.1 and v2.95.3 with the statement alone in its own file. The CLI’s v2.109.0 release notes, dated June 30, 2026, say migration up and migration down now handle CREATE INDEX CONCURRENTLY without failing, by running such a statement on its own; the notes name no other command, such as db push or db reset. So check the CLI version first; on v2.109.0 or later, keep the statement alone in its own migration file:

-- supabase migration new add_orders_user_idx
-- <timestamp>_add_orders_user_idx.sql holds this one statement:
create index concurrently if not exists orders_user_id_idx on public.orders (user_id);

A concurrent build that fails part way leaves an index marked invalid; PostgreSQL’s advice is to drop it and run CREATE INDEX CONCURRENTLY again.

The migration history no longer matches your files

When supabase db push stops with an error that tells you to run supabase migration repair, the history table on the remote project and your supabase/migrations folder disagree. It can happen when SQL runs in the dashboard’s SQL editor or Table Editor, which bypasses the history, when a migration file never gets committed, or when an AI tool runs SQL straight against the remote project. The Supabase CLI’s migration repair command takes --status applied or --status reverted with a version and changes the history table in one direction each:

CommandWhat it does to the history table
supabase migration repair --status applied <version>Inserts a record for the version, without running its SQL
supabase migration repair --status reverted <version>Deletes the record for the version, without undoing its SQL

Supabase’s database migrations guide says repair “updates the tracking table only” and is for when you know the real database state is correct. So read the schema first. Marking a half-run migration as reverted to make the history look clean only sets up the same SQL to run again on the next push. If the remote holds changes your files lack, supabase db pull writes the remote schema into a new file under supabase/migrations.

Rolling back the app in Lovable, Bolt or Replit leaves the database as it is

A builder or host rollback changes the code that runs and leaves the schema and rows where the migration left them. Lovable’s version history docs say reverting restores code only and redeploys edge functions to match; records, data changes or migrations made after that version are not undone. Bolt’s version history restores project files but does not restore Bolt Database or connected Supabase data. On Replit, “By default, rollbacks do not change your database.” So the older build works only if it still fits the schema that is there now. Rolling back the deploy itself is covered in roll back the deployment on Vercel or Netlify, and a revert that will not take in when a Lovable revert does not work.

How to set them up: forward fixes, local resets, safe releases and a recovery point

We would add them in this order: committed migrations, migrations wired into the deploy, a rehearsed way back, and a backup you have restored at least once.

Write the reverse as a new forward migration

Name the reverse after the file it undoes: supabase migration new revert_add_comments gives a <timestamp>_revert_add_comments.sql file. Say an AI builder added a comments table with an index, an updated-at trigger and two RLS policies in one migration; the reverse drops that whole set with if exists guards. drop table already removes the table’s own indexes, triggers and constraints, but a trigger function lives outside the table and survives, so drop it last.

-- <timestamp>_revert_add_comments.sql
drop policy if exists "comments_insert_own" on public.comments;
drop policy if exists "comments_select_own" on public.comments;
drop table if exists public.comments;  -- also drops its indexes and triggers
drop function if exists public.comments_set_updated_at();

Dropping the table also drops every row users wrote since the deploy, so if real people already used the feature, leave the table and fix the app instead. Rather than writing the SQL from memory, supabase db diff with -f <name> can save the difference between your files and the database as a new migration file. Read every line, run supabase db push --dry-run to print what would be applied, then supabase db push. Picture a migration that renamed full_name to display_name: renaming it straight back breaks the build that is live now, which reads display_name. The compatible correction adds full_name back, copies the values across and lets the code move first.

Undo a migration locally or on a preview branch with supabase db reset

supabase db reset recreates the local database, applies every file in supabase/migrations and then seeds from supabase/seed.sql if it exists.

supabase db reset            # rebuild from supabase/migrations, then seed.sql
supabase db reset --last 1   # reset only the last migration version
supabase migration up --local  # apply pending migrations to the local database

On a preview branch, Supabase’s branching troubleshooting guide says to push the corrected migrations, then delete the branch and reopen it; the new branch is a fresh clone of the base project, reseeded from seed.sql by default, and data changes on the old branch are lost. A reset from the dashboard instead reruns all migrations in order and drops the branch’s data. A local database or a branch is rebuilt from files, so a reset costs nothing there and everything on production.

How transaction rollback differs from migration rollback

Transaction rollback discards the statements of the current transaction before it commits; migration rollback reverses a change that already committed. A Postgres ROLLBACK cannot reach a committed migration, and some commands, such as CREATE INDEX CONCURRENTLY, cannot run inside a transaction block at all.

Three boundaries decide which one you are dealing with:

  • A failure before COMMIT leaves nothing behind: the ROLLBACK reference says every update the transaction made is discarded, and the CLI’s migration up and migration down record a migration in its history only after every statement succeeds.
  • A commit ends that safety net. From then on, only a new migration or a restore changes the result.
  • Statements that run outside the transaction, like a concurrent index build, need their own cleanup when they fail.

A migration that reverses cleanly can still block the app while it runs. ALTER TABLE’s lock notes say an ACCESS EXCLUSIVE lock is taken unless a subform says otherwise. Grouping several writes from app code into one unit is a separate job, covered in wrapping several writes in one transaction. We would not wrap a generated migration file in your own BEGIN and COMMIT without trying it on staging first.

Which migration tools reverse a change, and how

Migration tools fall into three groups: those that run a down step stored with the migration, those that compute a reverse plan, and forward-only tools where the reverse is a new migration.

ToolHow it reversesWhat you run
Supabase CLIForward-only; migration down drops the target’s schemas and rebuildsA new migration; supabase migration down only on a local or throwaway database
Prisma MigrateGenerates a down SQL file by diffing, for a failed migrationprisma migrate diff, prisma db execute, then prisma migrate resolve
Drizzle KitNo down or rollback command among its commandsA new migration from drizzle-kit generate
AtlasComputes a down plan from the current databaseatlas migrate down
FlywayRuns undo scripts you write, prefixed U by default, in the Teams editionThe undo command
LiquibaseCan generate rollback for XML, YAML and JSON changelogs; you write it for formatted SQL changelogsrollback, rollback-count or rollback-to-date
Rails Active RecordReverts a change method or runs the down methodbin/rails db:rollback, with STEP=3 for several
DjangoCan reverse back to the migration you name; raises IrreversibleError when an operation cannot be reversedpython manage.py migrate <app> <migration>
EF CoreRuns the Down operations of every migration newer than the targetdotnet ef database update <PreviousMigration>

Rails is the clearest case of a stored down step: the Rails migrations guide says bin/rails db:rollback reverts the latest migration and bin/rails db:migrate runs pending ones again. Django’s migrations docs reverse to a named migration the same way. In EF Core, a rollback migration is an update to an earlier target, and EF Core’s migration docs warn it may result in data loss. Atlas migrate down plans the reverse from the database as it is now, while Flyway undo migrations assume the whole migration succeeded before they undo it. Liquibase rollback works by tag, date or a count of changesets, and Drizzle Kit’s commands stop at generate, migrate, push, pull, check, up, studio and export.

Prisma’s down migrations revert the schema but not data changed during the up migration, and Rails lets a migration that might destroy some data refuse to run backwards. So no stored script makes a schema rollback bring back values the database no longer holds. Which tool to adopt in the first place is a question for the database migration checklist.

Expand and contract: the release order that makes rollback rare

Expand, backfill, contract: three phases that let a schema change ship without a moment where the live code and the schema disagree. Prisma’s expand-and-contract guide describes the same idea: add the new column and copy the data across, then remove the old column once nothing reads it.

  1. 01 Expand: add the new column or table in a forward migration, leaving the old one in place.
  2. 02 Deploy code that writes to both and reads the new one with a fallback to the old.
  3. 03 Backfill in small, retryable batches rather than one long update.
  4. 04 Verify counts and totals between old and new before anything depends on the new one.
  5. 05 Switch reads and writes to the new column or table.
  6. 06 Contract: drop the old column in a later release, after the rollback window has closed.

Each step is a forward migration, so the way back at any point is the previous app version, not a schema rewind. On a large table, set lock_timeout before the DDL; Postgres then aborts a statement that waits longer than that for a lock, and the default of zero means no limit. We would set it to a few seconds, so a blocked migration fails quickly and you retry later. Which deploy runs each step is set out in how to run database migrations on deploy.

Check the recovery point before a destructive migration

A migration that drops a column or table, overwrites values or merges rows destroys information, and recreating the column does not bring the values back. So before it runs, name the recovery point and confirm it exists. Supabase’s Free plan has no automated backups and the docs recommend exporting your data with the CLI yourself; Pro keeps 7 days of daily backups, Team 14 days and Enterprise up to 30; point-in-time recovery is a paid add-on on Pro, Team and Enterprise. Database backups exclude objects stored through the Storage API. Restore to a New Project needs physical backups and creates a database-only copy, which lets you compare lost rows while the live project keeps running. What each plan keeps, and how to prove a restore works, is in what each Supabase plan’s backups keep; bringing back only some rows is in getting deleted rows back in Postgres. A restore also loses every write after its point. In our reading, the harder part sits outside the database: payments taken and emails sent after that point still happened, and the restored rows no longer record them.

How to verify each one: rehearse the way back before you need it

Rollback readiness is proven by four runs you can repeat: the migration files build a clean database that matches production, a test schema change deploys in the right order, a test release rolls back with its data intact, and a backup restores into an isolated copy.

  1. 01 Apply the migration files to a clean test database and compare the resulting schema with production. Keep the diff output.
  2. 02 Deploy a representative schema change through the pipeline and confirm it runs before the code that needs it and stops the release when it fails. Keep the pipeline log.
  3. 03 Roll back a test release and check that the app still works and the data written before the rollback is still there. Keep the times and a row count.
  4. 04 Restore a backup into an isolated environment and check representative rows. Keep the counts and how long the restore took.

The place to run all four is a separate project, set up as a Supabase staging environment. The written page these checks feed, who rolls back and how, is what a rollback plan holds.

In the Production Hardening Sprint, deliverable 7.6 is verified this way: roll back a test release and verify application behavior and retained data. Deliverable 4.7 is verified by restoring a backup into an isolated environment and checking representative data integrity. The checks for 4.6 and 7.5 are the first two steps of the list above.

Where the sprint does this

Our engineers move schema changes into ordered migrations committed to the repository, integrate those migrations into the deployment process with ordering and compatibility checks, document and rehearse release rollback including how database changes are handled safely, and verify automated backups, set retention and perform a real restore test. Hosting, paid tools and API usage are paid through your accounts, so a point-in-time recovery add-on stays on your own Supabase bill. None of it promises that every migration can be undone; it means the way back is known and practiced before a release runs.

Common questions about undoing a schema change

How to rollback a migration?

Run the tool’s reverse command only on a database you can rebuild, and write a new forward migration on one that holds real data. Rails (bin/rails db:rollback), Django (migrate <app> <migration>) and EF Core (dotnet ef database update <PreviousMigration>) can reverse stored or generated steps, while the Supabase CLI and Drizzle Kit offer no reverse command that keeps your data, and Prisma generates a down file only to recover a failed migration.

What is the difference between COMMIT and ROLLBACK in SQL?

COMMIT makes the current transaction’s changes visible to other sessions and durable if the server crashes; ROLLBACK discards every update the transaction made. After a commit there is nothing left for ROLLBACK to discard, which is why a committed migration needs a new migration, or a restore, to undo it.

Which is better, Flyway or Liquibase?

Neither is better for every team; for rollback, the difference is who writes the reverse step. Flyway runs undo scripts you write, with a U prefix by default, in its Teams edition, while Liquibase can build the reverse itself for modeled changelogs (XML, YAML or JSON) and leaves you to write it in a formatted SQL changelog. This comparison comes from each tool’s documentation, not from running both.

When should I get help with a failed Supabase migration?

Get help once a failed migration has committed on a database with customer data and nobody can yet say whether it destroyed information, because the wrong first command can turn a fixable schema problem into lost rows. AxonBuild goes over the failed migration with you on a free audit, so the next command you run is one that keeps your rows.