DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The New Testing Pattern: Standardizing Regression for Cloud Migrations
  • Cost Optimization Strategies for Managing Large-Scale Open-Source Databases
  • Which Tool Is Better for Code Completion — Azure Data Studio or dbForge SQL Complete?
  • Simplify Database Geo-Redundancy Backup With Cloud Storage Services

Trending

  • The Agent Protocol Stack: MCP vs. A2A vs. AG-UI
  • Why Pass/Fail CI Pipelines Are Insufficient for Enterprise Release Decisions
  • Securing Everything: Mapping the Right Identity and Access Protocol (OIDC, OAuth2, and SAML) to the Right Identity
  • The Hidden Bottlenecks That Break Microservices in Production
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Migration from Lovable Cloud to Supabase

Migration from Lovable Cloud to Supabase

This article provides a step-by-step guide to migrating your data and users from Lovable Cloud to Supabase, breaking the process down into seven clear steps.

By 
Alexander Komyagin user avatar
Alexander Komyagin
·
Apr. 08, 26 · Tutorial
Likes (0)
Comment
Save
Tweet
Share
3.9K Views

Join the DZone community and get the full member experience.

Join For Free

Once your vibe-coded prototype on Lovable is up and running, you might be ready to graduate to self-hosting or a more advanced service that scales better and gives you more control. If your Lovable application uses Lovable Cloud, a common choice is to migrate your data to Supabase. Supabase is a popular Backend-as-a-Service platform based on PostgreSQL. It has a reasonable free tier and it offers baked-in solutions for auth, serverless code execution (Edge Functions), real-time database change notifications and REST API. One of the big advantages of the platform is that at its core it's based on Open Source technologies and the vast PostgreSQL ecosystem.

Internally, Lovable Cloud is already using a shared Supabase instance behind the scenes, but it doesn't expose direct database access making migration a little more involved than it needs to be. Below we list specific instructions for getting your data and users to Supabase in just 7 steps.

For this exercise, I created a demo "SpendSmart" Lovable application - it shows analytics for credit card spending, supports email-based authentication and enables row-level security to protect users from viewing each other's personal information and transactions. 

I assume that you already have development tools installed on your machine, such as git , node

 and npm.Image 1


Step 1: Connect your GitHub account and sync your Lovable project to a repository

As our first step, we will need to export the project code from Lovable. Fortunately, it is easy to do using their GitHub sync. You can follow the detailed instructions in their official documentation.

Image 2


Step 2: Clone your repository locally

After the project code has been successfully synced to GitHub, we can clone the repository locally:

Shell
 
git clone [email protected]:<USER>/<REPO>.git
cd <REPO>


Step 3: Create a new Supabase project

If you don't already have an existing project, navigate to and create it. As of this writing, their free tier provides a shared CPU, 500 MB RAM and 500 MB database size. While this is indeed not enough for a production database serving live traffic, it's plenty for moving your prototype from Lovable.

Step 4: Initialize Supabase config in your repo

After creating the Supabase project, we need to initialize it with our repo. Note that Lovable already exports Supabase database schema and RLS policies along with the original project code, so we don't need a separate step to export it.

Shell
 
npm install supabase --save-dev
npx supabase login 
npx supabase link 
npx supabase db push # this will create the schema and RLS policies


Step 5: Update the project's environment variables

The project's environment variables for connecting the application to Supabase backend are stored in the .env file in our repo:

Shell
 
VITE_SUPABASE_PROJECT_ID="..."
VITE_SUPABASE_PUBLISHABLE_KEY="..."
VITE_SUPABASE_URL="..."


From the Supabase Project view in your Web Browser, get Supabase Project Id, Url, and Publishable Key.

Replace the values in the .env file for all three variables.

Image 3

If your application is serving live traffic, at this point you should temporarily un-publish your app in Lovable=>Project Settings to preserve data integrity.

Step 6: Migrate auth data from Lovable 

If your Lovable app is serving live traffic, before we proceed with steps 6 and 7, I recommend that you temporarily un-publish your app in Lovable=>Project Settings. This is done to preserve data integrity, because now we will be migrating the database itself.

