v3.2.0

CLI Reference

31 commands. Runs on Node.js and Bun — install globally, or use npx / bunx.

install
❯npm install -g stabilize-cli
✔ installed stabilize-cli@3.2.0
❯bun add -g stabilize-cli
✔ installed stabilize-cli@3.2.0

The CLI is versioned independently of the ORM. This release bundles stabilize-orm@3.2.x and requires it — a project still on 2.x is told to upgrade rather than failing from inside the bundle.

It ships as one JavaScript bundle with no native dependencies, so the same install runs on Node.js 22.18+ and Bun 1.3+. The SQLite driver is chosen at run time — whichever of node:sqlite or bun:sqlite the runtime provides — and the other four backends are identical on both.

Running under Node.js

The CLI imports your config/database.ts, models/*.ts and the rest of your project at run time, and Node decides how to treat a .ts file by looking at the nearest package.json. Without "type": "module" it treats yours as CommonJS, so the import statements in your own files fail before any command runs:

terminal
❯stabilize-cli db:tables
SyntaxError: Cannot use import statement outside a module

Add "type": "module" to your project's package.json and every command works unchanged. Bun detects module syntax on its own, so Bun projects need nothing. Node 22.18 is the floor because that is where Node loads TypeScript by default.

MongoDB

Every command below works against a document backend as well, with one exception noted at the end. Where a command says “table”, MongoDB has a collection; where it says “row”, there is a document. Concretely:

  • db:tables, db:table:info, db:size and db:diff list and describe collections rather than tables.
  • db:truncate, db:drop and db:reset clear collections; db:backup and db:restore round-trip documents, preserving _id and real Date values.
  • db:console becomes a document console: it takes collections, find <collection> [filter] and any JSON command document.
  • status, migrate:status, migrate:pending, seeding and migrate:auto report and act on collections.
  • query is the exception. MongoDB has no SQL to run, so it says so and points you at db:tables, db:table:info and db:console rather than failing with MONGO_UNSUPPORTED after you have already written the statement.

Shorthand Aliases

Every generate command has short aliases:

g:m=generate:model
g:mg=generate:migration
g:s=generate:seed
g:a=generate:api
g:x=generate:all
g:t=generate:test

Generate

generate:model <name> [fields...]g:m

Generate a model file. Pass columns as field:type pairs.

--no-timestamps--no-soft-delete--versioned
terminal
❯stabilize-cli generate:model User name:string email:string age:int --versioned
generate:migration <name>g:mg

Generate a migration JSON file from an existing model.

-c, --config <path>
terminal
❯stabilize-cli generate:migration User
generate:seed <name>g:s

Generate a seed file with sample data from model columns.

-n, --count <number>
terminal
❯stabilize-cli generate:seed User --count 10
generate:api <name>g:a

Generate REST API scaffold with CRUD routes. Creates model if missing.

-p, --prefix <prefix>
terminal
❯stabilize-cli generate:api Product --prefix /v1
generate:all <name> [fields...]g:x

Generate model + migration + seed in one command.

--no-timestamps--versioned-n, --count
terminal
❯stabilize-cli generate:all Order userId:string total:decimal --count 20
generate:test <name>g:t

Generate a vitest test file with CRUD test stubs for a model.

terminal
❯stabilize-cli generate:test User

Migrate

migrate

Apply all pending migrations from migrations/ directory.

-c, --config <path>
terminal
❯stabilize-cli migrate
migrate:rollback

Roll back the most recent migration using down SQL.

-c, --config <path>
terminal
❯stabilize-cli migrate:rollback
migrate:fresh

Drop all tables and re-run migrations. No seed.

-c, --config <path>-f, --force
terminal
❯stabilize-cli migrate:fresh --force
migrate:status

Show detailed migration status with applied timestamps.

-c, --config <path>
terminal
❯stabilize-cli migrate:status
migrate:pending

Show only pending (not yet applied) migrations.

-c, --config <path>
terminal
❯stabilize-cli migrate:pending
migrate:auto

GORM-style auto migrate: create tables, add missing columns and indexes. Never deletes. Reads the models the project itself loaded, and reports any model whose table could not be created.

-c, --config <path>
terminal
❯stabilize-cli migrate:auto

Seed

seed

Run all pending seed files. Tracks applied seeds in database.

-c, --config <path>
terminal
❯stabilize-cli seed

Database

db:drop

Drop all tables. SQLite deletes the file.

-c, --config <path>-f, --force
terminal
❯stabilize-cli db:drop --force
db:reset

Drop all tables, re-run migrations, and seed. Full reset.

-c, --config <path>-f, --force
terminal
❯stabilize-cli db:reset --force
db:truncate [table]

Truncate a specific table or all tables.

-c, --config <path>-f, --force
terminal
❯stabilize-cli db:truncate users --force
db:backup

Backup database. SQLite copies .db file; others export to JSON.

-c, --config <path>-o, --output <dir>
terminal
❯stabilize-cli db:backup --output ./backups
db:restore <file>

Restore from a .db (SQLite) or .json backup file.

-c, --config <path>-f, --force
terminal
❯stabilize-cli db:restore backups/backup.db --force
db:tables

List all tables with row counts.

-c, --config <path>
terminal
❯stabilize-cli db:tables
db:size

Show database file size and per-table row counts.

-c, --config <path>
terminal
❯stabilize-cli db:size
db:diff

Compare model definitions against database tables. Shows missing/extra.

-c, --config <path>
terminal
❯stabilize-cli db:diff
db:consoledb:sql

Interactive SQL REPL. Type 'tables' to list, 'exit' to quit.

-c, --config <path>
terminal
❯stabilize-cli db:console
db:table:info <table>

Show detailed column info for a specific table.

-c, --config <path>
terminal
❯stabilize-cli db:table:info users

Model

model:validate

Validate all model files for errors (missing columns, types, etc).

terminal
❯stabilize-cli model:validate
model:info <name>

Show detailed model metadata: columns, relations, scopes.

terminal
❯stabilize-cli model:info User

Config

config:init

Scaffold a starter config/database.ts file.

--type <db>
terminal
❯stabilize-cli config:init --type postgres

Diagnostics

status

Show migration and seed status with health check.

-c, --config <path>
terminal
❯stabilize-cli status
health

Check database and cache connectivity with latency.

-c, --config <path>
terminal
❯stabilize-cli health
health:json

Health check with JSON output for CI/CD automation.

-c, --config <path>
terminal
❯stabilize-cli health:json
query <sql>

Execute a raw query and display the results. On MongoDB the argument is a document command, such as {"find": "users"}.

-c, --config <path>-p, --params
terminal
❯stabilize-cli query 'SELECT * FROM users LIMIT 5'
-V, --version

Print the CLI version and exit. Reads it from the manifest, so it cannot drift from the published package.

terminal
❯stabilize-cli --version
info

Show CLI version, runtime, platform, and all commands.

terminal
❯stabilize-cli info

Confirmation & Safety

Commands that destroy data — migrate:fresh, db:drop, db:reset, db:truncate and db:restore — ask before they act:

terminal
❯stabilize-cli db:drop
⚠ Drop ALL TABLES in 'test.db'? This cannot be undone. (y/N)

Anything other than y aborts and changes nothing. With no terminal attached — a CI runner, a piped script, docker run without -t — there is nobody to answer, so the CLI refuses rather than waiting forever on a question that can never be answered:

terminal
❯stabilize-cli db:drop < /dev/null
⚠ Drop ALL TABLES in 'test.db'? This cannot be undone.
Refusing to proceed without confirmation — stdin is not a terminal. Pass --force to proceed.

--force is how you say yes from a script

Every one of these commands takes -f, --force, which skips the prompt entirely. That is the supported way to run a destructive command unattended — nothing else opts in, so an accidental db:drop in a pipeline stops instead of taking your data with it.

Typical Workflow

workflow
❯stabilize-cli config:init --type sqlite
✔ Config generated: config/database.ts
❯stabilize-cli generate:all User name:string email:string age:int --count 10
ℹ Generating model, migration, and seed for 'user'...
✔ Model: models/user.ts
✔ Migration: migrations/20260402120000_create_user_table.json
✔ Seed: seeds/20260402120000_seed_user.ts
❯stabilize-cli migrate
✔ All 1 migration(s) applied.
❯stabilize-cli seed
✔ Applied 1 seed(s).
❯stabilize-cli model:validate
Model Validation
✔ User (models/user.ts, table: users)
Summary: 1 models, 0 errors, 0 warnings
❯stabilize-cli db:diff
Schema Diff
✔ users (in sync)
❯stabilize-cli health
✔ Database: healthy
Type: sqlite
Latency: 0.42ms