Migrating · Schema translation
How a schema is translated
One command reads a Postgres dump, a Prisma schema or a Convex schema and writes a first Napalm schema. Every draft follows the rules on this page.
- API
- —
- In the schema
- —
The command#
napalm schema draft writes a first dbschema/default.gel from one of three sources. The command reads files only, so the old database needs no connection and no driver.
Offline schema translation
napalm schema draft parses Postgres dumps, Prisma models or Convex validators into dbschema/default.gel with no live database connection.
Closed rules by default
Every drafted type starts closed, and Postgres RLS policies carry over as commented using (false) scaffolds until you author each condition.
- Postgres
- The file from
pg_dump --schema-only. - Prisma
- The
schema.prismafile or the folder of a schema split across files. MongoDB schemas work too. - Convex
- The
convex/schema.tsfile or theconvexfolder.
-o writes the draft to another file. The command prompts before overwriting an existing file, and --yes skips the prompt. Each source’s page drafts the same small project tracker and shows the whole draft.
Additions in every draft#
A plain copy of the source would stop at types, properties and links. Every draft also adds five schema constructs you would otherwise write by hand. The examples come from the Postgres draft.
Reverse backlinks, shared base types and rewrites
Every draft synthesizes .<link[is Source] backlinks, factors repeated timestamp columns into an abstract base type and converts updated_at triggers into rewrite update hooks.
Reverse links#
A link reads in one direction. The draft adds the other direction as a computed link on the target type, so a query reads a project’s tasks with no join.
# The other side of each link to User.projects_as_owner := .<owner[is Project];projects_as_members := .<members[is Project];A reverse link takes the plural of the source type. Two links from one type to the same target also take the link’s name, as projects_as_owner and projects_as_members do here. A one-to-one link reads back as one object.
One shared type#
created_at and updated_at repeat on three tables. The draft writes one abstract type, and the three types extend it. The rule applies when three or more types hold two or more properties alike.
# The properties User, Project and Task share.abstract type Timestamped { required created_at: datetime { default := datetime_current(); }; required updated_at: datetime { default := datetime_current(); rewrite update using (datetime_of_statement()); };}A trigger becomes a rewrite#
The old database kept updated_at current with a trigger. The draft writes rewrite update using (datetime_of_statement()) on the property in the block above. The rule applies to any trigger whose function only sets columns to the time, as the moddatetime extension’s function does. A Prisma @updatedAt becomes a rewrite as well.
A checked list becomes an enum#
A CHECK limited the role column to two values. The draft writes an enum with those values and casts the default. A Prisma enum and a Convex union of literals become enums too.
# The values the users.role check allowed.scalar type UserRole extending enum<member, admin>; required role: UserRole { default := <UserRole>'member';};A search column becomes a search index#
The search column was a generated tsvector over two columns. The draft writes one text search index over the same columns and drops the old column’s own index. A Convex search index becomes a text search index too.
index fts::index on (( fts::with_options(.title, language := fts::Language.eng), fts::with_options(.notes, language := fts::Language.eng)));A type holds one text search index. A second tsvector column on the same table stays a note.
Closed access rules#
A type with no rule answers nothing, and the draft never opens a type. Each row-level security policy from Postgres becomes a rule that allows nothing, and a comment above the rule holds the policy’s SQL. Prisma and Convex schemas hold no policies, so those drafts write no rules.
# draft: the policy "owners" (FOR ALL) became the rule below. The rule allows nothing until you write the condition:# using (owner_id = auth.uid())# In EdgeQL, the condition is (.owner.identity ?= global caller). That condition needs a caller global and an# identity link on the people type, and the guide at https://napalmdata.com/developers/migrating/moving-users builds# both.access policy owners allow all using (false);When a policy compares one column to auth.uid(), the comment also gives the condition in EdgeQL. The rule stays closed until you write the condition into the rule. Access rules has the whole language, and Coming from Supabase turns a set of policies into rules.
Untranslated items#
A comment that starts with draft: marks each item the command could not translate, and the command prints the count. The two items below stay notes from any source. The Postgres, Prisma and Convex pages list the rest.
- Password hashes
- A password column stays behind. People sign in again and reclaim every owned row. Moving your users builds the flow.
- Vectors
- A stored vector or a vector index stays a note. Search by meaning in Napalm is an
ext::ai::indexon the type.
A plan on a branch#
Read every line of the draft, then push the draft to a branch with --plan. The plan compiles the schema and changes nothing.
napalm branches create notes rehearsalnapalm schema push notes --branch rehearsal --planComing from Postgres and Coming from Convex carry on with the rules, the queries and the rows. A coding agent can start from the draft. Moving with a coding agent lists the files to hand over.