November 22, 2026 · 8 min read · Thomas Osayi
How to change your Supabase database safely with migrations
How to change a live Supabase schema without breaking your app: backups first, migrations with the Supabase CLI, a staging project, safe change patterns and RLS checks.
Changing a database that real people are using is the moment most AI-built apps go wrong. Someone renames a column in the Supabase dashboard, the app keeps asking for the old name, and every page that depends on it breaks. Or a new table goes live with no row level security, and anyone with the public key can read it.
None of this is hard to avoid. It takes a habit: every change goes into a migration file, gets tested somewhere that is not production, and gets checked for security before it ships. Here is the workflow I use, with the actual commands from the Supabase CLI documentation.
Why can't I just edit tables in the Supabase dashboard?
You can, but every edit made directly on production is invisible to your migration history, so you lose the ability to repeat, review or undo changes.
Supabase's own migration guide warns that making schema changes on the remote database through the SQL editor or Table Editor bypasses migration history and causes supabase db push to fail later with sync errors. In practice that means your local project, your staging project and production slowly drift apart until nobody knows what the real schema is.
There is also no review step. A change made by clicking happens instantly, to every user, with no test run first. If it breaks the app, you are fixing it live.
Migrations fix both problems. Each change becomes a timestamped SQL file in supabase/migrations, committed to Git, applied in order everywhere. Your schema becomes part of your code, which is also what makes a handoff possible, as I explain in "How to hand off your AI-built app to a developer."
If your app came from Lovable or a similar builder, check the GitHub repo for a supabase/migrations folder. Builders often write migration files as they go, which gives you a head start.
What should I do before changing anything?
Take a backup you know you can restore, and write down exactly what the change is and which parts of the app read the affected tables.
According to Supabase's backup documentation at the time of writing, Pro projects can access the last 7 days of daily backups, Team projects 14 days and Enterprise projects up to 30 days, and point in time recovery is available as a paid add-on on those plans. Free projects are told to export their data regularly themselves.
So, before a risky change:
- On a paid plan, confirm a recent daily backup exists in the dashboard. For a big change, consider point in time recovery.
- On any plan, take your own dump with supabase db dump, once for the schema and once with the data-only option, and store it outside Supabase.
- Search the codebase for every table and column name you plan to touch. That list tells you what to test.
How do I set up Supabase migrations for an existing project?
Install the CLI, link it to your project, and pull the current remote schema into a first migration that becomes your baseline.
The sequence looks like this:
- Run supabase init in your repo if there is no supabase folder yet.
- Run supabase login, then supabase link and choose your project.
- Run supabase db pull to create a migration that captures the current remote schema.
- Run supabase migration list to confirm local and remote agree.
- Run supabase start to boot a local Supabase stack in Docker, and supabase db reset to rebuild it from your migrations and seed.sql.
One version note: the CLI reference currently says flags like --linked and --db-url still work in v3 but are deprecated and will be removed in v4 in favour of --remote, and the migration guide now writes commands such as supabase db push --remote. Check supabase --version and use the flags your version documents.
From here, the local database is your sandbox. You can break it as often as you like and rebuild it in seconds with supabase db reset.
How do I make a schema change with supabase db diff or a new migration?
Either write the SQL yourself in a new migration file, or make the change in local Studio and let supabase db diff generate the SQL for you.
Writing it by hand
Run supabase migration new add_status_to_orders. This creates an empty timestamped file in supabase/migrations. Write your SQL there, such as an alter table that adds a column with a default.
Generating it with db diff
If you prefer clicking, make the change in your local Supabase Studio, then run supabase db diff -f add_status_to_orders. The CLI compares your local database to your migrations and writes the difference as a new migration file. Always read the generated SQL before committing it, because diff tools can express a rename as a drop and an add, which deletes data.
Either way, finish with supabase db reset to replay every migration from scratch and confirm the full history still applies cleanly. Then run the app locally against it and click through every screen that touches the changed tables.
Do I need a staging Supabase project?
For any app with paying or real users, yes: a second Supabase project that mirrors production is where you find out whether a migration works on realistic data.
Local testing catches syntax errors and broken flows. It does not catch problems that only appear with real data: a NOT NULL constraint that fails because 300 old rows have empty values, a unique index that fails because of duplicates, an index build that takes minutes on a big table.
A simple setup:
- Create a second project named something like myapp-staging.
- Apply your migrations to it, and load either anonymized production data or a realistic seed.
- Point a preview deployment of your frontend at it, using separate environment variables.
- Push every migration to staging first, test, and only then push to production.
Supabase also offers Branching, and its migration guide suggests a CI pipeline that runs supabase db push on merge to main. Both are good once the basic habit is in place. Start with a plain staging project if you are new to this.
How do I push migrations to production safely?
Preview the push with the dry run option, push during a quiet period, and have your backup and rollback plan ready before you press enter.
The steps:
- Run supabase migration list against production to see exactly which migrations are pending.
- Run supabase db push with --dry-run to print what would be applied without applying it.
- Run the real push. The CLI asks for confirmation on hosted targets, and non-interactive runs such as CI need --yes.
- Immediately test the critical flows on the live app.
Ship changes in an order that never breaks the running app:
- Additive changes are safe in one step: new tables, new nullable columns, new indexes.
- To add a required column, add it as nullable, backfill it, deploy code that writes it, then add the NOT NULL constraint.
- To rename a column, add the new one, copy data, deploy code that uses it, and drop the old one in a later migration.
- Never drop a column or table the currently deployed frontend still reads.
If a push goes wrong, write a new migration that reverses it rather than editing old files. The supabase migration repair command only changes the history table and does not run SQL, so it is for fixing history mismatches, not for undoing changes.
What do I need to check about RLS after a schema change?
Check that every new table has row level security enabled with correct policies and grants, and that new columns on existing tables do not expose data through existing policies.
This is the step people skip, and it is where data leaks come from. After every migration, check:
- New tables: enable row level security with an alter table statement, then add policies for select, insert, update and delete as needed. Supabase's documentation warns that a table in an exposed schema without RLS is readable and writable by any role with a grant on it.
- Grants: Supabase announced that new tables in the public schema are no longer exposed to the Data API automatically, a change that reached existing projects on October 30, 2026. Without an explicit GRANT, a role cannot reach the table, so a feature can mysteriously return nothing. Supabase recommends putting the grants, the RLS statement and the policies in the same migration as the table.
- New columns: a sensitive column added to a table, say internal notes on a bookings table, is readable by anyone the existing select policy allows. Move sensitive data to its own table with stricter policies.
- Views and functions: views can bypass RLS unless created with security_invoker, and security definer functions run with elevated rights.
Then rerun your cross-user permission tests. My post "Is your Lovable or Bolt app leaking data? Check Supabase row level security" goes deeper on policies.
What does a safe change look like in practice? A worked example
Here is an illustration with a made-up app: a catering order tool on Supabase that needed orders to move from a simple paid flag to a status column with values like pending, confirmed and delivered.
The safe sequence ran over two deploys. First, a backup and a local baseline with supabase db pull. Then one migration that added a nullable status column, backfilled it from the old paid flag, and added an index on status. That went to staging, where the backfill revealed 40 old test orders with odd data, which were cleaned up in the same migration. After pushing to production, the frontend was updated to read and write status.
A week later, once nothing read the paid flag anymore, a second migration set status to NOT NULL and dropped the old column. At no point did the live app break. I use the same discipline with Prisma migrations on the Postgres-backed codebase I work on at The Hoop Gang; the tool differs, the rules do not.

