Skip to content

Recipes

Recipe: Migrating from Supabase

This moves a Supabase project (tables, row-level security, SQL functions and triggers, users, a storage bucket, edge functions) to a Corabase project, locally first and then on Corabase Cloud. Everything is a CLI command. To keep running on the Supabase database instead of leaving it, see Supabase on the existing-database page.

The order matters: generate the tables from the source, then point the project at the target before anything writes.

Introspect the Supabase database, or a local copy of it. SUPABASE_DB_URL below is its direct connection string, as the postgres role (Supabase’s dashboard: Connect → Direct connection); set it in your shell first:

SUPABASE_DB_URL="postgresql://postgres:<password>@db.<project-ref>.supabase.co:5432/postgres"
rebase schema introspect --database-url "$SUPABASE_DB_URL" --from supabase

--from supabase translates what a Corabase database does not have:

In Supabase Written as
owner_id uuid default auth.uid() col.text().onCreateUser().userId(): the server writes the caller’s id
owner_id uuid references auth.users(id) col.text().userId(), and the foreign key listed under “Not carried over”
auth.uid() in a policy rebase.uid()
TO authenticated / TO anon the role is dropped and the rule requires a signed-in / signed-out caller
a policy only TO service_role dropped: server code runs in the server’s own context
plain indexes the table’s indexes

User-id columns become text because rebase.users.id and rebase.uid() are text: a uuid column compared with rebase.uid() in a policy fails.

The run ends with a list of what it did not carry over (functions, triggers, extensions, CHECK constraints, other indexes, composite foreign keys) and writes the SQL for each to backend/sql/_introspected-left-behind.sql, a draft that rebase db push does not apply until you rename it.

DATABASE_URL still names Supabase after step 1, and the introspect output says so. Change it (or remove it, to use the managed development database) before the first push:

rebase db push

Edit backend/sql/_introspected-left-behind.sql the way the tables were edited: auth.uid() → rebase.uid(), auth.users → rebase.users, no GRANT … TO anon, authenticated. Functions that called pg_net are better as a custom function. Make every statement safe to run again (DROP TRIGGER IF EXISTS before each CREATE TRIGGER), then rename the file without the leading _ and push:

mv backend/sql/_introspected-left-behind.sql backend/sql/introspected.sql
rebase db push

rebase db push applies every .sql file in backend/sql in name order, after the tables and before the policies, and records each by hash in rebase.sql_files, so a file runs again only when it changes. A deploy applies them the same way (step 8).

A function the browser called with supabase.rpc('fn') is declared with defineRpc, beside the tables. It is then served at POST /api/rpc/<name> and runs as the caller under row-level security, so a SECURITY DEFINER function behaves as it did on Supabase:

// backend/schema/rpc.ts, exported from backend/schema/index.ts
import { defineRpc, json } from "@rebasepro/server/schema";
export const getPublicProposal = defineRpc("get_public_proposal", {
access: "public", // supabase's anon key; "authenticated" for signed-in only
args: { token: json.string().required() } // validated before the function runs
});
// in the browser: supabase.rpc("get_public_proposal", { token })
const proposal = await rebase.rpc("get_public_proposal", { token });

Only declared functions are callable, and every public one is rate-limited. One that writes needs write: true.

Keep the Supabase user ids, so every owner_id still points at its user: import the users first, with their ids, then the application tables. rebase users import creates the accounts under the ids they had, with their Supabase password hashes when you pass --password-hashes bcrypt, sends no email, and skips one whose id or email is already there, so it can be run again. It reaches Corabase Cloud like every other rebase users command (--project <slug>, or --cloud in a linked directory).

SUPABASE_DB_URL="postgresql://postgres:<password>@db.<project-ref>.supabase.co:5432/postgres"
psql "$SUPABASE_DB_URL" -c "\copy (select id, email, created_at, email_confirmed_at is not null as email_verified, encrypted_password from auth.users) to users.csv csv header"
rebase users import users.csv --password-hashes bcrypt --dry-run
rebase users import users.csv --password-hashes bcrypt
rm users.csv

It reports each account as created, skipped or failed with the reason, and exits 1 when any failed. See Importing accounts for the columns it reads (display_name and roles too).

Then the application tables, with pg_dump against the source and the target. TARGET_URL is the new database’s connection string: your DATABASE_URL, or on Corabase Cloud the connectionString that rebase cloud db connect --reveal prints while it runs.

SUPABASE_DB_URL="postgresql://postgres:<password>@db.<project-ref>.supabase.co:5432/postgres"
TARGET_URL="postgresql://…" # the new database: your DATABASE_URL, or the tunnel's URL on Corabase Cloud
pg_dump "$SUPABASE_DB_URL" --data-only --schema=public --no-owner > data.sql
psql "$TARGET_URL" -f data.sql

Passwords move as their hashes. Supabase stores bcrypt in auth.users.encrypted_password, so each user signs in with the password they already have, under the same id as before, and their first sign-in replaces the hash with Corabase’s own. An account that had no password (magic link, a provider) has an empty encrypted_password and signs in the way it did. Leave the column and the flag out to import without passwords: those users sign in with a magic link, an email code or a password reset.

A public Supabase bucket maps to a storage source with paths under public/, which are served without a token. Copy the objects with any S3 client, keeping their keys.

A Deno edge function becomes a custom function in backend/functions/. The usual substitutions:

Supabase Corabase
Deno.serve(handler) defineFunction((app) => app.post("/", handler))
Deno.env.get("X") requireEnv(c, "X") inside the handler
createClient(url, serviceRoleKey) rebase.dataAsAdmin or rebase.sql on the server
a client with the user’s JWT getSql(c): SQL as the caller, under row-level security
EdgeRuntime.waitUntil(p) waitUntil(c, p) (background work)

Supabase lets an edge function run for 150 s; Corabase’s default is 30 s. A function that calls an LLM declares its own timeout, which the server caps at REBASE_FUNCTIONS_MAX_TIMEOUT_MS (300 s by default):

export default defineFunction((app) => {
app.post("/", handler);
}, { timeoutMs: 150_000 });

Pass getSignal(c) to the fetch that calls the model, so the call stops when the request does. See a function’s own timeout.

Magic-link and email-code sign-in need an email service. Set SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS and SMTP_FROM (rebase cloud env set on Cloud). Without them the route answers 503, and rebase cloud status reports blockedOn: email_not_configured.

rebase cloud projects create --name Triptelier --link
rebase cloud deploy

The deploy applies backend/sql as rebase db push does: the bundle carries the files, and the new revision’s boot runs each new or changed one once, after the tables and before the policies. A file that fails stops the boot and names the file, so a mistake in one shows up in the deploy, not in a running app.