Skip to content

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.

Terminal window
export SUPABASE_DB_URL='postgresql://postgres:<pw>@db.<ref>.supabase.co:5432/postgres' # Project settings > Database
export 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'
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).
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.

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 …), USING and WITH CHECK. The policy name is quoted when needed.
  • Columns: name becomes path, owner (uuid) becomes owner_id (uuid), owner_id (text in Supabase) becomes owner_id::text, bucket_id and metadata are unchanged. So auth.uid() = owner and auth.uid()::text = owner_id keep 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, COALESCE and casts to text, uuid, jsonb, json, boolean, integer, bigint, varchar. Expressions are checked with the Postgres parser, not by text matching.
  • Roles: anon and authenticated. A policy without TO (PUBLIC) becomes TO anon, authenticated (Base accepts only these two roles on storage.objects).
  • Each CREATE POLICY is 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.

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.

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 password

Server 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.

  1. Run the command again with --dry-run: the schema validation line must say ok.
  2. Sign in with an existing user, then run potalab base test rls (RLS testing).
  3. Run potalab base lint to find tables that RLS no longer covers.