Setting up migrations for an existing app and shipping one change like this usually fits my Fix Plus Features package from $200. If the change is one part of getting an app ready to launch, it sits inside Finish and Launch from $600.
The bottom line
Safe Supabase changes come from a short routine: back up, baseline your schema into migrations, make each change as a migration file, test it locally and on staging, push with a dry run first, and recheck RLS, policies and grants afterwards. It feels slower the first time. It is much faster than restoring a broken production database on a Friday night.
Questions, answered in one line
What is a database migration in Supabase?
A migration is a timestamped SQL file in the supabase/migrations folder that describes one change to your schema, so every environment can replay the same changes in order.
Can I keep using the Supabase Table Editor?
You can use it on your local or staging project and then generate a migration with supabase db diff, but avoid editing production tables directly.
Does the Supabase free plan include backups?
Supabase documents automatic daily backups for Pro, Team and Enterprise projects and recommends that free projects regularly export their own data.
Do I need a separate Supabase project for staging?
For any app with real users, yes, because a staging project lets you run migrations against realistic data without risking production.
Can someone set up migrations for my existing AI-built app?
Yes, Thomas Osayi can baseline an existing Supabase schema into migrations and ship a pending change as part of his Fix Plus Features package from $200.
Sources
- Database Migrations Supabase
- supabase db diff (CLI reference) Supabase
- Database Backups Supabase
- Breaking change: tables not exposed to Data and GraphQL API automatically Supabase
- Row Level Security Supabase
Related articles
- Supabase auth redirect URL not working? Fix localhost, preview and production redirects
- Environment variables undefined on Vercel? Every cause and fix
- How to fix a CORS error on a Next.js API route
- Firestore "Missing or insufficient permissions": what triggers it and how to fix it
Fix, finish and launch your AI-built app
Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.
See the service