Migrate from Supabase
potalab base migrate supabase moves a Supabase project into a Base project. It needs Node 22 or newer and Docker (it runs pg_dump and psql from the Base Postgres image, nothing is installed on the host).
It migrates, in this order: extensions, the schema (public and every user schema), auth.users, table data, the realtime publication and storage objects. Always start with --dry-run.
export SUPABASE_DB_URL='postgresql://postgres:<pw>@db.<ref>.supabase.co:5432/postgres' # Project settings > Databaseexport BASE_DB_PASSWORD='<owner or superuser password of the Base project database>'
# 1. Read-only report. The schema is also tried on the target inside a transaction that is rolled back.potalab base migrate supabase --dry-run --db-url postgresql://postgres@host:5432/<project_db> \ --owner-role '<project_db>.owner' --supabase-dir ./supabase --report migration-report.json
# 2. Apply (the target must be an empty project: no tables in the schemas that are migrated)potalab base migrate supabase --yes --db-url postgresql://postgres@host:5432/<project_db> --owner-role '<project_db>.owner'Options
Section titled “Options”| Option | Meaning |
|---|---|
--source-db-url |
Supabase connection string (or SUPABASE_DB_URL). Use the direct connection, not the transaction pooler. |
--db-url / --local |
Target Base project database. --local uses the stack of potalab base start. BASE_DB_PASSWORD supplies the password. |
--owner-role |
SET ROLE for the schema and data steps, so tables are owned by the project owner role like in production. |
--owner-db-url |
Project owner connection (<db>.owner, never a superuser) used to create the storage policies. Also BASE_OWNER_DB_URL. Default: the schema connection; a superuser connection is refused for this step. |
--schema a b |
Only these schemas (default: all user schemas). |
--only schema,data,auth,storage |
Run only some parts. Storage needs no database connection. |
--dry-run / --yes |
Report only / confirm the write. |
--supabase-url, --supabase-service-key |
Storage source (SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY). |
--base-url, --base-secret-key, --base-publishable-key |
Storage target: the project API URL and keys (BASE_URL, BASE_SECRET_KEY, BASE_PUBLISHABLE_KEY). |
--supabase-dir |
The app’s supabase/ folder: lists Edge Functions and enabled auth hooks in the report. |
--report file |
Also write the report as JSON (--json prints it on stdout). |
What is mapped
Section titled “What is mapped”| Supabase | Base |
|---|---|
Schemas auth, storage, realtime, extensions, graphql*, vault, supabase_*, net, cron, pgsodium* |
Never dumped. Base has its own. |
public and user schemas (tables, views, functions, triggers, RLS, policies) |
Applied as is. auth.uid(), auth.jwt(), auth.role() exist in Base and foreign keys to auth.users(id) stay valid. |
Roles anon, authenticated, service_role |
Same names in Base. |
Roles postgres, supabase_admin, authenticator, supabase_*_admin |
Removed from grants and policies. Ownership becomes the target role. |
Publication supabase_realtime |
Its tables are added to base_realtime. |
| Extensions | Allowlisted ones are enabled, including the compatibility shims pg_net, supabase_vault and pg_cron_compat. The rest are reported. |
auth.users |
The id is kept (RLS and foreign keys stay valid), plus email, metadata, creation and last sign-in time. A ban (banned_until) becomes a Base ban (see ban_duration in the Admin API). |
| Passwords | bcrypt hashes are copied. Base verifies them, so users sign in with their old password; the hash is upgraded to scrypt on the next password change. |
auth.identities |
auth.accounts rows. Configure the OAuth provider in Base; tokens are not copied. |
| Storage buckets and objects | Same id, public flag, size limit and MIME types; objects are downloaded and uploaded again. |
Storage policies (storage.objects) |
Imported when every part of the policy has a Base equivalent, see Storage policies. |
Storage policies
Section titled “Storage policies”After the storage step, each policy on Supabase storage.objects is translated and created on Base storage.objects as the project owner. Nothing is granted.
- Kept as in the source:
AS PERMISSIVE/AS RESTRICTIVE, the command (FOR SELECT…),USINGandWITH CHECK. The policy name is quoted when needed. - Columns:
namebecomespath,owner(uuid) becomesowner_id(uuid),owner_id(text in Supabase) becomesowner_id::text,bucket_idandmetadataare unchanged. Soauth.uid() = ownerandauth.uid()::text = owner_idkeep their meaning. - Allowed in the expressions:
auth.uid(),auth.jwt(),auth.role(),storage.foldername(),storage.filename(),storage.extension(),lower,upper,split_part,starts_with, comparisons,AND/OR/NOT,IS NULL,IN (...),= ANY(...),LIKE/ILIKE,->/->>,||, array indexes,CASE,COALESCEand casts totext,uuid,jsonb,json,boolean,integer,bigint,varchar. Expressions are checked with the Postgres parser, not by text matching. - Roles:
anonandauthenticated. A policy withoutTO(PUBLIC) becomesTO anon, authenticated(Base accepts only these two roles onstorage.objects). - Each
CREATE POLICYis first tried in a transaction that is rolled back, then applied. A policy with the same name on the target is left unchanged and reported.
A policy is reported, not applied, when it uses a subquery (EXISTS, IN (SELECT ...)), any other function (including your own), another column, another role (service_role, postgres, …) or when Postgres refuses it. The report gives the reason and, when available, the translated SQL to review.
Fail closed. If a RESTRICTIVE policy is not imported, no permissive policy of the same bucket is imported either (all buckets when the bucket cannot be read from bucket_id = '...'): access would otherwise be wider than on Supabase. The report marks these as blockers. Recreate the restrictive policy by hand, then the permissive ones.
--dry-run lists every policy as apply or report with its reason, and validates the apply ones on the target when one is given.
Not migrated
Section titled “Not migrated”The dry-run report lists these with the Base alternative: extensions that are not allowlisted, Edge Functions (port them to Functions), auth hooks (Auth hooks) and storage policies that could not be imported (see below). Sessions and refresh tokens (users sign in again), MFA factors, phone numbers, SSO users, non-bcrypt hashes and Vault secrets are not copied.
Switch the app to the Base SDK
Section titled “Switch the app to the Base SDK”The query API has the same shape. Replace the Supabase client:
import { createClient } from '@potalab/base'
const base = createClient({ url: process.env.BASE_URL!, key: process.env.BASE_PUBLISHABLE_KEY! })
const { data } = await base.from('todos').select('*').eq('done', false)await base.auth.signInWithPassword({ email, password }) // existing users keep their passwordServer code that used the service key keeps the name base: createClient({ url, key: process.env.BASE_SERVICE_KEY }).
For public buckets, base.storage.from('avatars').getPublicUrl('logo.png').data.publicUrl works as an <img src>; see Storage. Inside a function, ctx.admin reaches auth.admin.* and storage of the same project.
After the import
Section titled “After the import”- Run the command again with
--dry-run: the schema validation line must sayok. - Sign in with an existing user, then run
potalab base test rls(RLS testing). - Run
potalab base lintto find tables that RLS no longer covers.