stabilize-cli
v3.2.0
Published
Command-line interface for Stabilize ORM — model generation, migrations, seeding, health checks, and database management
Maintainers
Readme
Stabilize ORM CLI
The official command-line interface for the Stabilize ORM.
stabilize-cli is the essential companion tool for Stabilize ORM, providing a powerful set of commands to manage your database schema, generate files, and run development tasks directly from your terminal.
Features
- Code Generation: Instantly scaffold new models, migrations, seed files, and REST API routes.
- Flexible Field Arguments: Pass column definitions as arguments to
generate:model, e.g.name:string active:boolean. - Multi-Row Seeding: Use
--count <number>withgenerate:seedto control seed row count. - Schema Management: Auto-generate database-specific SQL migrations from models.
- AutoMigrate:
migrate:autocreates missing tables, columns and indexes in one step. It only ever adds — it never drops a column or changes a column type. - Schema Diffing:
db:diffcompares your model definitions against the live database and reports drift. - Soft Deletes & Versioning: Scaffold models with
softDeleteandversionedoptions. - Database Backup & Restore: Backup and restore your database with
db:backupanddb:restore. - REST API Generation: Generate full CRUD API scaffolds with
generate:api. - Fresh Migrations: Drop and re-migrate with
migrate:fresh(no seed). - Database Size Analysis: View table sizes and row counts with
db:size. - Interactive SQL Console: Run ad-hoc queries with
db:console(aliasdb:sql). - Model Introspection: Inspect model fields and validators with
model:info, and catch definition errors withmodel:validate. - Cross-DB Compatibility: Works with PostgreSQL, MySQL/MariaDB, SQLite, SQL Server, and MongoDB.
- MongoDB Support: The document database is a first-class target, not a degraded one.
db:consoleaccepts command documents, andstatus,db:tables,db:table:info,db:size,db:drop,db:truncate,db:diff,db:backup,db:restore, seeding and migration status all understand collections,_id, and realDatevalues.queryis the one exception: MongoDB has no SQL to run, so rather than failing withMONGO_UNSUPPORTEDfrom inside the driver it says so and points at the commands that do work. - TypeScript-First: All generated files are TypeScript, loaded directly by Node or Bun — no build step.
- Runs on Node.js and Bun: One published bundle, no native dependencies, no runtime lock-in.
Installation
# Using npm
npm install -g stabilize-cli
# Using Bun
bun add -g stabilize-cliThe published CLI is a single JavaScript bundle with no native dependencies, so the same install runs on either runtime.
Runtimes
| Runtime | Version | SQLite driver |
| ------- | -------- | ---------------------- |
| Node.js | 22.18+ | node:sqlite (built in) |
| Bun | 1.3+ | bun:sqlite (built in) |
Both are fully supported, and the other four backends — PostgreSQL, MySQL/MariaDB, SQL Server and MongoDB — behave identically on either.
Node.js: add "type": "module" to your project
The CLI imports your config/database.ts, models/*.ts and the rest of your
project at run time. Node decides how to treat a .ts file by looking at the
nearest package.json, and without "type": "module" it treats it as CommonJS —
so the import statements in your own files fail with:
SyntaxError: Cannot use import statement outside a moduleAdd this to your project's package.json if you are running the CLI under Node:
{
"type": "module"
}Bun detects module syntax on its own, so Bun projects need nothing.
Node.js 22.18 or later is required. That is the release where Node loads TypeScript by default; earlier 22.x releases need a flag and are not supported.
Commands
Generation
| Command | Description |
| ------------------------------------ | ------------------------------------------------- |
| generate:model <Name> [fields...] | Create a new model file in models/ |
| generate:migration <Name> | Generate a migration from a model |
| generate:seed <Name> | Generate a seed file. Use --count <n> |
| generate:api <Name> | Generate a REST API scaffold from a model |
| generate:test <Name> | Generate a test file for a model |
| generate:all <Name> [fields...] | Generate model, migration, and seed together |
| config:init | Scaffold a starter config/database.ts |
Migrations
| Command | Description |
| ---------------------- | ------------------------------------------------------------ |
| migrate | Apply all pending migrations |
| migrate:rollback | Roll back the most recent migration |
| migrate:fresh | Drop all tables and re-run all migrations (no seed) |
| migrate:status | Detailed migration status with timestamps |
| migrate:pending | Show only pending migrations |
| migrate:auto | Auto-migrate: create tables, add missing columns and indexes |
| db:diff | Compare model definitions against the database schema |
| seed | Run all pending seed files |
migrate:auto is additive only — it creates what is missing and never drops a column or alters a column type.
Database
| Command | Description |
| ---------------------- | ----------------------------------------------- |
| db:tables | List all tables in the database |
| db:table:info <table>| Show detailed column info for one table |
| db:size | Database and table size statistics |
| db:truncate [table] | Truncate a table, or all tables |
| db:drop [--force] | Drop all tables (use --force to skip confirm) |
| db:reset [--force] | Drop, migrate, and seed the database |
| db:backup | Backup the database to a timestamped file |
| db:restore <file> | Restore from a backup file |
| db:console (db:sql) | Start an interactive console (SQL, or documents on MongoDB) |
| query <sql> | Execute a raw SQL query and display results (SQL backends only) |
Models, Status & Health
| Command | Description |
| ------------------- | -------------------------------------------------- |
| model:info <name> | Show detailed info about a model |
| model:validate | Validate all model definitions for errors |
| status | Show migration and seed status |
| health | Check database and cache health |
| health:json | Health check with JSON output for automation |
| info | Show CLI, ORM, and environment information |
Command Examples
Generate a User model:
stabilize-cli generate:model User name:string active:boolean email:stringGenerate a REST API scaffold:
stabilize-cli generate:api User
# Creates api/User.ts with full CRUD routesBackup the database:
stabilize-cli db:backup
# Creates backups/backup_20250101120000.dbRestore from backup:
stabilize-cli db:restore backups/backup_20250101120000.db --forceFresh migration (drop + migrate):
stabilize-cli migrate:fresh --forceAuto-migrate (additive only):
stabilize-cli migrate:auto
# Creates missing tables, columns and indexes.
# Never drops a column and never changes a column type.Check for schema drift:
stabilize-cli db:diff
# Reports where your models and the live database disagreeView database size:
stabilize-cli db:size
# Shows file size, table count, and row countsCheck status:
stabilize-cli statusProject Documentation
License
MIT License - see LICENSE.
