Skip to the page

Migrating · Platform guides

Coming from Convex

Turn Convex tables into types, each function’s checks into rules and query and mutation functions into deployed queries.

In the schema
—

What you’ll move#

A notes app on Convex: tables in convex/schema.ts, query and mutation functions that check the caller before touching a table and React components that stay current through useQuery.

In ConvexIn Napalm
defineTable and v.id(…)A type and a link to another type
A check at the top of each functionAn access rule on the type, written once
A query functionA deployed query with one statement in one file
A mutation functionA deployed query that writes and commits whole or not at all
useQueryuseLiveQuery
An actionAn action (a deployed query and a handler you host)
ctx.scheduler and crons.tsJobs and schedules
File storageA file type under the record’s rules
Clerk or Auth0 through auth.config.tsThe same provider through the project’s sign-in

Before you start#

You need a project created in the console and the napalm CLI signed in. The largest shift is where logic runs. A Convex function runs TypeScript beside the data across several reads, while a Napalm deployed query executes one statement inside the database. Most functions combine a read, a check and a write, and one statement handles all three. Code calling external services stays TypeScript and runs in a handler.

Turn tables into types#

napalm schema draft --from convex/schema.ts writes an initial dbschema/default.gel from your Convex schema. Translating a Convex schema details how each definition maps over.

Draft types directly from convex/schema.ts

Tables and v.id references become typed links with automatic join indexes.

Before: convex/schema.ts
// convex/schema.tsimport { defineSchema, defineTable } from 'convex/server'import { v } from 'convex/values' export default defineSchema({  users: defineTable({    tokenIdentifier: v.string(),    email: v.string(),    name: v.optional(v.string()),  }).index('by_token', ['tokenIdentifier']),  notes: defineTable({    ownerId: v.id('users'),    sharedWith: v.optional(v.array(v.id('users'))),    title: v.string(),    body: v.string(),  }).index('by_owner', ['ownerId']),})

A v.id becomes a link, and an array of ids becomes a link to many. Drop the Convex indexes, because links are indexed automatically and sign-in handles the users table’s by_token lookup on its own.

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');}

Move each function’s checks into rules#

Before: convex/notes.ts
// convex/notes.tsimport { query } from './_generated/server' export const list = query({  args: {},  handler: async (ctx) => {    // Every function works out who is asking, and what they may see, for itself.    const identity = await ctx.auth.getUserIdentity()    if (!identity) return []    const user = await ctx.db      .query('users')      .withIndex('by_token', (q) => q.eq('tokenIdentifier', identity.tokenIdentifier))      .unique()    if (!user) return []    const mine = await ctx.db      .query('notes')      .withIndex('by_owner', (q) => q.eq('ownerId', user._id))      .collect()    const others = await ctx.db.query('notes').collect()    return [...mine, ...others.filter((note) => note.sharedWith?.includes(user._id))]  },})

The first half of that function resolves the caller, and the second half checks which notes they may see. Every other function touching notes repeats both halves. In Napalm, both halves become the two rules on Note, leaving the query clean.

dbschema/queries/myNotes.edgeql
# The notes the caller owns or was given. The rules decide which: the query doesn't say.select Note { id, title, body, created, is_mine := .owner.identity ?= global caller }order by .created desc
Written once
A rule applies to every query, live query and search, including queries added later by teammates who never read the rule.
In the database
A Convex function that forgets its check exposes all rows. A Napalm type with no rule returns nothing.
The caller
ctx.auth.getUserIdentity() becomes global caller. The project reads the caller directly from the session without looking up a users table.

Turn functions into deployed queries#

Query and mutation functions each become a single statement: arguments become typed variables, authorization moves into the access rule and useLiveQuery keeps read results current.

One atomic statement per query

Reads, access checks and multi-type writes collapse into one deployed .edgeql file with typed SDK calls.

Commit-aligned live queries

Every useLiveQuery on a screen advances together to the same commit.

