Skip to the page

Migrating · Platform guides

Coming from Supabase

Turn RLS policies into access rules, auth.users into people who sign in here and Storage buckets into file types.

API
—
In the schema
ext::files::File

What you’ll move#

A notes app on Supabase: profiles that hang off auth.users, notes with an RLS policy each, shares in a join table and files in a Storage bucket. The browser talks to Supabase with supabase-js.

In SupabaseIn Napalm
RLS policies on a tableAccess rules written on a type
auth.users and auth.uid()The project’s sign-in and global caller
The service_role key, which skips RLSA service key with only the access granted to its role
A bucket and policies on storage.objectsA file type under the record’s rules
supabase.from(…).select(…) from the browserDeployed queries called by name with typed variables
Realtime’s Postgres ChangesA live query on any deployed read
Database functions and rpc()Deployed queries
Edge FunctionsActions and jobs
pg_cronSchedules

Before you start#

You need a project made in the console and the napalm CLI signed in. Column types follow the Postgres translation table.

Terminal
# The tables and the policies, to write the schema fromsupabase db dump --schema public -f old-schema.sql # A first schema, drafted from that file into dbschema/default.gelnapalm schema draft --from old-schema.sql # A branch to work onnapalm branches create notes rehearsalnapalm schema push notes --branch rehearsal

The draft holds a type for each table and a closed rule for each policy. A comment above each rule holds the policy’s SQL, and the next section writes the conditions into the rules. Translating a Postgres schema shows how the command translates the dump.

Turn RLS policies into access rules#

In the old app, three RLS policies guard notes and shares. Because the third policy reads notes while the notes policy reads note_shares, Postgres stops with infinite recursion detected in policy for relation "notes". The usual workaround is a security definer function that bypasses RLS altogether.

Link-aware rules without recursion

Rules follow links directly without triggering policy recursion or needing security definer bypasses.

Native sign-in and caller binding

Sessions bind global caller automatically so Google, GitHub and email sign-ins reclaim existing rows.

Before: policies on two tables
alter table public.notes enable row level security;alter table public.note_shares enable row level security; create policy "Authors manage their notes" on public.notes  for all to authenticated  using ((select auth.uid()) = author_id); create policy "People a note is shared with read it" on public.notes  for select to authenticated  using (exists (    select 1 from public.note_shares s    where s.note_id = notes.id and s.person_id = (select auth.uid())  )); -- Reads notes, whose policy reads note_shares: "infinite recursion detected in policy for relation notes".create policy "Authors manage a note's shares" on public.note_shares  for all to authenticated  using (exists (    select 1 from public.notes n    where n.id = note_shares.note_id and n.author_id = (select auth.uid())  ));

In Napalm, the join table becomes a link, and the rules sit directly on the type holding that link.

dbschema/default.gel
type Note {  required owner: Person;  multi shared_with: Person;  required title: str;  required body: str;  required created: datetime {    default := datetime_current();  };  old_id: str {    constraint exclusive;  };   access policy owner_has_full_access    allow all    using (.owner.identity ?= global caller);  access policy shared_with_can_read    allow select    using ((global caller in .shared_with.identity) ?? false);  access policy the_move_can_write    allow all    using (global role ?= 'service');}
No recursion
A rule reads another type without re-running that type’s rules, so two types can freely reference each other.
Closed by default
A table without enable row level security is open to everyone holding the anon key. A type without a rule is closed to everyone.
No bypass
There is no service_role and no security definer. A backend reads and writes under a rule naming its role, and napalm keys reach counts the rows that rule reaches.
Policy roles
(select auth.uid()) becomes global caller. to authenticated becomes a rule requiring a caller. to anon becomes a rule with no condition.

Replace auth.users with people who sign in here#

A profile keyed by auth.users.id becomes a Person with no sign-in until the user returns. The reader below carries each person’s email address alongside their Google and GitHub accounts from auth.identities.

Google and GitHub
The same Google or GitHub account signs the person straight in with their notes intact and no verification email required.
Email and password
Passwords stay in Supabase. People return with a one-time code sent to their email address.
Magic links
Napalm sends emailed codes or links natively. An unknown address can either create a new account or be turned away.
Phone and anonymous
Napalm has neither. The reader skips any account with no email address.
The trigger on auth.users
Drop the trigger, because nothing needs copying at sign-up. Your app creates a person row the first time a new caller signs in.

Moving your users has the schema, the claim query and the commands that enable each sign-in method.

Move the rows#

The reader uses the database’s direct connection string so it can read the auth schema that the Supabase API hides. It hands rows to the sender from Switching over.

