Command-line interface tool for MikroORM TypeScript ORM providing database management, migrations, schema operations, and entity generation
npx @tessl/cli install tessl/npm-mikro-orm--cli@6.5.0MikroORM CLI is a comprehensive command-line interface tool for MikroORM, a TypeScript ORM for Node.js that implements Data Mapper, Unit of Work, and Identity Map patterns. The CLI provides essential database management capabilities including migrations, schema operations, entity generation, cache management, and seeding functionality across multiple database systems (MongoDB, MySQL, MariaDB, PostgreSQL, SQLite).
npm install @mikro-orm/cli or yarn add @mikro-orm/cliimport { CLIHelper, CLIConfigurator } from "@mikro-orm/cli";For CommonJS:
const { CLIHelper, CLIConfigurator } = require("@mikro-orm/cli");Install and use as a CLI tool:
# Install as dependency
npm install @mikro-orm/cli
# Use the CLI
npx mikro-orm debug
npx mikro-orm migration:create
npx mikro-orm schema:update --runGlobal installation:
# Install globally
npm install -g @mikro-orm/cli
# Use directly
mikro-orm debug
mikro-orm migration:create
mikro-orm schema:update --runMikroORM CLI is built around several key components:
mikro-orm for CommonJS, mikro-orm-esm for ESM)CLIHelper class providing common ORM operations and utilitiesCLIConfigurator class managing command setup and configuration loadingCommands for managing MikroORM's metadata cache system.
// Clear metadata cache
command: "cache:clear"
// Generate metadata cache
command: "cache:generate"Core database management operations including creation and import functionality.
// Create database if it doesn't exist
command: "database:create"
// Import SQL file to database
command: "database:import <file>"Generate TypeScript entities from existing database schemas.
// Generate entities from database schema
command: "generate-entities"Complete database migration management with creation, execution, and tracking capabilities.
// Migration commands
command: "migration:create" // Create new migration
command: "migration:up" // Migrate up to latest
command: "migration:down" // Migrate one step down
command: "migration:list" // List executed migrations
command: "migration:check" // Check if migrations needed
command: "migration:pending" // List pending migrations
command: "migration:fresh" // Clear database and rerun all migrationsDatabase schema management operations for creating, updating, and dropping schemas.
// Schema commands
command: "schema:create" // Create database schema
command: "schema:update" // Update database schema
command: "schema:drop" // Drop database schema
command: "schema:fresh" // Drop and recreate schemaDatabase seeding functionality for populating databases with test or initial data.
// Seeder commands
command: "seeder:run" // Run seeder class
command: "seeder:create <seeder>" // Create new seeder classDebugging and utility commands for configuration validation and troubleshooting.
// Debug CLI configuration
command: "debug"The CLIHelper class provides programmatic access to CLI functionality for custom tooling.
class CLIHelper {
static getConfiguration<D>(contextName?: string, configPaths?: string[], options?: Partial<Options<D>>): Promise<Configuration<D>>;
static getORM<D>(contextName?: string, configPaths?: string[], opts?: Partial<Options<D>>): Promise<MikroORM<D>>;
static isDBConnected(config: Configuration, reason?: boolean): Promise<boolean | string>;
static dump(text: string, config?: Configuration): void;
static dumpTable(options: TableOptions): void;
static showHelp(): void;
}All commands support these global options:
interface BaseArgs {
config?: string[]; // Path to ORM configuration file(s)
contextName?: string; // Configuration context name (default: 'default')
context?: string; // Alias for contextName
}Additional global flags:
--version / -v: Show version information--help / -h: Show help information// Base argument types
interface BaseArgs {
config?: string[];
contextName?: string;
context?: string;
}
// Command interface
interface BaseCommand<CommandArgs extends BaseArgs = BaseArgs> extends CommandModule<BaseArgs, CommandArgs> {}
// Table formatting options
interface TableOptions {
columns: string[];
rows: string[][];
empty: string;
}