Install supaschema
supaschema requires Node.js 22 or later and targets PostgreSQL 15 or later. Install it as a dev dependency in your project:Verify the installation:
After installation, a
postinstall script runs automatically and scaffolds a supaschema.config.json file in your project root if one does not already exist. You can also create or regenerate this file at any time by running npx supaschema init.Write your declarative schema
supaschema reads schema files from the path(s) configured in Then create Your schema files are the single source of truth. You edit them directly — you never write migration SQL by hand.
supaschema.config.json. By default it looks in supabase/schemas/. Create your first schema file:supabase/schemas/001_app.sql with the following content:Generate a migration with diff
With your schema file in place, run supaschema compares your declarative schema files (The generated migration file contains only the SQL needed to move from your current state to your desired state. Every statement is guarded so the migration is safe to re-run. Open it to review the output:
diff to generate a migration:--to, defaulting to supabase/schemas) against the current applied database state (--from, defaulting to your configured database, then falling back to git:HEAD) and writes a new timestamped migration file to supabase/migrations.You will see output similar to:Validate the migration with check
Before applying the migration, use
check to validate it:check parses the migration using the PostgreSQL WASM parser and verifies its structural correctness and safety. A passing check looks like:Apply the migration with Supabase CLI
supaschema generates migrations but never applies them to a database directly. Use the Supabase CLI to push your migration as you normally would:This keeps your existing deployment workflow intact. supaschema slots in as the migration generation step; the Supabase CLI handles the application step.
supaschema never modifies your database, reads from a live connection during
diff, or requires a shadow database at any point. Migration generation is entirely offline.(Optional) Generate TypeScript types
Once your schema is defined, you can generate TypeScript types from it:This produces a type file derived from your declarative schema, giving you end-to-end type safety from database schema to application code — no separate
supabase gen types step required against a live database.What’s Next?
You’ve installed supaschema, written a declarative schema, generated and validated a migration, and seen how to push it. From here you can:Installation & Configuration
Explore all configuration options, shell completions, and the
doctor command.Commands Reference
Deep-dive into
diff, check, verify, and all other supaschema commands.Type Generation
Learn how to configure and customise TypeScript type output.
CI/CD Integration
Add supaschema to your GitHub Actions or other CI pipeline.