generate
Generate a new migration that represents the difference between your current schema and the last recorded state. Each migration includes a forward (up.ts) and a rollback (down.ts) file, so changes can be applied and reverted reliably.
Usage
- npm
- pnpm
- Bun
- Yarn
npm exec durcno generate [--config path/to/durcno.config.ts]
pnpm exec durcno generate [--config path/to/durcno.config.ts]
bunx durcno generate [--config path/to/durcno.config.ts]
yarn durcno generate [--config path/to/durcno.config.ts]
Common options
--config <path>— Path to config file (defaults todurcno.config.ts).-y, --yes— Treat unconfirmed potential renames as drop + create instead of prompting.--rename-table <old=new>— Declare a table rename; repeat for multiple tables. The schema defaults topublic.--rename-column <table.old=new>— Declare a column rename; repeat for multiple columns. The schema defaults topublic.
Renames and non-interactive runs
When a table or column is dropped while another is added in the same schema, Durcno cannot tell a rename from a delete + create. In an interactive terminal it asks you to confirm each pair.
When stdin is not a TTY (CI, scripts, AI agents), generate never prompts. It exits with code 1 and prints the matching --rename-table / --rename-column flags. Pass those flags to record a rename, or pass --yes to treat the unresolved changes as drop + create.
- npm
- pnpm
- Bun
- Yarn
# Rename public.users to public.members and its username column to handle
npm exec durcno generate --rename-table public.users=public.members --rename-column public.members.username=handle
# Accept drop + create for anything left unconfirmed
npm exec durcno generate --yes
# Rename public.users to public.members and its username column to handle
pnpm exec durcno generate --rename-table public.users=public.members --rename-column public.members.username=handle
# Accept drop + create for anything left unconfirmed
pnpm exec durcno generate --yes
# Rename public.users to public.members and its username column to handle
bunx durcno generate --rename-table public.users public.members --rename-column public.members.username=handle
# Accept drop + create for anything left unconfirmed
bunx durcno generate --yes
# Rename public.users to public.members and its username column to handle
yarn durcno generate --rename-table public.users=public.members --rename-column public.members.username=handle
# Accept drop + create for anything left unconfirmed
yarn durcno generate --yes
Rename flags also work in an interactive terminal; only the remaining ambiguous pairs are prompted.
What it produces
After running the command you should see a new folder in your configured out directory (commonly migrations/) that contains:
up.ts— exports DDL statements to apply the migrationdown.ts— exports DDL statements to roll back the migration
Example
- Update your schema in
db/schema.ts(add or change tables/columns). - Run:
- npm
- pnpm
- Bun
- Yarn
npm exec durcno generate
pnpm exec durcno generate
bunx durcno generate
yarn durcno generate
- Review the generated
up.tsanddown.tsin the new migration folder. Edit the generated DDL statements if you need to tweak or add data migrations.
Tips
- Review
up.tsanddown.tscarefully before applying to production. - If a generated migration contains undesired changes, adjust the DDL statements or fix your schema and re-run
generate.
Next: apply the migration with durcno migrate.