Your Lovable Preview Writes to Live Customer Data: Fixing Dev and Production Separation
Lovable's preview, local runs, and published site share one database, and drafts edit live schema. Use the two-project Git pattern to isolate them.
TL;DR
| Layer | Default behavior in Lovable | Business risk | The fix |
|---|---|---|---|
| Preview (editor) | Runs against the project’s single production backend | Test edits create, change, and delete real customer records | Build/test in a separate dev project |
| Local IDE run | Same backend as the published app via .env (VITE_SUPABASE_URL) | Docs say it directly: local writes “change real data” | Dev project with its own database |
| Accepting a draft | Database structure, storage, and backend function changes go live immediately | Schema changed in production with no deploy step | Treat draft accepts as production changes; test drafts in dev |
| Publish | Deploys a copy; changes stay offline until “Publish changes” | The only gated step, but it gates UI, not data | Publish checklist + security scan, on a schedule |
| Migrations from Git | Not auto-run when commits sync | Dev and prod schema drift silently | Apply migrations explicitly per environment |
A founder we’ll call Dana runs a parts-ordering portal for her 40 B2B customers on Lovable. One Tuesday she asks it to “clean up the duplicate test orders” while testing a new invoice screen in preview. The preview shows the polished new screen, and the cleanup, executed against the only database this project has, just modified live customer order records. Two customers get wrong invoices that week. Nothing “broke” in any sense the platform would flag; there was simply no line between Dana’s testing and Dana’s production.
If your business runs on a Lovable app with real customers, this article explains the three invisible bridges between your testing and your live data (all documented by Lovable itself) and the two-project pattern that closes them in an afternoon.
The three invisible bridges from testing to production
Most people assume a published app is separated from their experiments the way production is separated in conventional development. In Lovable, by default, three bridges connect them:
Bridge 1: The preview shares the production database
A project is one app with one built-in backend. The preview you iterate on and the published site your customers use are two front doors to the same database. Lovable’s publishing docs are explicit about what publishing does gate, it deploys a copy of the project, and “the live site keeps showing the version you published” until you click Publish changes. What it never gates is the data underneath. Delete a row in the preview and it’s deleted for your customers.

Bridge 2: Your local IDE run shares it too
Connect a project to GitHub, clone it, and run it locally, the repo’s .env carries your backend URL and publishable key (VITE_SUPABASE_URL, VITE_SUPABASE_PUBLISHABLE_KEY). Lovable’s Git sync documentation contains the sentence every founder should memorize:
“A local app that keeps that configuration reads and writes the same backend as your published app, so records you create or delete locally change real data. A Git branch does not give you a separate database.”, docs.lovable.dev, Git sync
This is the bridge that catches developers joining the project. They clone, spin up locally, create test accounts, in production.
Bridge 3: Accepting a draft changes live schema: instantly
Drafts are Lovable’s mechanism for trying a bigger change in parallel. The trap is in what happens when you accept one:
“When you accept a draft, its changes to the database’s structure, file storage settings, and backend functions take effect in your live app immediately, and the rest of its changes join your project’s unpublished changes.”, docs.lovable.dev, Publishing
The UI part of the draft waits politely for Publish. The data model part (new tables, altered columns, changed backend functions) hits production the moment you click accept. No deploy step, no review gate, no undo button in the publish dialog. A draft accepted at 5 PM on a Friday is a live production migration at 5 PM on a Friday.

Why it’s built this way: and when that’s fine
Lovable optimizes for speed from idea to working software, and for its core audience (prototypes, proofs of concept, apps without live transactions), one project = one app = one backend is the right simplification. No environments to configure, no deploy pipelines to babysit.
The model starts costing money exactly when the app starts making you money: real customers, real orders, real invoices. At that point “test in preview” is synonymous with “test on live customers”, and the cost side of that trade is easy to compute. One bad afternoon of corrupted order records means support hours, refund credits, and the one thing an SMB can’t re-key: customer trust.
The fix: two projects, promoted through Git
Lovable has no in-project environment switch, but it gives you everything needed for the classic separation pattern, documented, supported features, no hacks:

