CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mikro-orm--cli

Command-line interface tool for MikroORM TypeScript ORM providing database management, migrations, schema operations, and entity generation

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

schema.mddocs/

Schema Commands

MikroORM CLI schema management commands for creating, updating, dropping, and recreating database schemas based on entity definitions. These commands provide direct schema manipulation capabilities for development and deployment workflows.

Capabilities

Create Schema

Creates database schema based on current entity metadata. Generates tables, indexes, and constraints from entity definitions.

/**
 * Create database schema command
 */
command: "schema:create"

interface SchemaCreateOptions extends BaseArgs {
  run?: boolean;       // Execute queries (--run / -r)
  dump?: boolean;      // Dump queries to console (--dump / -d) 
  fkChecks?: boolean;  // Include foreign key checks (--fk-checks)
  schema?: string;     // Set current schema for wildcard entities (--schema)
  seed?: string;       // Seed database after creation (--seed)
}

Usage Examples:

# Display schema creation queries without executing
mikro-orm schema:create --dump

# Create schema and execute queries
mikro-orm schema:create --run

# Create schema and seed with data
mikro-orm schema:create --run --seed DatabaseSeeder

# Create for specific schema with FK checks
mikro-orm schema:create --run --schema public --fk-checks

Update Schema

Updates existing database schema to match current entity definitions. Handles adding/modifying columns, indexes, and constraints.

/**
 * Update database schema command
 */
command: "schema:update"

interface SchemaUpdateOptions extends BaseArgs {
  run?: boolean;         // Execute queries (--run / -r)
  dump?: boolean;        // Dump queries to console (--dump / -d)
  fkChecks?: boolean;    // Include foreign key checks (--fk-checks)
  schema?: string;       // Set current schema for wildcard entities (--schema)
  safe?: boolean;        // Disable table and column dropping (--safe)
  dropTables?: boolean;  // Control table dropping (--drop-tables, default: true)
}

Usage Examples:

# Show update queries without executing
mikro-orm schema:update --dump

# Update schema safely (no drops)
mikro-orm schema:update --run --safe

# Update with table dropping disabled
mikro-orm schema:update --run --drop-tables=false

# Update specific schema
mikro-orm schema:update --run --schema myschema

Drop Schema

Drops database schema including all tables, indexes, and constraints. Provides options for complete database cleanup.

/**
 * Drop database schema command
 */
command: "schema:drop"

interface SchemaDropOptions extends BaseArgs {
  run?: boolean;                  // Execute queries (--run / -r)
  dump?: boolean;                 // Dump queries to console (--dump / -d)
  fkChecks?: boolean;            // Include foreign key checks (--fk-checks)
  schema?: string;               // Set current schema for wildcard entities (--schema)
  dropMigrationsTable?: boolean; // Drop migrations table (--drop-migrations-table)
  dropDb?: boolean;              // Drop entire database (--drop-db)
}

Usage Examples:

# Show drop queries without executing
mikro-orm schema:drop --dump

# Drop schema but keep migrations table
mikro-orm schema:drop --run

# Drop schema including migrations table
mikro-orm schema:drop --run --drop-migrations-table

# Drop entire database
mikro-orm schema:drop --run --drop-db

Fresh Schema

Drops existing schema and recreates it from current entity definitions. Combines drop and create operations for clean schema reset.

/**
 * Drop and recreate database schema command
 */
command: "schema:fresh"

interface SchemaFreshOptions extends BaseArgs {
  run?: boolean;      // Execute queries (--run / -r)
  schema?: string;    // Set current schema for wildcard entities (--schema)
  seed?: string;      // Seed database after recreation (--seed)
  dropDb?: boolean;   // Drop entire database before recreating (--drop-db)
}

Usage Examples:

# Fresh schema recreation (must use --run)
mikro-orm schema:fresh --run

# Fresh schema with seeding
mikro-orm schema:fresh --run --seed TestDataSeeder

# Fresh with database drop and recreation
mikro-orm schema:fresh --run --drop-db

# Fresh for specific schema
mikro-orm schema:fresh --run --schema test_schema

Command Requirements

Execution Requirements

Schema commands require either --run or --dump option:

  • --run: Execute the schema operations
  • --dump: Display SQL queries without executing

Without one of these options, the command will show help instead of executing.

Safety Considerations

  • Production use: Always use --dump first to review queries
  • Backup data: Schema operations can be destructive
  • Safe mode: Use --safe for update operations to prevent data loss
  • Testing: Test schema changes in development environment first

Global Options

All schema commands support:

  • --config: Path to ORM configuration file(s)
  • --contextName / --context: Configuration context name

Command-Specific Options

Common Options

  • --run / -r: Execute the SQL queries
  • --dump / -d: Display queries in console without executing
  • --schema: Set current schema name for wildcard schema entities
  • --fk-checks: Include foreign key constraint checks (create/update/drop only)

Create/Fresh Specific

  • --seed: Run specified seeder class after schema creation

Update Specific

  • --safe: Disable destructive operations (table/column dropping)
  • --drop-tables: Control whether tables can be dropped (default: true)

Drop Specific

  • --drop-migrations-table: Include migrations table in drop operation
  • --drop-db: Drop entire database instead of just schema

Fresh Specific

  • --drop-db: Drop and recreate entire database

Error Handling

Common Schema Errors

  • Missing execution option: Commands require either --run or --dump
  • Permission errors: Database user needs schema modification privileges
  • Constraint violations: Existing data may prevent schema changes
  • Foreign key conflicts: Related tables may prevent drops/modifications
  • Syntax errors: Generated SQL may have database-specific issues

Schema Safety

  • Data preservation: Update operations may lose data in column modifications
  • Constraint validation: New constraints may conflict with existing data
  • Index rebuilding: Large tables may take time for index operations
  • Transaction handling: Schema operations may not be fully transactional

Database Support

Schema commands work with:

  • PostgreSQL: Full support including schemas, constraints, and indexes
  • MySQL/MariaDB: Complete support with proper type handling
  • SQLite: Basic support with standard SQL features
  • MongoDB: Not applicable (schema-less document database)

Configuration

Schema operations use these configuration options:

interface SchemaConfiguration {
  schemaGenerator?: {
    disableForeignKeys?: boolean;  // Disable FK checks during operations
    createForeignKeyConstraints?: boolean; // Create FK constraints
  };
  schema?: string;                 // Default schema name
  entities: string[];              // Entity definitions for schema generation
}

docs

cache.md

database.md

debug.md

entities.md

helper-api.md

index.md

migrations.md

schema.md

seeders.md

tile.json