Your app is live. Real users have real data in it. Now you need a new field, a renamed column or a new table. You ask the AI tool to do it, and then you worry. Will it drop a table? Will it break the live app? People do report "the AI deleted my table". Most database changes are safe if you follow a few steps. Vendor facts below come from each vendor's own docs, checked in November 2026.
Short answer: Make a backup first and check that you can restore it. Write every change as a migration file, not as a quick edit on the live database. Prefer changes that only add things. Test on a copy. Read the SQL before it runs and look for DROP, TRUNCATE, DELETE and ALTER ... TYPE. If something goes wrong, stop writes, then restore or roll back.
1. Backup first, and check that you can restore it
A backup you never tried to restore is a hope, not a backup. Before any structure change, take a fresh backup. Then check that you know how to bring it back. The details for Supabase, Neon and Firebase are in the database backups guide.
If your app uses Lovable with Supabase, this matters even more. Lovable's Supabase page says: "You manage backups, compute, and billing in Supabase." So the backup is your job.
On Supabase, the backups page says Pro Plan projects can access the last 7 days of daily backups. For the Free plan, it recommends that you regularly export your data with the CLI's db dump command and keep copies off-site. Also know that a restore is not free of cost: "The project is inaccessible during this process, so plan for downtime beforehand."
2. What a migration is
A migration is a change to the database structure, written as a file. The file lives in your code, next to the app. The files run in order. So you can see what changed, when, and you can repeat the same steps on another database.
Supabase's migrations guide describes migrations as "SQL statements that create, update, or delete your existing database schemas." It shows these commands with the Supabase CLI:
supabase migration new create_employees_tablecreates a new migration file in thesupabase/migrationsfolder.supabase migration upapplies a new migration on your local copy.supabase db resetreapplies all migrations and seeds data, so you can test your changes locally.supabase db push --remotepushes your migrations to the remote database.
The same page has a warning that matters for AI-built apps. If you change the remote database directly, in the SQL editor or the Table Editor, this "bypasses the migration history and will cause db push to fail with sync errors." Quick edits on the live database leave no trail. Migration files do.
How Lovable handles it
Lovable's Supabase page says: "Lovable writes the SQL, shows it to you, and asks for your approval in the project chat before running it." After you approve, Lovable runs the migration on your Supabase project. It also saves the migration file in your project code. Inserting or modifying data needs your approval as well. That approval step is your chance to read the SQL. Do not click through it. Section 7 shows what to look for.
3. Safe changes and risky changes
Not all changes carry the same risk. Here is a simple split.
Low risk:
- Adding a new table.
- Adding a new column that is allowed to be empty (nullable).
PostgreSQL's ALTER TABLE docs say that if you add a column without constraints, "NULL is used as the DEFAULT" and a rewrite of the table is not required. Old rows stay as they are. The app keeps working because it does not know about the new column yet.
Risky:
- Dropping a column or a table. The data is gone from your point of view. The Postgres docs also say that "Indexes and table constraints involving the column will be automatically dropped as well."
- Renaming a column. Postgres says a rename has "no effect on the stored data". But your app code still asks for the old name. The live app breaks until the code is updated and deployed. The database and the app never change at exactly the same moment.
- Changing a type. The docs say that changing the type of an existing column "will normally cause the entire table and its indexes to be rewritten." Values can also fail to convert.
- Adding NOT NULL to a table that has data. The docs say it "may only be applied to a column provided none of the records in the table contain a NULL value for the column." Old rows with empty values will make it fail. And Postgres checks it by scanning the entire table.
Expand, then contract
This is plain advice, not a rule from one vendor. When you must rename or reshape something, do it in small steps over several deploys:
- Expand. Add the new column or table. Keep the old one. Nothing breaks.
- Copy. Copy the existing data from the old column into the new one. Check the counts.
- Switch. Change the app to read and write the new column. Deploy. Watch it for a few days.
- Contract. Only when nothing uses the old column anymore, remove it in a separate migration, after a fresh backup.
It is slower than one big rename. But at every step you can go back, and your users never see an error.
4. Supabase specifics: Row Level Security
When you add a table, you also add a security question. Supabase's Row Level Security docs say: "Enable RLS on every table in an exposed schema." They add a warning: "A table in an exposed schema without RLS is readable and writable by any role with a grant on it."
The same page says: "Once RLS is enabled, no data is accessible through the API when using a publishable key, until you create policies." So the new table needs two things: RLS turned on, and policies that let the right users in.
A new column on an existing table can also need attention. If your policies list or check specific columns, or if your app reads the column through a view or function, check that the new column behaves as you expect. A new "owner" or "user_id" column that is empty on old rows can lock people out of their own data, or the other way around.
For the full list of checks, read the database security checks for AI-built apps.
5. Test on a copy before the live database
Never try a structure change on live data first. Use a copy. The idea is explained in the staging copy guide. Your options:
- A separate Supabase project. Create a second project, apply your migrations there, and test the app against it. Live users are not affected.
- Supabase branching. The branching docs say preview branches are "ephemeral and best suited for focused testing". Be careful with one thing: "By default, new branches do not start with any data or storage objects from your base project." So a branch tests your migration file, but not how it behaves on your real rows, unless you load data into it with a seed file or the "Include data" option in the dashboard.
- Neon branches. Neon's branching docs describe a branch as "a copy-on-write clone of your data." That is a real copy of your rows. Its testing workflow covers "testing schema changes". Run your migration on a branch, check the result, then delete the branch.
Treat a copy of real user data with care. It contains the same personal data as the live database. Do not share it around.
6. Firestore: no schema, so the "migration" is in your code
Firebase works differently. The Firestore data model page says "Cloud Firestore is schemaless" and that "Documents within the same collection can all contain different fields or store different types of data in those fields."
That means there is no database step that adds a column. You just start writing a new field in new documents. The catch: old documents keep the old shape. They do not get the new field by themselves. If you rename name to fullName in the code, every old document still has name and nothing in fullName.
This is plain advice for that case:
- Make the code handle both shapes. For example, read
fullNameand, if it is missing, fall back toname. - Write only the new shape from now on.
- Run a one-time script to update old documents, on a copy first. Check the counts after.
- Remove the fallback only when no old documents are left.
It is the same expand-then-contract idea as in section 3, just done in code. Also check your Firestore security rules after you add new fields or collections.
7. What to tell the AI tool, and what to check in the SQL
Be specific. AI tools do what you ask in the shortest way, and the shortest way to a rename can be a drop and a re-create. Example prompts:
- "Write this as a new migration file. Do not drop or rename existing columns. Show me the SQL before running it."
- "Add a nullable column called phone to the profiles table. Do not change any existing data."
- "Create a new table for invoices. Enable Row Level Security and add policies so users can only see their own rows. Show me the SQL first."
- "I want to rename the column status to state. Use the expand-then-contract approach: add the new column, copy the data, update the app, and keep the old column for now."
- "List every place in the code that uses this column before you change anything."
Then read the SQL yourself. You do not need to be a developer to spot these words:
DROP TABLEorDROP COLUMN: removes things. Stop and ask why.TRUNCATE: empties a whole table.DELETEwithout aWHERE: deletes every row.ALTER COLUMN ... TYPEorSET DATA TYPE: changes a type, can fail or rewrite the table.SET NOT NULL: fails or blocks if old rows are empty.CASCADE: also removes things that depend on the object.RENAME: the app code must change too.DISABLE ROW LEVEL SECURITY: opens the data to everyone.
If you see one of these and you did not ask for it, say no and ask the tool to explain. If you are not sure, a second pair of eyes is cheap compared to lost data.
8. If it already went wrong
Stay calm and go in this order.
- Stop the writes. Do not let new data come in on top of a broken state. Pause the app, switch on a maintenance page, or turn off the forms. Do not run more AI fixes on the live database.
- Write down what happened. The time of the change, the SQL that ran, and the error. You need this for the restore point.
- Restore. On Supabase, the backups page says "You can restore your project to any of the backups." It also says that "Pro, Team and Enterprise Plan projects can enable PITR as an add-on." PITR is point-in-time recovery. It lets you pick a moment, such as just before the bad change. The page notes that a PITR restore "replaces the current database state", and that to keep current data you can restore to a new project first. Restoring to a new project lets you copy back the rows you need without overwriting good data.
- On Neon, the branch restore docs say you can restore a root branch to an earlier state in its own history, within your history window. Neon keeps the branch's final state before the restore in an automatically created backup branch, so you can undo a restore too. Check the history window for your plan in the Neon docs.
- Roll back the app. If the code was deployed together with the change, also go back to the last working version. See how to roll back a broken deploy. The database and the code must match each other.
Rolling back the app does not roll back the database. These are two separate things. Fix both.
9. Checklist
- A fresh backup exists, and I know how to restore it.
- The change is written as a new migration file, kept with the code.
- The change only adds things where possible: a new table or a nullable column.
- Renames and type changes are split into expand, copy, switch and contract.
- I read the SQL before it ran. No DROP, TRUNCATE, DELETE without WHERE, or ALTER ... TYPE that I did not ask for.
- New tables have Row Level Security on, with policies.
- I tested on a copy: a second project, a branch, or a Neon branch.
- Firestore: the code handles both old and new document shapes.
- I know how to roll back the app if the deploy goes wrong.
- The old column or table is removed only later, in its own migration, after a new backup.
Want this fixed for you?
I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including database changes on a live app without losing data. Send me the details and I'll reply within 24 hours.