Skip to the page

Migrating · Migration steps

Moving your users

Import user accounts without migrating password hashes so returning users reclaim their existing rows on first sign-in.

API
—
In the schema
ext::auth::Identity

What you’ll build#

This guide migrates existing user accounts into your Napalm project so every returning user reclaims their owned records at first sign-in. You send zero mass password-reset emails on cutover day, and unclaimed records stay inaccessible to everyone else throughout the migration.

Preload user records

Imported user records store confirmed emails and upstream provider subjects ahead of cutover.

Claim on first sign-in

Returning users link their verified session identity once and access every owned row.

Regardless of your previous database, each existing account imports as a Person row storing its confirmed email address or upstream OAuth subject IDs. When that user signs in to Napalm for the first time, one deployed query links their new ext::auth::Identity to the imported Person row, and every access rule in your schema resolves ownership through that link.

Account data that migrates#

Source account dataMigrates?How Napalm handles it
User accounts and owned recordsYesHow Napalm handles itImport one Person row per user and keep the legacy ID in old_id during migration.
Confirmed email addressesYesHow Napalm handles itStore the lowercased email on Person so a verified email factor claims the account.
Google and GitHub accountsYesHow Napalm handles itStore the upstream OAuth subject ID, which stays constant for the user across apps.
External OIDC accountsYesHow Napalm handles itConfigure the same OIDC issuer on your project so returning users sign in directly.
Password hashesNoHow Napalm handles itNapalm never imports external password hashes. Returning users sign in with an emailed code or set a verified new password.
Phone-only accountsNoHow Napalm handles itBuilt-in sign-in does not send SMS codes. Collect a verified email address before cutover.

Configure sign-in providers#

Enable a sign-in method covering every account type in your existing system. Most migrations enable two flows: your existing OAuth or OIDC provider alongside email magic links for password users.

Terminal
# Google or GitHub users sign in with the same accounts through your OAuth clientnapalm sign-in provider notes google --client-id <client-id> # Existing OIDC providers such as Auth0, Okta or Clerk carry over unchangednapalm sign-in provider notes oidc --issuer-url https://login.example.com --display-name "Example login" --client-id <client-id> # Email verification codes for password users (configure SMTP first with napalm sign-in email)napalm sign-in provider notes magicLink
Google and GitHub
Google and GitHub issue a stable per-user subject ID across applications. Importing that ID lets Napalm match returning users on their first sign-in.
External OIDC provider
Any OpenID Connect provider carries over in place. Import the provider’s issuer URL alongside each user’s sub claim. Each OIDC provider counts as one SSO connection at $30 per month.
Email magic links
Returning users enter their email address and submit the one-time verification code, proving ownership of the address stored on their Person row.
Fresh passwords
Email-and-password sign-up also claims an existing Person row once the user verifies their address. Keep --require-verification enabled so unverified addresses can never claim an imported account.

Sign-in for your app covers the client SDK calls for every provider.

Separate Person rows from auth identities#

Greenfield Napalm schemas often link application records directly to ext::auth::Identity. Migrated apps separate Person from ext::auth::Identity because application rows arrive before users sign in. Domain records link to Person, and Person.identity starts empty until first sign-in.

