or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-mikro-orm--cli

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@mikro-orm/cli@6.5.x

To install, run

npx @tessl/cli install tessl/npm-mikro-orm--cli@6.5.0

0

# MikroORM CLI

1

2

MikroORM 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).

3

4

## Package Information

5

6

- **Package Name**: @mikro-orm/cli

7

- **Package Type**: npm

8

- **Language**: TypeScript

9

- **Installation**: `npm install @mikro-orm/cli` or `yarn add @mikro-orm/cli`

10

11

## Core Imports

12

13

```typescript

14

import { CLIHelper, CLIConfigurator } from "@mikro-orm/cli";

15

```

16

17

For CommonJS:

18

19

```javascript

20

const { CLIHelper, CLIConfigurator } = require("@mikro-orm/cli");

21

```

22

23

## Basic Usage

24

25

Install and use as a CLI tool:

26

27

```bash

28

# Install as dependency

29

npm install @mikro-orm/cli

30

31

# Use the CLI

32

npx mikro-orm debug

33

npx mikro-orm migration:create

34

npx mikro-orm schema:update --run

35

```

36

37

Global installation:

38

39

```bash

40

# Install globally

41

npm install -g @mikro-orm/cli

42

43

# Use directly

44

mikro-orm debug

45

mikro-orm migration:create

46

mikro-orm schema:update --run

47

```

48

49

## Architecture

50

51

MikroORM CLI is built around several key components:

52

53

- **CLI Entry Points**: Two executable entry points (`mikro-orm` for CommonJS, `mikro-orm-esm` for ESM)

54

- **Command System**: Yargs-based command registration with typed arguments and builder patterns

55

- **Helper System**: `CLIHelper` class providing common ORM operations and utilities

56

- **Configuration System**: `CLIConfigurator` class managing command setup and configuration loading

57

- **Command Factories**: Factory classes for generating related commands (migrations, schema operations)

58

- **Command Categories**: Commands organized by functionality (cache, database, entities, migrations, schema, seeders, debug)

59

60

## Capabilities

61

62

### Cache Management

63

64

Commands for managing MikroORM's metadata cache system.

65

66

```typescript { .api }

67

// Clear metadata cache

68

command: "cache:clear"

69

70

// Generate metadata cache

71

command: "cache:generate"

72

```

73

74

[Cache Commands](./cache.md)

75

76

### Database Operations

77

78

Core database management operations including creation and import functionality.

79

80

```typescript { .api }

81

// Create database if it doesn't exist

82

command: "database:create"

83

84

// Import SQL file to database

85

command: "database:import <file>"

86

```

87

88

[Database Commands](./database.md)

89

90

### Entity Management

91

92

Generate TypeScript entities from existing database schemas.

93

94

```typescript { .api }

95

// Generate entities from database schema

96

command: "generate-entities"

97

```

98

99

[Entity Commands](./entities.md)

100

101

### Migration System

102

103

Complete database migration management with creation, execution, and tracking capabilities.

104

105

```typescript { .api }

106

// Migration commands

107

command: "migration:create" // Create new migration

108

command: "migration:up" // Migrate up to latest

109

command: "migration:down" // Migrate one step down

110

command: "migration:list" // List executed migrations

111

command: "migration:check" // Check if migrations needed

112

command: "migration:pending" // List pending migrations

113

command: "migration:fresh" // Clear database and rerun all migrations

114

```

115

116

[Migration Commands](./migrations.md)

117

118

### Schema Operations

119

120

Database schema management operations for creating, updating, and dropping schemas.

121

122

```typescript { .api }

123

// Schema commands

124

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

125

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

126

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

127

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

128

```

129

130

[Schema Commands](./schema.md)

131

132

### Seeding System

133

134

Database seeding functionality for populating databases with test or initial data.

135

136

```typescript { .api }

137

// Seeder commands

138

command: "seeder:run" // Run seeder class

139

command: "seeder:create <seeder>" // Create new seeder class

140

```

141

142

[Seeder Commands](./seeders.md)

143

144

### Debug and Utilities

145

146

Debugging and utility commands for configuration validation and troubleshooting.

147

148

```typescript { .api }

149

// Debug CLI configuration

150

command: "debug"

151

```

152

153

[Debug Commands](./debug.md)

154

155

### Helper API

156

157

The CLIHelper class provides programmatic access to CLI functionality for custom tooling.

158

159

```typescript { .api }

160

class CLIHelper {

161

static getConfiguration<D>(contextName?: string, configPaths?: string[], options?: Partial<Options<D>>): Promise<Configuration<D>>;

162

static getORM<D>(contextName?: string, configPaths?: string[], opts?: Partial<Options<D>>): Promise<MikroORM<D>>;

163

static isDBConnected(config: Configuration, reason?: boolean): Promise<boolean | string>;

164

static dump(text: string, config?: Configuration): void;

165

static dumpTable(options: TableOptions): void;

166

static showHelp(): void;

167

}

168

```

169

170

[Helper API](./helper-api.md)

171

172

## Global Options

173

174

All commands support these global options:

175

176

```typescript { .api }

177

interface BaseArgs {

178

config?: string[]; // Path to ORM configuration file(s)

179

contextName?: string; // Configuration context name (default: 'default')

180

context?: string; // Alias for contextName

181

}

182

```

183

184

Additional global flags:

185

- `--version` / `-v`: Show version information

186

- `--help` / `-h`: Show help information

187

188

## Types

189

190

```typescript { .api }

191

// Base argument types

192

interface BaseArgs {

193

config?: string[];

194

contextName?: string;

195

context?: string;

196

}

197

198

// Command interface

199

interface BaseCommand<CommandArgs extends BaseArgs = BaseArgs> extends CommandModule<BaseArgs, CommandArgs> {}

200

201

// Table formatting options

202

interface TableOptions {

203

columns: string[];

204

rows: string[][];

205

empty: string;

206

}

207

```