Migrating · Schema translation
How a schema is translated
napalm schema draft --from reads a Postgres dump, Prisma schema or Convex schema and generates a starter Napalm schema.
- API
- —
- In the schema
- —
Running schema draft#
napalm schema draft generates an initial dbschema/default.gel from three local schema formats:
- Postgres
- A SQL schema dump from
pg_dump --schema-only. - Prisma
- A single
schema.prismafile or a multi-file schema directory, including MongoDB Prisma schemas. - Convex
- A
convex/schema.tsfile or theconvexdirectory.
Because the command reads files on disk directly, you never connect it to a live database or install database drivers. Pass -o to write the draft to a custom path, or --yes to overwrite an existing file without prompting.
Offline schema translation
The CLI parses SQL dumps, Prisma schemas and Convex validators from disk.
Closed by default
Every drafted type blocks API access until you write explicit policy conditions.
Each source guide translates the same four-table project tracker and shows the complete drafted schema.
Generated schema constructs#
Instead of stopping at flat types, properties and forward links, napalm schema draft generates five idiomatic schema constructs automatically. The snippets below come from the Postgres translation guide.
Synthesized links and types
The draft synthesizes reverse backlinks, shared base types, timestamp rewrites and enums.
Reverse links#
Forward links traverse in one direction. The draft adds a computed reverse link on each target type so queries can read a project’s tasks without a manual join.
# The other side of each link to User.projects_as_owner := .<owner[is Project];projects_as_members := .<members[is Project];Each reverse link uses the plural of the source type. When one type has two links to the same target, the draft suffixes each backlink name with its forward link, such as projects_as_owner and projects_as_members. Exclusive one-to-one links read back as a single object.
Shared base types#
When three or more types share at least two identical properties, the draft extracts an abstract base type that each concrete type extends. Here User, Project and Task all inherit created_at and updated_at.
# 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()); };}Timestamp rewrites#
Where the Postgres schema maintained updated_at with a trigger, the draft writes rewrite update using (datetime_of_statement()) directly on the property. Any trigger function that only stamps the current time converts the same way, including Postgres’s moddatetime extension. Prisma’s @updatedAt attribute produces the identical rewrite.
Checked columns as enums#
Where a SQL CHECK constraint restricted role to a fixed list of strings, the draft declares a typed enum and casts the column default. Prisma enums and Convex literal unions translate to enums the same way.
# The values the users.role check allowed.scalar type UserRole extending enum<member, admin>; required role: UserRole { default := <UserRole>'member';};Full-text search indexes#
Where the search column used a generated tsvector across two text columns, the draft declares an fts::index over those columns and drops the separate column index. Convex search indexes translate to fts::index declarations as well.
index fts::index on (( fts::with_options(.title, language := fts::Language.eng), fts::with_options(.notes, language := fts::Language.eng)));Each type supports one fts::index. If a table has a second tsvector column, the draft emits a draft: comment for manual review.
Closed access rules#
A type without an access rule denies all requests, and napalm schema draft never opens a type automatically. Each Postgres RLS policy becomes a closed using (false) scaffold with the original SQL preserved in a comment above the rule. Because Prisma and Convex schema files do not contain access policies, drafts from those sources emit no policy scaffolds.
# 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 an RLS policy compares a column directly against auth.uid(), the comment also suggests the matching EdgeQL condition. The scaffold remains closed until you replace false with your real rule. Access rules covers the policy language, and Coming from Supabase walks through converting multi-table RLS policies.
Untranslated items#
Whenever the command encounters a construct without a direct equivalent, it emits a # draft: comment in the schema and prints the total count of review notes. Two items remain manual across every source, and the Postgres, Prisma and Convex pages cover source-specific notes.
- Password hashes
- Password hash columns are omitted because Napalm does not import external password hashes. Returning users sign in and reclaim their rows through the flow in Moving your users.
- Vector columns
- Stored embedding columns and vector indexes become
# draft:notes. Semantic search in Napalm uses a declarativeext::ai::indexon the type.
Verify on a branch#
Review every # draft: note in the generated file, then run napalm schema push with --plan against a branch. The command compiles your schema and prints the migration plan without modifying any branch.
napalm branches create notes rehearsalnapalm schema push notes --branch rehearsal --planComing from Postgres and Coming from Convex continue from the drafted schema through access rules, deployed queries and batch row imports. If you want an agent to finish the translation, Moving with a coding agent lists the files and prompt to use.