Adopt an existing database

schemic pull runs the diff in reverse: it reads a live database’s schema and writes matching s.* definitions into your TypeScript. Use it to adopt a database you did not define in Schemic, or to reconcile changes someone made directly on the server back into your code.

Preview the changes

By default pull is non-destructive — it shows what it would write, without changing any file:

Shell
npx schemic pull

It introspects the database and renders the difference against your current schema files, like a code-review diff. Nothing is written until you ask.

Write the changes

Apply the preview with --write:

Shell
npx schemic pull --write

pull makes surgical edits to your real .ts files: it adds and updates the definitions the database has, while preserving your comments, imports, and untouched fields. It does not rewrite a file from scratch.

Keep or discard local-only definitions

When your files contain definitions the database does not have, pull follows a git-like “commit or stash” guard rather than silently clobbering your work. Two flags resolve it:

FlagEffect
--mergeKeep local-only entities (a table, function, or access definition that exists in your code but not the database), and apply the database’s changes alongside them.
--discardMirror the database exactly, dropping local-only definitions.

An entity here is one exported definition — a table, a function, an access rule. A single file can hold several, and --merge decides per entity.

A typical adoption flow

Shell
npx schemic init            # scaffold config + database/ layout
# edit schemic.config.ts to point at the existing database
npx schemic pull            # preview the introspected schema
npx schemic pull --write    # write it into database/schema/
npx schemic gen baseline    # record a baseline migration for the current state

After this your existing database is fully described in TypeScript, and future changes flow through the normal migration workflow.

Where to go next