Command-line interface tool for MikroORM TypeScript ORM providing database management, migrations, schema operations, and entity generation
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
MikroORM CLI migration system providing comprehensive database schema versioning and migration management. Supports creating, executing, and tracking database schema changes over time.
Creates a new migration file with schema differences between current entities and database state.
/**
* Create new migration command
*/
command: "migration:create"
interface MigrationCreateOptions extends BaseArgs {
blank?: boolean; // Create blank migration (--blank / -b)
initial?: boolean; // Create initial migration (--initial / -i)
dump?: boolean; // Dump queries to console (--dump / -d)
path?: string; // Migration directory path (--path / -p)
name?: string; // Custom migration name (--name / -n)
}Usage Examples:
# Create migration with auto-generated schema diff
mikro-orm migration:create
# Create blank migration for custom SQL
mikro-orm migration:create --blank
# Create initial migration from current schema
mikro-orm migration:create --initial
# Create with custom name and dump queries
mikro-orm migration:create --name AddUserTable --dump
# Save to custom directory
mikro-orm migration:create --path ./migrations/customExecutes pending migrations to bring database schema up to latest version.
/**
* Migrate up to latest version command
*/
command: "migration:up"
interface MigrationUpOptions extends BaseArgs {
to?: string; // Migrate up to specific version (--to / -t)
from?: string; // Start migration from specific version (--from / -f)
only?: string; // Migrate only specified versions (--only / -o)
}Usage Examples:
# Migrate to latest version
mikro-orm migration:up
# Migrate to specific version
mikro-orm migration:up --to 20231201_001
# Migrate from specific version
mikro-orm migration:up --from 20231120_002
# Run only specific migration
mikro-orm migration:up --only 20231201_001Reverts migrations by executing down methods to undo schema changes.
/**
* Migrate one step down command
*/
command: "migration:down"
interface MigrationDownOptions extends BaseArgs {
to?: string; // Migrate down to specific version (--to / -t)
from?: string; // Start migration from specific version (--from / -f)
only?: string; // Migrate only specified versions (--only / -o)
}Usage Examples:
# Migrate one step down
mikro-orm migration:down
# Migrate down to specific version
mikro-orm migration:down --to 20231120_001
# Revert only specific migration
mikro-orm migration:down --only 20231201_002Displays all executed migrations with their execution timestamps.
/**
* List all executed migrations command
*/
command: "migration:list"
// No additional options beyond global optionsUsage Examples:
# List executed migrations
mikro-orm migration:list
# List with specific config
mikro-orm migration:list --config ./orm.config.jsChecks if there are pending migrations that need to be executed. Useful for CI/CD pipelines and deployment scripts.
/**
* Check if migrations are needed command
*/
command: "migration:check"
// No additional options beyond global options
// Exit code 0: no pending migrations
// Exit code 1: pending migrations existUsage Examples:
# Check migration status
mikro-orm migration:check
# Use in scripts
if mikro-orm migration:check; then
echo "Database is up to date"
else
echo "Pending migrations found"
mikro-orm migration:up
fiShows all pending migrations that haven't been executed yet.
/**
* List all pending migrations command
*/
command: "migration:pending"
// No additional options beyond global optionsUsage Examples:
# List pending migrations
mikro-orm migration:pending
# Check with custom configuration
mikro-orm migration:pending --context productionDrops the database schema and re-runs all migrations from scratch. Useful for testing and development environment resets.
/**
* Clear database and rerun all migrations command
*/
command: "migration:fresh"
interface MigrationFreshOptions extends BaseArgs {
dropDb?: boolean; // Drop entire database (--drop-db)
seed?: string; // Seed database after migration (--seed)
}Usage Examples:
# Drop schema and run all migrations
mikro-orm migration:fresh
# Fresh migration with database seeding
mikro-orm migration:fresh --seed DatabaseSeeder
# Fresh migration with database drop and recreation
mikro-orm migration:fresh --drop-db
# Fresh migration with seeding and custom config
mikro-orm migration:fresh --seed TestDataSeeder --config ./test.config.jsAll migration commands support:
--config: Path to ORM configuration file(s)--contextName / --context: Configuration context name--blank / -b: Create empty migration file for custom SQL--initial / -i: Create initial migration from current entity state--dump / -d: Display generated SQL queries in console--path / -p: Set custom directory for migration files--name / -n: Specify custom name for migration file--to / -t: Target specific migration version--from / -f: Start from specific migration version--only / -o: Execute only specified migration(s)Generated migration files follow this structure:
import { Migration } from '@mikro-orm/migrations';
export class Migration20231201001234 extends Migration {
async up(): Promise<void> {
this.addSql('CREATE TABLE "user" ("id" serial PRIMARY KEY, "name" varchar(255) NOT NULL);');
}
async down(): Promise<void> {
this.addSql('DROP TABLE "user";');
}
}Migration system uses these configuration options:
interface MigrationConfiguration {
migrations: {
path?: string; // Migration files directory
pattern?: RegExp; // Migration file naming pattern
transactional?: boolean; // Run migrations in transactions
disableForeignKeys?: boolean; // Disable FK checks during migration
allOrNothing?: boolean; // All migrations succeed or all fail
};
}