Migrating · Migration steps
Moving with a coding agent
Give a coding agent your existing schema and migration brief, then verify every step with the CLI.
- API
- —
- In the schema
- —
What you’ll build#
You will set up a coding agent to draft and verify your migration. The agent reads exported files from your old system, writes the schema and access rules, turns your app’s data calls into query files and builds the batch import script. You review the output and deploy.
Compiler-checked agent loop
The coding agent translates your exported schema, policies and queries, verifying every statement with check_query before saving.
Branch-scoped key isolation
A branch-bound ndb_… key confines every schema push, test import and reach audit to rehearsal, and main refuses the key outright.
A move suits an agent because a command checks every step. The schema either migrates or fails. A query either compiles against the schema or names the failing line. A count either matches the old system’s count or is off by a number.
Before you start#
Coding agents sets the agent up and describes the agent’s tools. A move adds a separate branch so nothing the agent tries can touch main.
# The agent's instructions, and its connection to the project's MCP servernapalm init notesnapalm endpoint notes --share-schema # A branch for the move, and a key that works there and nowhere elsenapalm branches create notes rehearsalnapalm endpoint notes --branch rehearsal --enable --share-schemanapalm keys create notes --label move-agent --branch rehearsal export NAPALM_KEY=ndb_…export NAPALM_PROJECT_URL=https://<project-address>/branches/rehearsalOn a branch the agent runs statements as text, and a move needs nothing more. Deployed queries live on main, and you deploy those queries yourself.
Hand the agent the old system#
Put the exported files in a folder named old. None of the files holds a row or a secret.
| Coming from | What to export | Tells the agent |
|---|---|---|
| Postgres | pg_dump --schema-only --no-owner, the ORM’s schema file and the code that runs queries | Tells the agentTables, keys and constraints. The checks are in the code. |
| Supabase | supabase db dump --schema public and supabase/functions | Tells the agentTables and RLS policies. The policies hold the rules. |
| Firebase | firestore.rules, storage.rules, firestore.indexes.json, functions/ and a few hundred documents of each collection as JSON | Tells the agentThe rules and the real contents of a document. Firestore has no schema to read. |
| Convex | The convex/ folder | Tells the agentTables in schema.ts. The checks are at the top of each function. |
| Gel | dbschema/ and the files that hold EdgeQL | Tells the agentEverything. The agent writes rules for open types and a file for each statement. |
For Postgres and Supabase, draft a schema from the dump. For an app on Prisma, draft from the app’s schema.prisma. For Convex, draft from convex/schema.ts. Put the draft in the same folder so the agent starts from a typed schema. Each draft: comment names one item the command left for the agent. How a schema is translated shows the rules every draft follows.
# Postgres or Supabase: a first schema for the agent to refinenapalm schema draft --from old/old-schema.sql -o old/draft.gel # Prisma: the same, from the app's own schemanapalm schema draft --from prisma/schema.prisma -o old/draft.gel # Convex: the same, from convex/schema.tsnapalm schema draft --from convex/schema.ts -o old/draft.gelGive the agent the brief#
Paste the brief below as the task. Change the project and branch names to yours. Each page of the Napalm docs has a Markdown copy at the page’s address plus .md, and the brief points the agent at those copies.
Move this app's database to Napalm. The old system is described by the files in old/.Work on the branch "rehearsal" of the project "notes". Never push to main. 1. Write dbschema/default.gel from the old tables or collections. - For Postgres, Supabase, Prisma or Convex, start from old/draft.gel, which napalm schema draft wrote, and resolve every comment that starts with draft:. - A foreign key or a stored id is a link. A join table or an array of ids is a multi link. - Every type keeps the old system's id in old_id (str, exclusive). - People are a Person type with an optional identity link, an optional email and old_sign_ins, as https://napalmdata.com/developers/migrating/moving-users.md has them.2. Give every type its access rules. For each one, name the place in old/ the rule came from: a policy, a security rule, or a check in a function. A type with no rule is closed. Say so when you mean it.3. Put each read and write the app makes in dbschema/queries, one statement a file, named for what it does. A query never takes "who is asking" as a variable: it reads global caller.4. Put the move's own statements in dbschema/move: one per type, taking <json>$rows, writing by old_id with "unless conflict on .old_id else (update …)". Parents before children.5. Write the reader for this source in scripts/, as the page for it does: https://napalmdata.com/developers/migrating/switching-over.md6. Before saving any statement, compile it with the check_query tool. Prove each step with the commands in "The commands that prove each step", and show their output.When the old system does something a statement can't (a trigger, a stored procedure, an offlinewrite, a password), stop and list it. Don't approximate it.Don't write a key, a connection string or a password into any file.- Rule sources
- Requiring a source comment on each rule keeps the output auditable. You can compare every policy directly against the check it replaces and spot any rule the agent invented.
- No approximations
- The hardest part of a migration is behavior with no direct counterpart, such as triggers or stored procedures. An explicit list of gaps is far safer than a schema that quietly drops unsupported logic.
- Project conventions
napalm initwrites the project’s conventions toAGENTS.md: EdgeQL and never SQL, rules in the schema, values as parameters andcheck_querybefore a statement is saved.
Prove each step with a command#
| Step | Command | Passes when |
|---|---|---|
| The schema | napalm schema push notes --branch rehearsal --plan | Passes whenThe command prints a plan with every type the old system had. |
| One statement | The check_query tool | Passes whenThe tool says whether the statement reads or writes, or names the problem on an error. |
| The app’s queries | napalm queries push notes --branch rehearsal | Passes whenEvery file compiles against the branch’s schema. |
| The move’s statements | napalm queries push notes --queries dbschema/ | Passes whenEvery file in the never-deployed folder compiles. |
| The rules | napalm keys reach notes --new --branch rehearsal | Passes whenA key reaches the rows the move needs. A type you meant to close counts zero rows. |
| The rows | The reader, run twice | Passes whenBoth runs print the old system’s counts. |
| One person | napalm people reach notes <person> --branch rehearsal | Passes whenSomeone who signed in on the branch reads only that person’s rows and no one else’s. |
Keep four things yourself#
- Secrets
- The old database’s connection string and the move’s key go in your shell’s environment. The agent runs the reader, and the reader reads both values from the environment.
- main
- The agent’s service key is bound to
rehearsal, somainrefuses it. In your terminal, however, the CLI runs with your org token, so only the brief and your command approvals stop a push tomain. Run the final push tomainyourself. - Reading the rules
- Every rule controls access to someone’s data. Read each rule beside its source in
old/before pushing tomain, even when every check passes. - The switch
- Pausing the old system and releasing the app is your decision. Switching over has the order of steps.
Check the agent’s work#
Ask the agent what the old system has
The agent answers from the files in
oldand names the tables or collections that will become types.Call main with the agent’s key
mainrefuses the call. The key reads and writes the branch and nothing else.Read the agent’s list of things that cannot move
The list is not empty for any real app. A trigger, a password column or an offline write should be on the list.
Run the table above yourself
Each command prints the output the agent showed you.