Skip to main content
Use this when application code needs database types and runtime validators before the migration is applied. supaschema types reads declarative PostgreSQL files and emits TypeScript database types plus runtime Zod validators from the same schema model used for migrations.

Use this when

  • A pull request changes SQL and TypeScript together.
  • Database introspection cannot see the new schema yet.
  • You want runtime validators generated from the same source as migrations.
  • You want a typed, validated application boundary without adding an ORM schema layer.
  • You want generated application contracts without adding a provider-specific or ORM schema layer.

Do this

Generate types from the configured schema tree:
npx supaschema types
Override the source or output when needed:
npx supaschema types --from dir:database/schemas
npx supaschema types --out src/lib/database.types.ts
supaschema diff refreshes configured TypeScript and Zod outputs after writing a migration, so the schema, migration, and app types can be reviewed together. Use the generated helpers as the application contract:
import { schemas, type TableInsert, type TableRow } from "./database.zod";

type Account = TableRow<"app", "accounts">;
type NewAccount = TableInsert<"app", "accounts">;

const input: NewAccount = schemas.app.Tables.accounts.Insert.parse(body);
That covers the shape and validation responsibilities that teams often reach for an ORM-generated client to solve. Query execution can stay SQL-native through your PostgreSQL driver or platform client.

Verify

Commit generated outputs when your project reviews them:
git diff --exit-code database.types.ts database.zod.ts
Then run your app typecheck:
npm run typecheck

Types command

See type and Zod output flags.

Configuration

Set default output paths in config.

ORM-free apps

Use generated outputs as the application contract.

CI recipe

Keep generated files checked in CI.
Last modified on June 18, 2026