Step 6 is a bit non-trivial as to make things clean, we need to capture records from Lovable Cloud's auth.users table and import it using Supabase's createUser() API. We wrote a simple helper script for that. Save it as migrate.js and edit SUPABASE_URL and SERVICE_ROLE_KEY:

JavaScript
 
import fs from 'node:fs';
import csv from 'csv-parser';
import { createClient } from '@supabase/supabase-js';

// 1. Configuration - Update these with your NEW project details
const SUPABASE_URL = // New Supabase Project URL
const SERVICE_ROLE_KEY = // Supabase secret key from Settings->API Keys

const supabase = createClient(SUPABASE_URL, SERVICE_ROLE_KEY);

async function migrateUsers(filePath) {
    const users = [];

    // 2. Read and parse the CSV
    fs.createReadStream(filePath)
        .pipe(csv({ separator: ';' })) // Using the semicolon delimiter from your example
        .on('data', (row) => users.push(row))
        .on('end', async () => {
            console.log(`Found ${users.length} users. Starting migration...`);

            for (const user of users) {
                try {
                    // Parse the metadata JSON string
                    const metadata = user.raw_user_meta_data ? JSON.parse(user.raw_user_meta_data) : {};

                    const { data, error } = await supabase.auth.admin.createUser({
                        id: user.id, // Keeps the original ID so your foreign keys don't break
                        email: user.email,
                        password_hash: user.encrypted_password, // Injects the hash directly
                        user_metadata: metadata,
                        email_confirm: true // Prevents sending confirmation emails to everyone
                    });

                    if (error) {
                        console.error(`Error importing ${user.email}:`, error.message);
                    } else {
                        console.log(`Imported: ${user.email}`);
                    }
                } catch (parseError) {
                    console.error(`Failed to parse data for ${user.email}:`, parseError.message);
                }
            }
            console.log('Migration complete!');
        });
}

// Get the filename from the command line argument
const csvFile = process.argv[2];
if (!csvFile) {
    console.log('Usage: node migrate.js your_file.csv');
} else {
    migrateUsers(csvFile);
}


Now run the following SQL query in Lovable Cloud to get the auth information. Export the result as a CSV file using the "Export CSV" button in the UI: 

SELECT id, email, encrypted_password, raw_user_meta_data, created_at FROM auth.users; 

Image 4


After that, you can import the users using the script above:

Shell
 
npm install @supabase/supabase-js csv-parser
node migrate_auth.js query-results-export-....csv


Step 7: Migrate your tables from Lovable Cloud to Supabase (Final Step)

Finally, export each table's data as CSV files:

Image 5


To import the data into your Supabase project, you can use pgAdmin, write a script with psql and the COPY command, or use a tool like Dsync. Here we used Dsync because it automates the whole import task and doesn't require custom scripting or ordering the files with respect to foreign keys in the schema.

Lovable exports CSV files with the naming convention <TABLE_NAME>-export-<DATE>.csv. Rename those files into <TABLE_NAME>.csv and put them into a temporary folder, like /tmp/love-export/public/. The "public" subfolder name will be interpreted by Dsync as the schema name. The file names will be interpreted as table names.

You will also need your new Supabase direct connection string (IPv4 compatible if IPv6 doesn't work):

Image 6


The sample Dsync command:

Shell
 
dsync --mode InitialSync file:///tmp/love-export --delimiter=";" postgresql://postgres....:.....@....:5432/postgres"


Done

After the Dsync command has successfully completed, you should check the tables in Supabase and ensure that they all exist and are populated.

You can now start your project locally, authenticate with the same credentials and see the same data in your app:

Shell
 
npm i
npm run dev


Database Cloud Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • The New Testing Pattern: Standardizing Regression for Cloud Migrations
  • Cost Optimization Strategies for Managing Large-Scale Open-Source Databases
  • Which Tool Is Better for Code Completion — Azure Data Studio or dbForge SQL Complete?
  • Simplify Database Geo-Redundancy Backup With Cloud Storage Services

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook