Production readiness
No staging environment: separating test and production in a Lovable / Supabase app
If your Lovable app is connected to one Supabase project, every database change you approve in the chat runs on the database your users are using - and with your own Supabase project, Lovable's drafts share that live backend too. A staging environment is a second database (a second Supabase project, or a Supabase branch) with its own keys and test data, where every change runs first. The same migration file then goes to production once it works.
What you are seeing
You usually notice it after the fact:
- You asked the AI to change or rename a table, approved the SQL, and the live app broke for real users at the same moment.
- Test accounts, test orders or rows like
asdfshow up in your production data, mixed with real customers. - Real users got an email, a notification or a charge that was meant to be a test.
- You reverted the code to an earlier version, but the data or the table change stayed. Lovable's docs say reverting "does not restore or roll back your database data" (Lovable version history).
- You cannot try a risky change - a new pricing table, a data migration, new permission rules - without trying it on your customers.
How to check it yourself
Check your own project only. Everything below only reads settings and data.
1. Find out which backend your app uses
- Lovable's built-in backend (Lovable Cloud): Lovable retired the Test and Live split on 2026-10-23, so "every project on the built-in backend runs on a single database" (Lovable environments, checked 2026-11-21). If you relied on Test before, it is gone. Lovable says detached Test databases can be restored until 2026-12-01 and are fully deleted after that.
- Your own Supabase project: Lovable connects each Lovable project to one Supabase project at a time, and when it changes the database it "writes the SQL, shows it to you, and asks for your approval in the project chat before running it" (Lovable + Supabase). Running it means running it on that one project.
2. Find out which Supabase project the app talks to
If your code is synced to GitHub, clone it and search for project addresses from the project root:
grep -rnoE "https://[a-z0-9]+\.supabase\.co" --exclude-dir=node_modules --exclude-dir=.git ..env files and in the build - means one database for everything.Then open the Supabase dashboard. The part of the address before .supabase.co is the project ref, and it also appears in the dashboard URL. If your organization has only that one project and the branch selector in the top bar shows only the main branch, there is no staging database.
3. Look for test data in production
In the Supabase dashboard, open SQL Editor on the production project and run:
-- Accounts that look like test accounts
select id, email, created_at, last_sign_in_at
from auth.users
where email ilike any (array['%test%', '%@example.com', '%+%@%'])
order by created_at desc
limit 100;4. Check whether database changes are kept as files
A staging setup only works if every change exists as a file you can run twice: once on staging, once on production. Lovable saves the migrations it runs in your code under supabase/migrations/ (Lovable + Supabase). Changes made by hand in the Supabase dashboard are not saved anywhere. To see what the production database has recorded, run in SQL Editor:
-- Does this project keep a migration history at all?
select to_regclass('supabase_migrations.schema_migrations') is not null as has_migration_history;-- If it does: the most recent migrations applied
select version
from supabase_migrations.schema_migrations
order by version desc
limit 20;true. Compare the versions with the file names in supabase/migrations/ - each file name starts with its version.With the Supabase CLI you can do the same comparison in one step. The commands on this page follow the CLI reference as checked on 2026-11-21, where --remote targets the linked project; older CLI versions use --linked instead.
supabase login
supabase link YOUR_PRODUCTION_PROJECT_REF
supabase migration list --remote5. Check which keys the server code uses
Open Edge Functions > Secrets in the dashboard and read the names (not the values) of the secrets. If there is one Stripe key and it is a live key, every test you run through the app is a real payment. Stripe live keys start with sk_live_ or rk_live_, sandbox keys with sk_test_ or rk_test_ (Stripe API keys).
Why it happens
AI builders make the first version fast by giving you one app, one database and one set of keys. Nothing in that setup separates trying a change from shipping it:
- Database changes run when you approve them. With your own Supabase project, Lovable runs the SQL on the connected project, and that project is your production database.
- Drafts do not help with your own Supabase project. Lovable's docs say a draft then shares your live backend, so database changes made in it reach the live app immediately, and deleting the draft does not undo them (Lovable drafts).
- On Lovable Cloud, a draft usually gets its own backend with example data, but it uses your live values for secrets and connected services, and accepting it applies its database changes to the live app at once:
“Accepting a draft can change your live database's structure, but it never copies data from the draft.”
- Code and data move separately. Reverting or publishing the front end does not change the database back, so a broken table change stays broken until someone fixes the database.
- A remix is not automatically a test environment. Lovable says a remix copies the code and the table structure without the records, but code in the copy can still reach services the original uses through addresses or keys written into the code (Lovable remix). A remix that still points at your production Supabase project tests nothing.
How to fix it
The goal: a second database with the same structure, its own keys and only test data, plus a rule that every database change runs there first. There are two ways to get the second database on Supabase.
Option A: a second Supabase project as staging
This is the setup Supabase's own environments guide describes: "You need a *new* project for staging" (Managing environments). It works on any plan. On the Free plan, as of 2026-11-21, you get two active projects and Supabase pauses Free projects after a week of inactivity (Supabase pricing), so a staging project you rarely touch may need to be restored before use.
- Create a new Supabase project in the same organization and name it clearly, for example
myapp-staging. Save its database password. - If anyone changed the production database by hand in the dashboard, capture those changes as a migration file first: link the CLI to production and run
supabase db pull --remote, which saves the current schema as a new file insupabase/migrations/(Managing environments). Commit that file. - Apply all migration files to the empty staging project (commands below). Staging now has the same tables, policies and functions as production, and no customer data.
- Copy the settings that are not part of migrations: Authentication providers, Site URL and Redirect URLs, email templates and SMTP, Storage buckets if they were created in the dashboard, and Edge Function secrets - with test values.
- Point a copy of the front end at staging (see below), try the app end to end, and only then apply the same migration to production.
# 1. Staging first
supabase link YOUR_STAGING_PROJECT_REF
supabase db push --remote --dry-run # lists the migrations it would apply
supabase db push --remote
# 2. Test the app against staging. Then production, the same files:
supabase link YOUR_PRODUCTION_PROJECT_REF
supabase migration list --remote
supabase db push --remote --dry-run
supabase db push --remote--dry-run prints what would run without running it. The CLI asks for the database password; you can set it in the SUPABASE_DB_PASSWORD environment variable instead. In scripts and CI, add the global --yes flag.Option B: Supabase Branching
Branches are separate environments created from your project, each with its own Supabase instance and API credentials. Supabase recommends persistent branches for long-lived environments like staging; preview branches are deleted when the pull request is merged or closed (Branching). As of 2026-11-21, Branching is not available on the Free plan, and a branch on the default Micro compute size starts at $0.01344 per hour, billed on top of your plan and not covered by the Spend Cap (Branching usage, Supabase pricing).
- New branches start without your production data or storage objects. Test data comes from a seed file (see below), or from the dashboard's Include data option, which needs the Point-in-Time Recovery add-on and makes the branch as sensitive as production (Dashboard branching).
- Auth secrets such as OAuth provider secrets and SMTP passwords get placeholder values on a branch. Set real test values as branch secrets (Branching).
- With the GitHub integration, branches are built from the migration files in your repository. If you turn on the "Deploy to production" option, merging runs a deployment that applies pending migrations to production. Supabase recommends making the migration check a required check so a failing migration blocks the merge (GitHub integration).
- Branching from the dashboard works without GitHub, but Supabase labels it as an opt-in preview feature (Dashboard branching).
Point a copy of the front end at staging
The database is only half of it - you also need a version of the app that talks to staging. Find where the Supabase client is created (search for createClient() and make sure the URL and public key come from environment variables, not from text written into the file. For a React + Vite project (the default for Lovable projects created before 2026-05-13, or before 2026-06-22 on Enterprise, unless the project was later upgraded to TanStack Start), Vite loads .env.[mode] files for the mode you build in (Vite env variables):
// The file where your project creates the Supabase client
import { createClient } from "@supabase/supabase-js";
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseKey = import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY;
if (!supabaseUrl || !supabaseKey) {
throw new Error("Missing VITE_SUPABASE_URL or VITE_SUPABASE_PUBLISHABLE_KEY");
}
export const supabase = createClient(supabaseUrl, supabaseKey);# .env.staging - used by: vite build --mode staging
VITE_SUPABASE_URL=https://YOUR_STAGING_PROJECT_REF.supabase.co
VITE_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...
# .env.production - used by: vite build
VITE_SUPABASE_URL=https://YOUR_PRODUCTION_PROJECT_REF.supabase.co
VITE_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...anon) key belong here - everything with a VITE_ prefix ends up in the browser. Secret keys, Stripe secret keys and webhook secrets go in Edge Function secrets of each project.- Newer Lovable projects, and older ones upgraded in place, use TanStack Start instead of plain React + Vite (Upgrade to TanStack Start). To see which one you have, ask Lovable which stack the project is on, or look for
@tanstack/react-startin package.json. The idea is the same - the address comes from a variable that differs per environment - but check how your project reads its variables before copying the example. - Inside Lovable, a second Lovable project connected to the staging Supabase project is another way to get a staging front end. Two cautions from Lovable's docs: Lovable projects that share one Supabase project overwrite each other's secrets (including
LOVABLE_API_KEY), and moving a project between Lovable Cloud and your own Supabase project is not automatic (Lovable + Supabase). Run the search from check step 2 on the copy to make sure no production address is left in its code. - If your code is synced to GitHub, Lovable edits and syncs one branch at a time, and you can switch that branch in the GitHub settings (Lovable GitHub). Keeping the migration files in the same repository is what lets staging and production run the same changes.
- Show a visible "Staging" label in the staging build, for example when
import.meta.env.MODE === "staging", so nobody mistakes it for the real app.
Keep everything else separate too
- Payments: staging uses a Stripe sandbox and its
sk_test_orrk_test_key. In a sandbox, card networks do not process payments (Stripe API keys). Each webhook endpoint has its own signing secret, so staging needs its own endpoint and secret. - Auth: set the Site URL and Redirect URLs in each project's URL Configuration to that environment's own address. Supabase recommends exact redirect paths in production rather than broad wildcards (Redirect URLs).
- Email: send staging email through a test SMTP account or to your team only, so a test never reaches a customer.
- Test data: put it in
supabase/seed.sql. Seed files run onsupabase startandsupabase db reset(Seeding) and on branches when seeding is enabled; Supabase says data changes in seed files are not merged to production (GitHub integration). Do not copy real customer records into staging unless you have to - then staging needs the same protection as production.
-- supabase/seed.sql - example rows for staging only.
-- Replace the table and columns with your own.
insert into public.products (name, price_cents)
values
('Test product A', 1000),
('Test product B', 2500);Then make it the rule
- Every database change starts as a migration file, made by Lovable or with
supabase migration new. No hand edits in the production dashboard. - The file runs on staging first, and you click through the parts of the app it touches.
- Back up production, then apply the same file to production.
- When you are ready, automate it: Supabase's guide shows GitHub Actions that push migrations to staging on one branch and to production on another (Managing environments).
When to get help
A second project and a clear rule take an afternoon for a small app. It gets harder when:
- The production database was changed by hand for months and the migration files no longer match it, so staging cannot be rebuilt from them.
- A test change already damaged real data and you need to decide between a restore and a targeted repair.
- Payments, webhooks or emails are involved and you need to be sure staging can never touch real customers or real money.
- You want the migration path automated in CI, with checks that block a broken migration before it reaches production.
Sources
Primary documentation this guide was checked against. Platforms change - if something here no longer matches, the source wins.
- BranchingSupabase docs
- Branching via GitHubSupabase docs
- Branching via the dashboardSupabase docs
- Manage Branching usageSupabase docs
- Managing environmentsSupabase docs
- CLI reference: db pushSupabase docs
- Seeding your databaseSupabase docs
- Redirect URLsSupabase docs
- Database backupsSupabase docs
- PricingSupabase
- Test and Live environmentsLovable docs
- DraftsLovable docs
- Supabase integrationLovable docs
- Version historyLovable docs
- Remix a projectLovable docs
- GitHub integrationLovable docs
- Database backupsLovable docs
- Upgrade to TanStack StartLovable docs
- Env variables and modesVite docs
- API keysStripe docs
Frequently asked questions
- Are Lovable drafts a staging environment?
- Not with your own Supabase project: Lovable says a draft then shares your live backend, so database changes reach the live app immediately. On Lovable Cloud a draft usually gets its own database with example data, but it uses your live secrets and connected services, and accepting it changes the live database structure at once.
- Is a second Supabase project or Supabase Branching better?
- A second project works on any plan and is the setup Supabase's environments guide describes. Branching needs a paid plan and costs per branch per hour, but builds the branch from your migration files and can deploy migrations to production on merge. For a small app with one owner, a second project is the simpler start.
- Can I just copy my production data into staging?
- You can, but then staging holds your customers' personal data and needs the same protection as production. Supabase branches start without production data by default for this reason. Prefer a seed file with invented test data.
- My Lovable Cloud project used Test and Live. What changed?
- Lovable retired the split on 2026-10-23, and every project on the built-in backend now has a single database. According to Lovable's docs, detached Test databases stay restorable until 2026-12-01 and are deleted after that.
- Does reverting to an earlier version in Lovable undo a database change?
- No. Lovable's docs say reverting does not restore or roll back database data, and it does not undo structure changes from an accepted draft. That is why database changes need to be tried on staging and backed up before they reach production.
Related guides
Fixed-price audit
Want someone to check the whole app, not just this?
A review of data security, production readiness and App Store readiness for apps built with AI tools. 900 USD, a ranked list of fixes within 5 business days.