Supabase DB Schema Migration

🛠️ Supabase DB Schema Migration (Without Data)

This guide walks you through migrating a database schema only (excluding data) from one Supabase project to another.

⚠️ Prerequisite: Disable RLS (Row Level Security)

Before migrating, disable RLS in both source and destination projects.

Steps:

Open the Supabase dashboard.

Navigate to: Authentication → Policies.

For each table:

Click on the table section (top-right).

Click "Disable RLS".

📤 Step 1: Export the Source DB Schema

Use pg_dump to extract only the schema (no data) from the source database.

✅ Template:

pg_dump --schema-only --no-owner --no-acl --dbname="postgresql://SOURCE_USER:SOURCE_PASSWORD@SOURCE_HOST:PORT/SOURCE_DB" -f schema_dump.sql

📦 Example:

pg_dump --schema-only --no-owner --no-acl --dbname="postgresql://myuser:mypassword@localhost:5432/mydatabase" -f schema_dump.sql

This will create a file named schema_dump.sql containing your schema.

📥 Step 2: Import Schema into Destination DB

Now push the exported schema to the destination Supabase database using psql.

✅ Template:

psql "postgresql://TARGET_USER:TARGET_PASSWORD@TARGET_HOST:PORT/TARGET_DB" -f schema_dump.sql

📦 Example:

psql "postgresql://myuser:mypassword@localhost:5432/targetdb" -f schema_dump.sql

📝 Notes:

You should re-enable RLS after migration.