Skip to the page

Migrating · Migration steps

Moving with a coding agent

Give a coding agent your existing schema and migration brief, and verify every step with the CLI.

API
—
In the schema
—

What you’ll build#

This guide sets up a coding agent to draft and verify your migration on an isolated branch. Your agent reads exported schema and rule files from the legacy system, writes dbschema/default.gel and access policies, converts data calls into .edgeql query files and builds the batch export script while you review the diffs and run final cutover.

Compiler-checked agent loop

Your coding agent translates schemas, policies and queries against live compiler feedback.

Branch-scoped key isolation

A branch-bound service key confines every test import to rehearsal while protecting main.

Migrations suit coding agents well because deterministic CLI checks gate every step: schemas either compile and migrate cleanly or fail with a line error, queries type-check against the branch schema and imported row counts match your source totals.

Before you start#

Coding agents covers project MCP setup and agent tooling. For a migration, create a dedicated rehearsal branch and a branch-bound service key so agent experiments can never touch main.

Terminal
# Configure agent instructions and connect your project's MCP servernapalm init notesnapalm endpoint notes --share-schema # Create an isolated rehearsal branch and a branch-scoped service keynapalm 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/rehearsal

On rehearsal, the agent executes EdgeQL statements as text over HTTPS. Named deployed queries live on main, which you push yourself after reviewing the branch.

Export files from your old stack#

Place exported schema, policy and function files into an old/ directory containing zero customer rows or credentials.

Source stackFiles to export into old/What the agent learns
Postgrespg_dump --schema-only --no-owner, your ORM schema and data-access modulesWhat the agent learnsTable definitions, foreign keys and the application-layer authorization checks to turn into access rules.
Supabasesupabase db dump --schema public and supabase/functionsWhat the agent learnsTables, constraints and the SQL RLS policies that translate into schema rules.
Firebasefirestore.rules, storage.rules, firestore.indexes.json, functions/ and redacted JSON document samplesWhat the agent learnsSecurity rules alongside real document shapes, since Firestore has no static schema file.
ConvexThe convex/ directoryWhat the agent learnsTable validators in schema.ts and the per-function authorization checks to lift into rules.
Geldbschema/ and application files containing EdgeQLWhat the agent learnsExisting object types, inline queries to extract into .edgeql files and open types needing access rules.

For Postgres, Supabase, Prisma or Convex, generate an initial draft with napalm schema draft into old/draft.gel so the agent starts from compiled EdgeQL types and a checklist of # draft: comments. How a schema is translated explains every generated construct.

Terminal
# Postgres or Supabase: generate an initial schema draft to refinenapalm schema draft --from old/old-schema.sql -o old/draft.gel # Prisma: generate a draft from your Prisma schemanapalm schema draft --from prisma/schema.prisma -o old/draft.gel # Convex: generate a draft from convex/schema.tsnapalm schema draft --from convex/schema.ts -o old/draft.gel

Give the agent the migration brief#

Paste the prompt below into your coding agent, substituting your project slug and branch name. Every Napalm documentation page also serves a plain Markdown copy at its URL plus .md, which the brief links directly.

Migration brief
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, generated by     napalm schema draft, and resolve every comment that starts with draft:.   - Convert foreign keys and stored IDs into links, and join tables or ID arrays into multi links.   - Every type keeps the old system's id in old_id (str, exclusive).   - Model users with a Person type holding an optional identity link, an optional email and     old_sign_ins, following https://napalmdata.com/developers/migrating/moving-users.md.2. Add access rules to every type. Above each policy, cite the source file in old/ that the   rule replaces (an RLS policy, security rule or handler check). A type with no rule is closed.   Add a comment when leaving a type closed intentionally.3. Put each application read and write in dbschema/queries, one statement per file, named for   the operation. Queries never accept a caller ID parameter and read global caller instead.4. Put batch import statements in dbschema/move: one file per type accepting <json>$rows and   upserting on old_id with "unless conflict on .old_id else (update …)". Import parents first.5. Write the export script for this source database in scripts/, following   https://napalmdata.com/developers/migrating/switching-over.md.6. Compile every EdgeQL statement with the check_query tool before saving it. Verify each step with the commands in "Verify each step with a command" and show the output.When the old system relies on behavior a single statement cannot express (triggers, storedprocedures, offline write queues or password hashes), stop and list each item instead ofapproximating. Never write a service key, connection string or password into any file.
Traceable rule comments
Requiring a comment above each access policy naming its legacy source file lets you audit every rule side by side and spot invented permissions immediately.
Explicit gap reporting
Procedural triggers, custom extensions and password columns have no silent 1-to-1 translation. Instructing the agent to stop and list unsupported constructs prevents silent behavioral regressions.
Generated AGENTS.md rules
napalm init writes Napalm’s repository conventions into AGENTS.md: EdgeQL only, declarative schema access rules, parameterized inputs and check_query verification before saving any .edgeql file.

Verify each step with a command#

Every step of the brief pairs with a CLI or MCP check that returns a deterministic pass or fail result.

StepVerification commandPassing result
Schemanapalm schema push notes --branch rehearsal --planPassing resultPrints a clean migration plan covering every expected object type.
Individual statementMCP check_query toolPassing resultConfirms parameter types, return shape and read or write mode with zero compiler errors.
Application queriesnapalm queries push notes --branch rehearsalPassing resultCompiles every file in dbschema/queries against the rehearsal schema.
Import statementsnapalm queries push notes --queries dbschema/move --branch rehearsalPassing resultCompiles every batch upsert file in dbschema/move without deploying.
Service key reachnapalm keys reach notes --new --branch rehearsalPassing resultConfirms the migration key reaches expected types while restricted types report zero rows.
Idempotent row importRun the export script twicePassing resultBoth passes complete cleanly and print counts matching the source database.
Per-user reachnapalm people reach notes <person> --branch rehearsalPassing resultConfirms an imported user reads only their own and shared rows.

Decisions to keep in human hands#

Keep credentials, access policy sign-off and production cutover under your direct control.

Credentials
Export OLD_DATABASE_URL and NAPALM_KEY in your own shell environment rather than placing secrets in files the agent can read.
Production pushes to main
Although the ndb_… service key is restricted to rehearsal, your local napalm CLI is authenticated with your org token. Keep main pushes human-approved and run cutover commands yourself.
Access rule review
Read every access policy in dbschema/default.gel alongside the legacy policy or handler check it replaces before pushing to main, even when automated checks pass.
Production cutover
Deciding when to pause legacy writes and switch client traffic stays with you. Switching over walks through the cutover checklist.

Check the agent’s work#

  1. Ask the agent to summarize the legacy schema

    Confirm the agent reads from old/ and accounts for every table, collection and join table.

  2. Send a request to main using the branch service key

    main rejects the credential because the service key is scoped exclusively to rehearsal.

  3. Review the agent’s list of untranslated items

    Almost any production app produces at least one item, such as password hashes, procedural triggers or offline write queues.

  4. Run the verification commands yourself

    Re-run each command in the verification table from your own terminal and confirm the output matches.

Type a word or two to search every docs page.