dbschema/default.gel
type Person {  # Who this is here, once they've signed in. Empty until then.  identity: ext::auth::Identity {    constraint exclusive;  };  # Lowercased. Empty for someone the old system knew only by a provider's account.  email: str {    constraint exclusive;  };  required name: str;   # The old system's id for this row, and the sign-ins it knew this person by. Both go when the move is over.  old_id: str {    constraint exclusive;  };  multi old_sign_ins: str;   access policy self_can_read_and_change    allow select, update    using (.identity ?= global caller);  access policy unclaimed_goes_to_its_person    allow select, update    using (      not exists .identity      and (((.email in global caller_emails) ?? false) or ((global caller_sign_in in .old_sign_ins) ?? false))    );  # A note can't be read without its owner, so the people on a note see each other.  access policy seen_by_people_on_the_same_note    allow select    using (exists (      select (.<owner[is Note] union .<shared_with[is Note])      filter .owner.identity ?= global caller or ((global caller in .shared_with.identity) ?? false)    ));  access policy the_move_can_write    allow all    using (global role ?= 'service');}

On Person, unclaimed_goes_to_its_person governs the one-time claim, while seen_by_people_on_the_same_note lets collaborators on a shared note read each other’s Person records. The claim policy evaluates two verified globals derived directly from the session token.

dbschema/default.gel
# The addresses the caller has confirmed, lowercased.global caller_emails := str_lower((  select ext::auth::EmailFactor  filter .identity ?= global caller and exists .verified_at).email); # The caller's sign-in as the old system would know it: its issuer, a space, its subject.global caller_sign_in := (global caller).issuer ++ ' ' ++ (global caller).subject;
caller_emails
Resolves only to verified email factors on the caller’s identity. Signing up with someone else’s email address without completing verification yields an empty set.
caller_sign_in
Concatenates the issuer and subject claims from the verified token, such as https://accounts.google.com 1167….
role
Grants write access to your migration service key via the branch’s serviceGlobals setting (Billing & payments shows the configuration). Remove the_move_can_write once cutover completes.

Import Person records#

Import users in batches through an idempotent EdgeQL statement that upserts on old_id so retried batches never create duplicate Person rows.

dbschema/move/importPeople.edgeql
# One batch of people from the old system. Sent again, a batch changes nothing it already made.for row in json_array_unpack(<json>$rows)union (  insert Person {    old_id := <str>row['id'],    # An address that's missing or null is left empty.    email := str_lower(<str>json_get(row, 'email')),    name := <str>row['name'],    old_sign_ins := array_unpack(<array<str>>row['sign_ins']),  }  unless conflict on .old_id  else (    update Person set {      name := <str>row['name'],      old_sign_ins := array_unpack(<array<str>>row['sign_ins']),    }  ))

Each user’s sign_ins array stores upstream provider identities formatted as <issuer> <subject>. Platform-specific export scripts appear in Supabase, Firebase, Convex, Gel and Postgres, and Switching over provides the batch sender.

ProviderIssuer stringSubject ID
Googlehttps://accounts.google.comSubject IDThe numeric OAuth sub claim.
GitHubhttps://github.comSubject IDThe numeric GitHub user ID rather than the mutable username.
Custom OIDCThe exact URL passed to --issuer-urlSubject IDThe sub claim issued by that provider.

Claim accounts at first sign-in#

Claiming an imported account takes one parameterless deployed query. Because the unclaimed_goes_to_its_person policy already scopes visibility to the matching unclaimed Person, claimPerson needs no user arguments.

dbschema/queries/claimPerson.edgeql
# Run once after a sign-in. It links the caller to the person moved for them, if there is one they haven't taken.update Personfilter not exists .identityset { identity := global caller }
dbschema/queries/me.edgeql
# The caller's own person: nobody, until they've claimed one.select Person { id, name, email }filter .identity ?= global caller
src/claim.ts
// src/claim.tsimport { call, signIn } from './napalm' // Link the caller's session to any unclaimed Person row after sign-in. Subsequent calls are no-ops.signIn.onChange((session) => {  if (session) void call('claimPerson')})
Idempotent after claim
Once Person.identity is populated, filter not exists .identity matches zero rows, so claimPerson is a no-op on subsequent sign-ins.
Scoped to the caller
An authenticated caller can select or update an unclaimed Person only when a verified email or upstream subject matches. Other unclaimed rows remain invisible.
No identity reassignment
After claiming a row, self_can_read_and_change rejects any update that attempts to point .identity at a different caller.
New users
A user who was not in the legacy database matches zero unclaimed rows, and me returns an empty result so your app can insert a fresh Person record.
Live queries update automatically
Any useLiveQuery subscription opened before claimPerson commits receives the newly claimed rows immediately without a page reload.

Check the claim flow#

Verify all four cases on an isolated branch loaded with imported Person rows before cutover. napalm people reach notes <person> audits exact readable and writable row counts per type for any user.

  1. Sign in as an imported user

    me returns the imported Person, and owned records appear immediately. Signing out and signing back in preserves the linked identity.

  2. Sign up with an imported email without verifying

    me returns zero rows and the Person remains unclaimed until the user completes email verification.

  3. Sign in as a new user

    claimPerson updates zero rows, and querying Person exposes zero unclaimed accounts.

  4. Sign in with a linked OAuth provider

    The user claims their Person row immediately via caller_sign_in, even when the legacy account had no email address on file.

Type a word or two to search every docs page.