Quickstart
import { Steps } from “@astrojs/starlight/components”;
This walks you from an empty directory to a schema applied to a live PostgreSQL database.
It assumes you’ve installed the nschema tool and have a database
you can connect to.
-
Scaffold a project.
Terminal window nschema initThis writes two files:
config.sql— the project’sPROVIDER/BACKENDconfiguration blocks (which database to connect to, and where state lives).schemas/example.sql— a sample desired-schema file.
Edit the sample to describe the schema you want, written in NSchema DDL:
-- schemas/example.sqlCREATE SCHEMA app;CREATE TABLE app.widgets (id bigint NOT NULL,name text,CONSTRAINT widgets_pkey PRIMARY KEY (id)); -
Point at your database.
The connection string is a secret, so supply it through the environment rather than committing it:
Terminal window export NSCHEMA_POSTGRES_CONNECTION_STRING="Host=localhost;Database=app;Username=postgres;Password=postgres"See Configuration blocks for setting the provider and backend, and Environment variables for the full list of overrides.
-
Check the schema files are well-formed (optional, but a fast pre-flight):
Terminal window nschema validate -
Preview the migration.
Terminal window nschema planThis computes the changes and prints them, without touching the database.
-
Apply it.
Terminal window nschema applyapplyshows the same plan, then prompts for confirmation before making any changes. Answeryesto proceed.
That’s the core loop: edit the .sql files → plan → apply. Everything else builds on
it.
What next?
Section titled “What next?”- Already have a database? Use
importto write its schema out as DDL and adopt it into NSchema — see Adopting an existing database. - Learn the schema language. Defining schemas is a practical introduction; the grammar reference is the complete spec.
- Understand the workflow. The plan / apply workflow covers saved plans, scoping, and the day-to-day loop.
- Automate it. Running in CI covers
--auto-approve, detailed exit codes, and offline planning.