@mikro-orm/cli 6.3.14-dev.66 → 6.3.14-dev.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,5 +15,7 @@ export declare class CLIConfigurator {
15
15
  private static createBasicConfig;
16
16
  static configure(): yargs.Argv<{
17
17
  config: string[] | undefined;
18
+ } & {
19
+ contextName: string;
18
20
  }>;
19
21
  }
@@ -29,6 +29,12 @@ class CLIConfigurator {
29
29
  type: 'string',
30
30
  array: true,
31
31
  desc: `Set path to the ORM configuration file`,
32
+ })
33
+ .option('contextName', {
34
+ alias: 'context',
35
+ type: 'string',
36
+ desc: 'Set name of config to load out of the ORM configuration file. Used when config file exports an array or a function',
37
+ default: process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default',
32
38
  })
33
39
  .alias('v', 'version')
34
40
  .alias('h', 'help')
package/CLIHelper.d.ts CHANGED
@@ -3,8 +3,8 @@ import { MikroORM, type Configuration, type IDatabaseDriver, type Options } from
3
3
  * @internal
4
4
  */
5
5
  export declare class CLIHelper {
6
- static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver>(configPaths?: string[], options?: Partial<Options<D>>, validate?: boolean): Promise<Configuration<D>>;
7
- static getORM<D extends IDatabaseDriver = IDatabaseDriver>(configPaths?: string[], opts?: Partial<Options<D>>, validate?: boolean): Promise<MikroORM<D>>;
6
+ static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver>(contextName?: string, configPaths?: string[], options?: Partial<Options<D>>): Promise<Configuration<D>>;
7
+ static getORM<D extends IDatabaseDriver = IDatabaseDriver>(contextName?: string, configPaths?: string[], opts?: Partial<Options<D>>): Promise<MikroORM<D>>;
8
8
  static isDBConnected(config: Configuration, reason?: false): Promise<boolean>;
9
9
  static isDBConnected(config: Configuration, reason: true): Promise<true | string>;
10
10
  static getNodeVersion(): string;
package/CLIHelper.js CHANGED
@@ -11,7 +11,7 @@ const core_1 = require("@mikro-orm/core");
11
11
  * @internal
12
12
  */
13
13
  class CLIHelper {
14
- static async getConfiguration(configPaths, options = {}, validate = true) {
14
+ static async getConfiguration(contextName, configPaths, options = {}) {
15
15
  const deps = core_1.ConfigurationLoader.getORMPackages();
16
16
  if (!deps.has('@mikro-orm/cli') && !process.env.MIKRO_ORM_ALLOW_GLOBAL_CLI) {
17
17
  throw new Error('@mikro-orm/cli needs to be installed as a local dependency!');
@@ -19,10 +19,11 @@ class CLIHelper {
19
19
  core_1.ConfigurationLoader.commonJSCompat(options);
20
20
  core_1.ConfigurationLoader.registerDotenv(options);
21
21
  configPaths ??= core_1.ConfigurationLoader.getConfigPaths();
22
- return core_1.ConfigurationLoader.getConfiguration(configPaths, options, validate);
22
+ contextName ??= process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default';
23
+ return core_1.ConfigurationLoader.getConfiguration(contextName, configPaths, options);
23
24
  }
24
- static async getORM(configPaths, opts = {}, validate) {
25
- const options = await CLIHelper.getConfiguration(configPaths, opts, validate);
25
+ static async getORM(contextName, configPaths, opts = {}) {
26
+ const options = await CLIHelper.getConfiguration(contextName, configPaths, opts);
26
27
  const settings = core_1.ConfigurationLoader.getSettings();
27
28
  options.set('allowGlobalContext', true);
28
29
  options.set('debug', !!settings.verbose);
@@ -10,7 +10,7 @@ class ClearCacheCommand {
10
10
  * @inheritDoc
11
11
  */
12
12
  async handler(args) {
13
- const config = await CLIHelper_1.CLIHelper.getConfiguration(args.config);
13
+ const config = await CLIHelper_1.CLIHelper.getConfiguration(args.contextName, args.config);
14
14
  if (!config.get('metadataCache').enabled) {
15
15
  CLIHelper_1.CLIHelper.dump(core_1.colors.red('Metadata cache is disabled in your configuration. Set cache.enabled to true to use this command.'));
16
16
  return;
@@ -9,7 +9,7 @@ class CreateDatabaseCommand {
9
9
  * @inheritDoc
10
10
  */
11
11
  async handler(args) {
12
- const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
12
+ const orm = await CLIHelper_1.CLIHelper.getORM(args.contextName, args.config);
13
13
  const schemaGenerator = orm.getSchemaGenerator();
14
14
  await schemaGenerator.ensureDatabase();
15
15
  await orm.close(true);
@@ -18,7 +18,7 @@ class CreateSeederCommand {
18
18
  */
19
19
  async handler(args) {
20
20
  const className = CreateSeederCommand.getSeederClassName(args.seeder);
21
- const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
21
+ const orm = await CLIHelper_1.CLIHelper.getORM(args.contextName, args.config);
22
22
  const seeder = orm.getSeeder();
23
23
  const path = await seeder.createSeeder(className);
24
24
  CLIHelper_1.CLIHelper.dump(core_1.colors.green(`Seeder ${args.seeder} successfully created at ${path}`));
@@ -18,7 +18,7 @@ class DatabaseSeedCommand {
18
18
  * @inheritDoc
19
19
  */
20
20
  async handler(args) {
21
- const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
21
+ const orm = await CLIHelper_1.CLIHelper.getORM(args.contextName, args.config);
22
22
  const className = args.class ?? orm.config.get('seeder').defaultSeeder;
23
23
  await orm.getSeeder().seedString(className);
24
24
  CLIHelper_1.CLIHelper.dump(core_1.colors.green(`Seeder ${className} successfully executed`));
@@ -19,8 +19,9 @@ class DebugCommand {
19
19
  const configPaths = args.config ?? CLIHelper_1.CLIHelper.getConfigPaths();
20
20
  CLIHelper_1.CLIHelper.dump(' - searched config paths:');
21
21
  await DebugCommand.checkPaths(configPaths, 'yellow');
22
+ CLIHelper_1.CLIHelper.dump(` - searched for config name: ${core_1.colors.green(args.contextName)}`);
22
23
  try {
23
- const config = await CLIHelper_1.CLIHelper.getConfiguration(configPaths);
24
+ const config = await CLIHelper_1.CLIHelper.getConfiguration(args.contextName, configPaths);
24
25
  CLIHelper_1.CLIHelper.dump(` - configuration ${core_1.colors.green('found')}`);
25
26
  const drivers = CLIHelper_1.CLIHelper.getDriverDependencies(config);
26
27
  CLIHelper_1.CLIHelper.dump(' - driver dependencies:');
@@ -23,7 +23,7 @@ class GenerateCacheCommand {
23
23
  */
24
24
  async handler(args) {
25
25
  const options = args.combined ? { combined: './metadata.json' } : {};
26
- const config = await CLIHelper_1.CLIHelper.getConfiguration(args.config, {
26
+ const config = await CLIHelper_1.CLIHelper.getConfiguration(args.contextName, args.config, {
27
27
  metadataCache: { enabled: true, adapter: core_1.FileCacheAdapter, options },
28
28
  });
29
29
  config.getMetadataCacheAdapter().clear();
@@ -37,7 +37,7 @@ class GenerateEntitiesCommand {
37
37
  if (!args.save && !args.dump) {
38
38
  return CLIHelper_1.CLIHelper.showHelp();
39
39
  }
40
- const orm = await CLIHelper_1.CLIHelper.getORM(args.config, { discovery: { warnWhenNoEntities: false } });
40
+ const orm = await CLIHelper_1.CLIHelper.getORM(args.contextName, args.config, { discovery: { warnWhenNoEntities: false } });
41
41
  const dump = await orm.entityGenerator.generate({
42
42
  save: args.save,
43
43
  path: args.path,
@@ -10,7 +10,7 @@ class ImportCommand {
10
10
  * @inheritDoc
11
11
  */
12
12
  async handler(args) {
13
- const orm = await CLIHelper_1.CLIHelper.getORM(args.config, { multipleStatements: true });
13
+ const orm = await CLIHelper_1.CLIHelper.getORM(args.contextName, args.config, { multipleStatements: true });
14
14
  await orm.em.getConnection().loadFile(args.file);
15
15
  CLIHelper_1.CLIHelper.dump(core_1.colors.green(`File ${args.file} successfully imported`));
16
16
  await orm.close(true);
@@ -82,7 +82,7 @@ class MigrationCommandFactory {
82
82
  static async handleMigrationCommand(args, method) {
83
83
  // to be able to run have a master transaction, but run marked migrations outside of it, we need a second connection
84
84
  const options = { pool: { min: 1, max: 2 } };
85
- const orm = await CLIHelper_1.CLIHelper.getORM(args.config, options);
85
+ const orm = await CLIHelper_1.CLIHelper.getORM(args.contextName, args.config, options);
86
86
  const migrator = orm.getMigrator();
87
87
  switch (method) {
88
88
  case 'create':
@@ -82,7 +82,7 @@ class SchemaCommandFactory {
82
82
  if (!args.run && !args.dump) {
83
83
  return CLIHelper_1.CLIHelper.showHelp();
84
84
  }
85
- const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
85
+ const orm = await CLIHelper_1.CLIHelper.getORM(args.contextName, args.config);
86
86
  const generator = orm.getSchemaGenerator();
87
87
  const params = { wrap: args.fkChecks == null ? undefined : !args.fkChecks, ...args };
88
88
  if (args.dump) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/cli",
3
- "version": "6.3.14-dev.66",
3
+ "version": "6.3.14-dev.68",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -63,8 +63,8 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@jercle/yargonaut": "1.1.5",
66
- "@mikro-orm/core": "6.3.14-dev.66",
67
- "@mikro-orm/knex": "6.3.14-dev.66",
66
+ "@mikro-orm/core": "6.3.14-dev.68",
67
+ "@mikro-orm/knex": "6.3.14-dev.68",
68
68
  "fs-extra": "11.2.0",
69
69
  "tsconfig-paths": "4.2.0",
70
70
  "yargs": "17.7.2"