scripts/from-supabase.ts
// scripts/from-supabase.tsimport pg from 'pg'import { move } from './send' // The database's own connection string, from the Supabase dashboard: it reads auth.users, which the API doesn't.const old = new pg.Client({ connectionString: process.env.OLD_DATABASE_URL }) /** A table's rows in the order of their ids, a thousand at a time, so nothing large is held or locked. */async function* pages(sql: string) {  let after = ''  for (;;) {    const { rows } = await old.query(sql, [after])    if (rows.length === 0) return    yield* rows    after = rows[rows.length - 1].id  }} await old.connect()// People first: a note names its owner. Each comes with the Google and GitHub accounts Supabase knew them by.await move(  'importPeople',  pages(`    select u.id::text, u.email, coalesce(p.name, u.email) as name,           coalesce(array_agg(case i.provider             when 'google' then 'https://accounts.google.com ' || i.provider_id             when 'github' then 'https://github.com ' || i.provider_id           end) filter (where i.provider in ('google', 'github')), '{}') as sign_ins    from auth.users u    left join public.profiles p on p.id = u.id    left join auth.identities i on i.user_id = u.id    where u.id::text > $1 and u.email is not null    group by u.id, p.name    order by u.id::text    limit 1000`),)await move(  'importNotes',  pages(`    select n.id::text, n.author_id::text as owner_id, n.title, n.body, n.created_at,           coalesce(array_agg(s.person_id::text) filter (where s.person_id is not null), '{}') as shared_with    from public.notes n    left join public.note_shares s on s.note_id = n.id    where n.id::text > $1    group by n.id    order by n.id::text    limit 1000`),)// Files' records last: each names its object by the path it has in the bucket.await move(  'importAttachments',  pages(`    select id::text, note_id::text, path as key, name    from public.attachments    where id::text > $1    order by id::text    limit 1000`),)await old.end()
Terminal
npm install pg tsxOLD_DATABASE_URL=postgres://postgres:…@db.<project-ref>.supabase.co:5432/postgres \NAPALM_URL=https://<project-address>/branches/rehearsal NAPALM_KEY=ndb_… \  npx tsx scripts/from-supabase.ts

Turn buckets into file types#

Bucket policies have to slice object paths to infer the owner. In Napalm, a file is a record on the note, so the note’s own rules govern who can read or delete it.

File records under the owning type’s rules

Napalm replaces bucket path-slicing policies by importing bytes directly from S3-compatible storage into rule-checked records.

dbschema/default.gel
# A file on a note. Whoever may read the note may have the file.type Attachment extending ext::files::File {  required note: Note;  # The object's key in the old store, which the import copies it by.  old_key: str {    constraint exclusive;  };   access policy note_owner_has_full_access    allow all    using (.note.owner.identity ?= global caller);  access policy shared_with_can_read    allow select    using ((global caller in .note.shared_with.identity) ?? false);  access policy the_move_can_write    allow all    using (global role ?= 'service');}

The reader’s final pass creates a record holding each file’s bucket path. Because Supabase Storage is S3-compatible, Napalm copies the bytes directly.

dbschema/move/importAttachments.edgeql
# One batch of files' records, each on its note. The bytes come after: Napalm copies them by the key a row names.for row in json_array_unpack(<json>$rows)union (  insert Attachment {    old_key := <str>row['key'],    note := assert_exists((select Note filter .old_id = <str>row['note_id'])),    file_name := <str>row['name'],  }  unless conflict on .old_key)
Terminal
# An S3 access key for the project's storage, from the Supabase dashboard. Count and sample first.export NAPALM_SOURCE_SECRET_ACCESS_KEY=…napalm files store import notes --endpoint https://<project-ref>.supabase.co/storage/v1/s3 \  --region <project-region> --path-style --access-key-id <key-id> \  --map type=default::Attachment,key=old_key,bucket=attachments --plan
The real copy
Run the same command without --plan to confirm and start the import. napalm files store ls notes lists files imported, missing and refused.
Checks during the copy
Napalm records each object’s size and sniffs the format from the opening bytes. A constraint on file_format lets a type refuse disallowed formats.
Signed URLs
A query selecting file_url returns a signed link for every file the caller may read. Files & uploads covers uploads from the app.

Move realtime, functions and cron#

Postgres Changes
A table channel sends raw row deltas and leaves the app to reconstruct screen state. A live query keeps a deployed read’s complete result current as the signed-in user, including joins, filters and access rules.
Broadcast and Presence
Client-to-client broadcast channels have no separate API yet. Show active viewers builds presence directly with rows.
rpc() and functions
A database function becomes a deployed query: its arguments become variables, and security definer becomes an access rule.
Edge Functions
An Edge Function holding a secret such as a payment key becomes an action: a deployed query selects only the records the caller may reach, and a handler you host does the external call. An Edge Function triggered after a write becomes a job.
pg_cron
napalm schedules add puts a deployed query on a schedule, running it under a dedicated key.
Database webhooks
A notify declaration on a type emits a signed webhook after each commit touching that type. Webhooks covers delivery and retries.

Check the move#

  1. Run the reader twice against the branch

    The second run prints identical counts, matching Supabase’s counts after every run.

  2. Read a shared note as both people

    After both users sign in, run napalm people reach for the note’s author and for a person on its share list. Neither needs a bypass function to get past the other’s rule.

  3. Sign in with Google as a moved person

    Their notes appear immediately without sending an email or prompting for a password.

  4. Run the store import with --plan

    The plan counts every record waiting for bytes and verifies a sample of their objects in the bucket.

Type a word or two to search every docs page.