chkit generate
Compares your current TypeScript schema definitions against the previous snapshot, computes a migration plan, and writes migration SQL and an updated snapshot.
Synopsis
Section titled “Synopsis”chkit generate [flags]| Flag | Type | Default | Description |
|---|---|---|---|
--name <name> | string | — | Migration name (used in the filename) |
--migration-id <id> | string | — | Escape hatch: override the default timestamp migration prefix |
--rename-table <mapping> | string | — | Explicit table rename: old_db.old_table=new_db.new_table |
--rename-column <mapping> | string | — | Explicit column rename: db.table.old_column=new_column |
--table <selector> | string | — | Scope operations to matching tables |
--dryrun | boolean | false | Print the plan without writing any files |
Global flags documented on CLI Overview.
Behavior
Section titled “Behavior”Schema diff and plan
Section titled “Schema diff and plan”- Loads your config and schema definitions
- Reads the previous snapshot from
metaDir/snapshot.json - Computes a diff between old and new definitions using
planDiff()from@chkit/core - Produces an ordered list of SQL operations
If there are no differences, no migration file is created.
Risk levels
Section titled “Risk levels”Every operation in the plan is assigned a risk level:
| Risk | Meaning | Example operations |
|---|---|---|
safe | Non-destructive, no data loss | CREATE TABLE, ADD COLUMN |
caution | Potentially impactful, review recommended | ALTER TABLE settings changes |
danger | Destructive, may cause data loss | DROP TABLE, DROP COLUMN |
Table scoping
Section titled “Table scoping”The --table flag limits operations to tables matching a selector:
database.table— exact matchdatabase.prefix*— prefix wildcard in a specific databasetable— matches across all databases
An empty match set emits a warning and produces no output.
Rename workflow
Section titled “Rename workflow”chkit detects potential renames through two mechanisms:
- Schema metadata — set
renamedFromon your schema definition - CLI flags —
--rename-table old_db.old_table=new_db.new_tableand--rename-column db.table.old_col=new_col
CLI flags take priority when both sources specify a mapping for the same object. Rename flags accept comma-separated values for multiple mappings.
Validation errors are raised for conflicting, chained, or cyclic rename mappings.
Dryrun mode
Section titled “Dryrun mode”With --dryrun, the command prints the migration plan (operations with risk levels and SQL) without writing any files. Useful for previewing changes before committing.
Plans for objects in a database lead with a create_database operation (CREATE DATABASE IF NOT EXISTS, risk safe), so a single new table reports operationCount: 2 — the create_database plus the create_table. The CREATE DATABASE is idempotent and a no-op if the database already exists.
Codegen integration
Section titled “Codegen integration”If the codegen plugin is configured with runOnGenerate: true (the default), chkit generate automatically runs codegen after writing migration artifacts. A codegen failure causes generate to fail.
Validation errors
Section titled “Validation errors”Schema validation issues (such as invalid definitions) produce a validation_failed error with structured issue codes and messages. The process exits with code 1.
Examples
Section titled “Examples”Generate a named migration:
chkit generate --name add_users_tablePreview changes without writing files:
chkit generate --dryrunScope to a specific table:
chkit generate --table analytics.eventsExplicit table rename:
chkit generate --rename-table old_db.users=new_db.accountsExplicit column rename:
chkit generate --rename-column analytics.events.old_name=new_nameExit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Validation error |
JSON output
Section titled “JSON output”Plan mode (--dryrun)
Section titled “Plan mode (--dryrun)”{ "command": "generate", "schemaVersion": 1, "scope": { "enabled": false }, "mode": "plan", "operationCount": 2, "riskSummary": { "safe": 2, "caution": 0, "danger": 0 }, "operations": [ { "type": "create_database", "key": "database:default", "risk": "safe", "sql": "CREATE DATABASE IF NOT EXISTS default;" }, { "type": "create_table", "key": "default.users", "risk": "safe", "sql": "CREATE TABLE ..." } ], "renameSuggestions": []}Apply mode (default)
Section titled “Apply mode (default)”{ "command": "generate", "schemaVersion": 1, "scope": { "enabled": false }, "migrationFile": "./chkit/migrations/20260604104251_add_users_table.sql", "snapshotFile": "./chkit/meta/snapshot.json", "definitionCount": 3, "operationCount": 2, "riskSummary": { "safe": 2, "caution": 0, "danger": 0 }}Validation error
Section titled “Validation error”{ "command": "generate", "schemaVersion": 1, "error": "validation_failed", "issues": [{ "code": "...", "message": "..." }]}Related commands
Section titled “Related commands”chkit init— scaffold a project before your first generatechkit migrate— apply generated migrations to ClickHousechkit codegen— manually trigger TypeScript type generation