dbschema/queries/addNote.edgeql
# A note of the caller's own. Someone with no person yet has no owner to give it, and it's refused.insert Note {  owner := assert_exists(assert_single((select Person filter .identity ?= global caller))),  title := <str>$title,  body := <str>$body,}
src/NoteList.tsx
// src/NoteList.tsximport { deployed } from 'napalm-client'import { useLiveQuery } from 'napalm-client/react' type Note = { id: string; title: string; body: string; created: string; is_mine: boolean } /** dbschema/queries/myNotes.edgeql, by its name. */const myNotes = deployed<Note, Record<string, never>>('myNotes') export function NoteList() {  // As useQuery(api.notes.list) was: the rows, kept current.  const { rows } = useLiveQuery(myNotes, {})  return (    <ul>      {rows?.map((note) => (        <li key={note.id}>{note.title}</li>      ))}    </ul>  )}
Reactivity
A Convex query reruns whenever data it read changes. A live query updates when a commit changes its result, and every live query on a page advances to the same commit together.
Types
napalm generate emits a typed call and hook for each query to replace api.notes.list. TypeScript shows both.
Optimistic updates
Screens can render a write before it commits. Realtime & collaboration builds that pattern.
Logic that loops
A function that reads, branches in TypeScript and reads again becomes one statement with a subquery or two calls. Logic a statement cannot express runs in a handler.

Move the documents#

An export writes each table as a file of documents. The reader shapes each document into the row the import statement expects and passes batches to the sender from Switching over.

scripts/from-convex.ts
// scripts/from-convex.tsimport { createReadStream } from 'node:fs'import { createInterface } from 'node:readline'import { move } from './send' /** One table of `npx convex export`, unzipped: a document a line. */async function* table(name: string): AsyncGenerator<Record<string, any>> {  const lines = createInterface({ input: createReadStream(`export/${name}/documents.jsonl`) })  for await (const line of lines) if (line.trim()) yield JSON.parse(line)} /** Each document as the import statement reads a row. */async function* shaped<Row extends object>(name: string, shape: (document: Record<string, any>) => Row) {  for await (const document of table(name)) yield shape(document)} // People first: a note names its owner. A document's _id is its old id, and _creationTime is in milliseconds.await move(  'importPeople',  shaped('users', (user) => ({    id: user._id,    email: user.email,    name: user.name ?? user.email,    // Convex writes who someone is as "issuer|subject". Napalm's rule reads the two with a space between.    sign_ins: user.tokenIdentifier ? [user.tokenIdentifier.replace('|', ' ')] : [],  })),)await move(  'importNotes',  shaped('notes', (note) => ({    id: note._id,    owner_id: note.ownerId,    shared_with: note.sharedWith ?? [],    title: note.title,    body: note.body,    created_at: new Date(note._creationTime).toISOString(),  })),)
Terminal
# Every table as a file of documents, one a linenpx convex export --path export.zipunzip export.zip -d export npm install tsxNAPALM_URL=https://<project-address>/branches/rehearsal NAPALM_KEY=ndb_… npx tsx scripts/from-convex.ts

Each export captures a single snapshot. For the final pass, pause writes, export again and run the reader from the top. Rows already moved overwrite cleanly with the same values.

Move sign-in, files and scheduled work#

Sign-in
Keep your provider. napalm sign-in provider notes oidc with the provider’s issuer signs the same users in and counts as one SSO connection. Each tokenIdentifier carried by the reader maps to the same person in Napalm. Moving your users has the claim query.
Files
Give each file a record holding the URL returned by ctx.storage.getUrl, then run napalm files import to fetch and verify each file. Files & uploads covers the type.
Actions
Code calling a payment or email provider becomes a handler you host, fronted by a deployed query that selects only the records the caller may reach. Actions defines the contract.
Scheduled functions
ctx.scheduler.runAfter becomes a job queued inside the statement’s commit. A cron becomes napalm schedules add.
Search
Search and vector indexes become indexes declared on the type. Search covers both.

Check the move#

  1. Run the reader twice against a branch

    Both runs print identical counts matching the export’s line counts.

  2. Sign in through your provider as a moved person

    Both their own notes and the notes shared with them are waiting.

  3. Add a note in one window

    Open a second window signed in as the same person, and the list updates live without a reload.

  4. Add a note as someone the move never brought

    Napalm refuses the write because the caller has no person record to own the note yet.

Type a word or two to search every docs page.