1. Create the dev project with Remix
Remix creates an independent copy of a project, its own code, its own project chat, and critically its own built-in backend and database. Remix your production project once; name the copy …-dev. Now the bridges are severed by construction: nothing you break in dev touches production data, because dev has its own data. Plans are priced by credits, not projects, so there is no second subscription; the copy just draws from the same pool when you actually use it.
One caveat from the docs before you trust the copy: treat a remix as a live app, not a sandbox. A key or a URL written into the code still points at production services until you scrub it, so check where the copy sends requests before you test writes.
2. Give each project its own Git repository
Connect the dev project to GitHub first: Lovable creates a new repository automatically. Then connect the production project, and Lovable creates a second one. That is not a workaround, it is a documented limit: Git sync links exactly one repository to one project, and connecting a project to a repository that already exists is explicitly unsupported. The dream diagram of “one repo, two branches” is not what the platform offers; two projects means two repos.
Promotion is then a merge between the two repositories: dev repo first, then production. A short script or a small GitHub Action that opens the pull request handles it. Two structural facts from the docs keep that promotion path safe:
- Pushing to a repo never publishes. “Does pushing to my repository update my live site? No.” Code reaches the production project through Git, but customers see nothing until a human publishes, a second gate for free.
- Protected branches are respected. If the production repo requires review for
main, Lovable’s own pushes land on alovable-syncbranch and wait for your merge, so your review process applies to AI-generated code too.
3. Move schema changes explicitly: this is the step everyone skips
Lovable does not run database migration files that arrive through Git commits. Every structural change must be applied deliberately, per environment. The workflow that keeps dev and prod honest:
- Make the schema change in the dev project (ask Lovable there, it records a migration file).
- Test the feature against dev’s isolated database.
- Apply the same migration to production deliberately, via a tracked SQL migration run in the production project’s SQL editor, or an explicit chat request there, before or with the code publish, never after.
This is also your audit trail: schema changes in production become events someone chose, not side effects of accepting a draft.
4. The six-step release gate (before anything reaches customers)
Every promotion from dev to production runs through the same six checks. Whether your engineer automates them in CI or your team walks through them as a release checklist, skipping a step is how broken migrations reach live buyers:
| Step | Release gate | Who owns it | What breaks if skipped |
|---|---|---|---|
| 1. Dev smoke test | Verify the new workflow end-to-end on the …-dev project with synthetic test orders | Operations / founder | Broken forms or calculation bugs get promoted straight to main |
2. Code review (dev repo → prod repo) | Promote through the reviewed pull request your script or GitHub Action opens | Engineer / technical lead | Unreviewed AI prompt edits overwrite working business logic |
| 3. Database backup & migration | Take a fresh production snapshot, then apply the tested SQL migration to production before publishing UI changes | Engineer | New UI screens query columns or functions that do not exist in production yet |
| 4. Security Quick scan | Click Publish changes in the production project and review Lovable’s built-in RLS and dependency scan | Founder / engineer | Newly created tables ship with permissive or missing Row-Level Security |
| 5. Live post-publish verification | Run one real read/write check against the live production URL and confirm webhook/email delivery | Operations | Silent env-var or webhook mismatches go unnoticed until a customer complains |
| 6. Release tag | Tag the Git commit with the release date so you can roll back in minutes if needed | Engineer | No clean restore point if an edge case surfaces the next morning |
You don’t need complex deployment tooling on day one, following that six-row sequence in order prevents the entire class of incidents in this article. What it removes is the Friday-afternoon failure mode: testing a prompt against live customer records under pressure.
Where the DIY Remix setup still falls short in real operations
Splitting into two projects closes the immediate preview-writes-to-prod trap, but founders running daily operations hit three walls that Remix alone does not solve:
- Your live customer data is already sitting in the first project. Remix copies code and schema structure, not sanitized test fixtures, and if your original database has messy records, missing foreign keys, or exposed columns, those flaws stay in production until audited.
- Schema and RLS drift on release two. Because Lovable does not auto-run Git migrations across projects, one forgotten column or security policy in production causes silent write failures that the chat window cannot see or diagnose.
- No automated rollback or dead-letter queue. When an external Stripe, Shopify, or email webhook fails against a Lovable backend, failed events vanish unless an engineered queue captures them (compare how an owned operations platform handles validation, audit logs, and role boundaries live at demo.kamensky.dev).
5. Guardrails that cost nothing
- Branch protection on
main: forces review before AI-written code reaches the production project. - Read the publish dialog’s Quick scan: it checks row-level security policy mistakes, dependencies, and connectors. Lovable’s docs recommend resolving critical findings before going live; Business/Enterprise workspaces can block publishing with unresolved critical issues.
- Never put secrets in
VITE_variables: they ship to every visitor’s browser. Service-role keys stay server-side (Lovable-managed secrets don’t sync to your repo). - Don’t force-push, rebase, or squash the synced branch: Lovable keeps its own copy and will file your rewrite as a conflict; reverts go in as new commits.
Cost-benefit: the cheapest insurance in your stack
| Two-project setup | One bad afternoon | |
|---|---|---|
| Cost | ~1–2 hours setup; occasional dev-project run credits; one extra publish step per release | Wrong invoices/orders to N customers; support hours; refunds; “their system is unreliable” |
| Failure mode | Annoyance (extra step) | Reputation, the thing a small business can’t re-key |
| Who it protects | Every customer, every release, permanently | - |
For a business earning revenue through the app, the two-project pattern is the highest-return hour of engineering the platform offers. And it’s the first thing checked in any production-readiness pass, alongside the deeper issues in Your Replit/Lovable Demo Isn’t a Production System and the handoff mechanics in Handing Your AI-Built App to a Developer.
When one project is still fine
Keep the single-project setup while all of these hold: the app is pre-launch, no real customer data exists in the backend, and you’re the only person building. The day any of those stops being true (usually the day real customers place real orders) spend the afternoon and split.
Get a production-readiness pass before your customers find the gap
If your revenue now flows through a Lovable (or Replit, Bolt, or Supabase-backed) app with no separation between your testing and your customers’ data, that’s a fixable afternoon, plus a checklist that keeps it fixed. Andrey Kamensky (kamensky.dev) hardens AI-built systems into production operations: environment separation, data backups, security review, and the automation glue around them. See the pattern in Rescuing Broken AI-Built and No-Code Systems, or the exposed-keys checklist in vibe-coded app security: Supabase RLS. And when the published domain misbehaves while the preview looks perfect, the five host-dependent causes (auth allowlists, baked environment variables, SPA rewrites) are the first places to check.
Start with a bounded Operations & Data Audit (a prioritized list of what would break first and what it costs to prevent) or book a 20-minute fit call →.
Sources & further reading
- Publish your Lovable project: publish = deploy a copy; draft acceptance changes live database structure immediately
- Sync your Lovable project with GitHub, GitLab, or Bitbucket: one branch at a time, pushes never publish, “a Git branch does not give you a separate database”
- Projects in Lovable: one project = one app; remix for independent copies; no project limit
- Why Every New Prompt Breaks Something That Already Worked in AI-Built Apps: golden-path smoke tests, diff scoping, and rollback rules to stop functional regressions
- Your Replit/Lovable Demo Isn’t a Production System: the 8-point production checklist
- Handing Your AI-Built App to a Developer Without a Full Rewrite: what exports and repos silently leave behind
- Vibe-Coded App Security: Supabase RLS and Exposed Keys: locking down the backend your app shares
- Rescuing Broken AI-Built and No-Code Systems: the full rescue pattern on a real project
Frequently asked questions
Does the Lovable preview use the same database as my published app?
Yes. A Lovable project has exactly one built-in backend, and the preview, local IDE runs, and the published site all point at it. Lovable's own documentation warns that a locally running app connected with the project's .env "reads and writes the same backend as your published app, so records you create or delete locally change real data. A Git branch does not give you a separate database."
Does Lovable support separate development and production environments?
Not within one project, a project is one app with one backend, and it syncs one Git branch at a time. The supported pattern for separation is two projects: remix your production project into a development copy (Remix creates an independent project with its own backend and database), build and test there, and promote code to production through Git, applying database migrations explicitly before publishing. Note that Git sync links exactly one repository to one project (Lovable creates a new repo on connect), so the promotion is a merge between the two repositories, not two branches of one repo.
Why did my production database change when nobody published anything?
Accepting a draft is not publishing, but per Lovable's docs, a draft's changes to the database's structure, file storage settings, and backend functions take effect in your live app immediately, while its screen changes wait for the next publish. Testing flows that accept drafts is a production database change, whatever the preview shows.
How much does a second, development Lovable project cost?
Effectively nothing beyond build credits. Lovable plans are priced by credits, not by projects or seats (there is no project limit) so a development project costs only the credits you spend building in it. Publishing from the publish dialog is free; hosting the dev copy consumes run credits only when you actually use it.