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.
- Code Generation: Instantly scaffold new models, migrations, and seed files with a single command.
- Flexible Field Arguments for Models: Pass column definitions as arguments to
generate model, e.g.,name:string active:boolean. - Multi-Row Seeding: Use
--count <number>(or-n <number>) withgenerate seedto control how many seed rows are generated, using the model's schema. - Schema Management: Automatically generate database-specific SQL migrations from your existing models.
- Lifecycle Hooks Support: Scaffold models with hooks defined in
ModelConfigor as class methods forbeforeCreate,afterUpdate, etc. - Soft Deletes & Versioning: Scaffold models with
softDeleteandversionedoptions for audit, rollback, and time-travel support. - Database Tooling: Run migrations, roll them back, and check their status against the database.
- Data Seeding with Dependencies: Populate your database with test data, manage seed history, and respect dependencies between seed files.
- Cross-DB Compatibility: Seed and migration history tables are now created with auto-increment
idand proper string/timestamp types for MySQL, Postgres, and SQLite. - Workflow Automation: A powerful
db:resetcommand to drop, migrate, and seed your database for a clean development slate, with a--forceflag for non-interactive use. - TypeScript & Modern Bun Support: All files generated are TypeScript-first, designed for Bun runtimes.
For the best experience, install the CLI globally using your preferred package manager.
# Using npm
npm install -g stabilize-cli
# Using Bun
bun add -g stabilize-cliAfter installation, the stabilize-cli command will be available in your terminal.
The Stabilize CLI is designed to work within a project that has stabilize-orm@^1.3.0 installed and configured. It automatically looks for a config/database.ts file in your project's root directory to connect to the database.
All commands are run using the stabilize-cli executable.
| Command | Description |
|---|---|
generate model <Name> [fields...] |
Creates a new model file in models/ with hooks, soft delete, and versioning. Pass column definitions as extra arguments (e.g. name:string active:boolean). |
generate migration <ModelName> |
Generates a new SQL migration from an existing model. |
generate seed <SeedName> |
Creates a new seed file in seeds/, based on the model schema. Use --count <number> or -n <number> to control number of rows. |
migrate |
Applies all pending migrations to the database. |
migrate:rollback |
Rolls back the most recently applied migration. |
seed |
Runs all pending seed files, respecting dependencies. |
seed:rollback |
Rolls back the most recently applied seed. |
status |
Shows the status (APPLIED or PENDING) of all migration and seed files. |
db:drop [--force] |
Drops all tables in the database. Use --force to skip confirmation. Use with caution. |
db:reset [--force] |
Drops, migrates, and seeds the database. Use --force to skip confirmation. For development only. |
Generating a new User model with custom fields:
stabilize-cli generate model User name:string active:boolean email:string
# ✔ Success: Model generated: models/User.tsGenerating a seed file for User with 10 rows (uses model's schema):
stabilize-cli generate seed User --count 10
# ✔ Success: Seed generated: seeds/20251019135400_User.tsGenerating a migration from the Product model:
stabilize-cli generate migration Product
# ✔ Success: Migration generated: migrations/20251018203000_create_product_table.jsonApplying all pending migrations:
stabilize-cli migrate
# ✔ All pending migrations applied.Applying all pending seeds:
stabilize-cli seed
# ✔ Successfully applied 1 seed(s).Resetting the database non-interactively:
stabilize-cli db:reset --force
# ✔ Database reset complete.Checking the status of your database:
stabilize-cli status
# Migration Status
# ---------------------------------
# [ APPLIED ] 20251018203000_create_product_table
#
# Seed Status
# ---------------------------------
# [ PENDING ] 20251018203000_ProductBy default, generated models include:
versioned: truefor audit and time-travel support.softDelete: truewith adeletedAtcolumn for soft deletes.- Lifecycle hooks defined in
ModelConfigand as class methods. - Custom columns: Pass fields as arguments, e.g.
name:string isActive:boolean createdAt:date.
stabilize-cli generate model Product name:string category:string price:numericContributions are welcome! Please read the Contributing Guide for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
Created with ❤️ by ElectronSz
File last updated: 2025-10-19 13:59:00 UTC