@mikro-orm/cli 7.2.0-dev.2 → 7.2.0-dev.21
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.
- package/CLIConfigurator.d.ts +2 -0
- package/CLIConfigurator.js +6 -0
- package/CLIHelper.d.ts +6 -3
- package/CLIHelper.js +42 -3
- package/commands/ClearCacheCommand.js +2 -1
- package/commands/CompileCommand.js +9 -5
- package/commands/CreateDatabaseCommand.js +1 -0
- package/commands/CreateSeederCommand.js +2 -1
- package/commands/DatabaseSeedCommand.js +2 -1
- package/commands/DebugCommand.js +1 -0
- package/commands/DiscoveryExportCommand.d.ts +1 -0
- package/commands/DiscoveryExportCommand.js +9 -5
- package/commands/GenerateCacheCommand.js +6 -2
- package/commands/GenerateEntitiesCommand.js +5 -0
- package/commands/ImportCommand.js +2 -1
- package/commands/MigrationCommandFactory.js +11 -10
- package/commands/SchemaCommandFactory.js +2 -1
- package/package.json +3 -3
package/CLIConfigurator.d.ts
CHANGED
|
@@ -11,9 +11,11 @@ export interface BaseCommand<CommandArgs extends BaseArgs = BaseArgs> extends Co
|
|
|
11
11
|
declare function createBasicConfig(): Argv<{
|
|
12
12
|
config: string[] | undefined;
|
|
13
13
|
contextName: string;
|
|
14
|
+
quiet: boolean;
|
|
14
15
|
}>;
|
|
15
16
|
export declare function configure(): Promise<Argv<{
|
|
16
17
|
config: string[] | undefined;
|
|
17
18
|
contextName: string;
|
|
19
|
+
quiet: boolean;
|
|
18
20
|
}>>;
|
|
19
21
|
export {};
|
package/CLIConfigurator.js
CHANGED
|
@@ -30,6 +30,12 @@ function createBasicConfig() {
|
|
|
30
30
|
type: 'string',
|
|
31
31
|
desc: 'Set name of config to load out of the ORM configuration file. Used when config file exports an array or a function',
|
|
32
32
|
default: process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default',
|
|
33
|
+
})
|
|
34
|
+
.option('quiet', {
|
|
35
|
+
alias: 'q',
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
desc: 'Do not show any auxiliary output.',
|
|
38
|
+
default: false,
|
|
33
39
|
})
|
|
34
40
|
.alias('v', 'version')
|
|
35
41
|
.alias('h', 'help')
|
package/CLIHelper.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Configuration, type EntityManager, type EntityManagerType, type IDataba
|
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
5
|
export declare class CLIHelper {
|
|
6
|
+
static quiet: boolean;
|
|
6
7
|
/**
|
|
7
8
|
* Gets a named configuration
|
|
8
9
|
*
|
|
@@ -16,6 +17,7 @@ export declare class CLIHelper {
|
|
|
16
17
|
static isDBConnected(config: Configuration, reason?: false): Promise<boolean>;
|
|
17
18
|
static isDBConnected(config: Configuration, reason: true): Promise<true | string>;
|
|
18
19
|
static getDriverDependencies(config: Configuration): string[];
|
|
20
|
+
static info(text: string): void;
|
|
19
21
|
static dump(text: string, config?: Configuration): void;
|
|
20
22
|
static getSettings(): Settings;
|
|
21
23
|
static getConfigPaths(): Promise<string[]>;
|
|
@@ -35,18 +37,19 @@ export declare class CLIHelper {
|
|
|
35
37
|
empty: string;
|
|
36
38
|
}): void;
|
|
37
39
|
/**
|
|
38
|
-
* Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp
|
|
40
|
+
* Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp, nub
|
|
39
41
|
* Use `MIKRO_ORM_CLI_TS_LOADER` env var to set the loader explicitly.
|
|
42
|
+
* `nub` is skipped when a custom tsconfig path is used, and it supports only the legacy decorators.
|
|
40
43
|
* This method is used only in CLI context.
|
|
41
44
|
*/
|
|
42
|
-
static registerTypeScriptSupport(configPath?: string, tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'auto'): Promise<boolean>;
|
|
45
|
+
static registerTypeScriptSupport(configPath?: string, tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'nub' | 'auto'): Promise<boolean>;
|
|
43
46
|
static isESM(): boolean;
|
|
44
47
|
static showHelp(): void;
|
|
45
48
|
}
|
|
46
49
|
export interface Settings {
|
|
47
50
|
verbose?: boolean;
|
|
48
51
|
preferTs?: boolean;
|
|
49
|
-
tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'auto';
|
|
52
|
+
tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'nub' | 'auto';
|
|
50
53
|
tsConfigPath?: string;
|
|
51
54
|
configPaths?: string[];
|
|
52
55
|
}
|
package/CLIHelper.js
CHANGED
|
@@ -9,6 +9,7 @@ import { searchConfiguration } from './searchConfiguration.js';
|
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
export class CLIHelper {
|
|
12
|
+
static quiet = false;
|
|
12
13
|
/**
|
|
13
14
|
* Gets a named configuration
|
|
14
15
|
*
|
|
@@ -88,6 +89,13 @@ export class CLIHelper {
|
|
|
88
89
|
return [];
|
|
89
90
|
}
|
|
90
91
|
}
|
|
92
|
+
static info(text) {
|
|
93
|
+
if (CLIHelper.quiet) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// eslint-disable-next-line no-console
|
|
97
|
+
console.log(text);
|
|
98
|
+
}
|
|
91
99
|
static dump(text, config) {
|
|
92
100
|
if (config?.get('highlighter')) {
|
|
93
101
|
text = config.get('highlighter').highlight(text);
|
|
@@ -257,8 +265,9 @@ export class CLIHelper {
|
|
|
257
265
|
CLIHelper.dump(ret);
|
|
258
266
|
}
|
|
259
267
|
/**
|
|
260
|
-
* Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp
|
|
268
|
+
* Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp, nub
|
|
261
269
|
* Use `MIKRO_ORM_CLI_TS_LOADER` env var to set the loader explicitly.
|
|
270
|
+
* `nub` is skipped when a custom tsconfig path is used, and it supports only the legacy decorators.
|
|
262
271
|
* This method is used only in CLI context.
|
|
263
272
|
*/
|
|
264
273
|
static async registerTypeScriptSupport(configPath = 'tsconfig.json', tsLoader) {
|
|
@@ -270,32 +279,62 @@ export class CLIHelper {
|
|
|
270
279
|
process.env.TSIMP_PROJECT ??= configPath;
|
|
271
280
|
process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS ??= '1';
|
|
272
281
|
const explicitLoader = tsLoader ?? process.env.MIKRO_ORM_CLI_TS_LOADER ?? 'auto';
|
|
282
|
+
const usesDefaultTsConfig = fs.absolutePath(configPath) === fs.absolutePath('tsconfig.json');
|
|
273
283
|
const setEsmImportProvider = () => {
|
|
274
284
|
return (globalThis.dynamicImportProvider = (id) => import(id).then(mod => mod?.default ?? mod));
|
|
275
285
|
};
|
|
286
|
+
if (explicitLoader === 'nub' && !usesDefaultTsConfig) {
|
|
287
|
+
throw new Error('The `nub` loader does not support a custom tsconfig path. Use the project tsconfig.json or select another loader.');
|
|
288
|
+
}
|
|
276
289
|
const loaders = {
|
|
277
290
|
oxc: { esm: '@oxc-node/core/register', cjs: '@oxc-node/core/register' },
|
|
278
291
|
swc: { esm: '@swc-node/register/esm-register', cjs: '@swc-node/register' },
|
|
279
292
|
tsx: { esm: 'tsx/esm/api', cjs: 'tsx/cjs/api', cb: (tsx) => tsx.register({ tsconfig: configPath }) },
|
|
280
293
|
jiti: { cjs: 'jiti/register', cb: setEsmImportProvider },
|
|
281
294
|
tsimp: { cjs: 'tsimp/import', cb: setEsmImportProvider },
|
|
295
|
+
nub: { esm: '@nubjs/loader', cjs: '@nubjs/loader' },
|
|
282
296
|
};
|
|
297
|
+
const errors = [];
|
|
283
298
|
for (const loader of Utils.keys(loaders)) {
|
|
299
|
+
if (loader === 'nub' && !usesDefaultTsConfig) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
284
302
|
if (explicitLoader !== 'auto' && loader !== explicitLoader) {
|
|
285
303
|
continue;
|
|
286
304
|
}
|
|
287
305
|
const { esm, cjs, cb } = loaders[loader];
|
|
288
306
|
const isEsm = this.isESM();
|
|
289
307
|
const module = isEsm && esm ? esm : cjs;
|
|
290
|
-
|
|
308
|
+
let mod;
|
|
309
|
+
try {
|
|
310
|
+
mod = await Utils.tryImport({ module });
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
const error = new Error(`Failed to load TypeScript loader \`${loader}\` (${module}): ${e.message}`, {
|
|
314
|
+
cause: e,
|
|
315
|
+
});
|
|
316
|
+
if (explicitLoader !== 'auto') {
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
errors.push(error);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
291
322
|
if (mod) {
|
|
292
323
|
cb?.(mod);
|
|
293
324
|
process.env.MIKRO_ORM_CLI_TS_LOADER = loader;
|
|
294
325
|
return true;
|
|
295
326
|
}
|
|
296
327
|
}
|
|
328
|
+
// a loader that is installed but broken is a real problem, not a missing dependency
|
|
329
|
+
if (errors.length > 0) {
|
|
330
|
+
throw new Error(errors.map(e => e.message).join('\n'), { cause: errors[0] });
|
|
331
|
+
}
|
|
332
|
+
const loadersMessage = usesDefaultTsConfig
|
|
333
|
+
? '`oxc`, `swc`, `tsx`, `jiti`, `tsimp` nor `nub`'
|
|
334
|
+
: '`oxc`, `swc`, `tsx`, `jiti` nor `tsimp`';
|
|
335
|
+
const nubHint = usesDefaultTsConfig ? '' : ' The `nub` loader was skipped as a custom tsconfig path is configured.';
|
|
297
336
|
// eslint-disable-next-line no-console
|
|
298
|
-
console.warn(
|
|
337
|
+
console.warn(`Neither ${loadersMessage} found in the project dependencies, support for working with TypeScript files might not work.${nubHint} To use \`oxc\`, install \`@oxc-node/core\`. To use \`swc\`, install both \`@swc-node/register\` and \`@swc/core\`.`);
|
|
299
338
|
return false;
|
|
300
339
|
}
|
|
301
340
|
static isESM() {
|
|
@@ -7,6 +7,7 @@ export class ClearCacheCommand {
|
|
|
7
7
|
* @inheritDoc
|
|
8
8
|
*/
|
|
9
9
|
async handler(args) {
|
|
10
|
+
CLIHelper.quiet = args.quiet;
|
|
10
11
|
const config = await CLIHelper.getConfiguration(args.contextName, args.config);
|
|
11
12
|
if (!config.get('metadataCache').enabled) {
|
|
12
13
|
CLIHelper.dump(colors.red('Metadata cache is disabled in your configuration. Set cache.enabled to true to use this command.'));
|
|
@@ -14,6 +15,6 @@ export class ClearCacheCommand {
|
|
|
14
15
|
}
|
|
15
16
|
const cache = config.getMetadataCacheAdapter();
|
|
16
17
|
await cache.clear();
|
|
17
|
-
CLIHelper.
|
|
18
|
+
CLIHelper.info(colors.green('Metadata cache was successfully cleared'));
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -17,6 +17,7 @@ export class CompileCommand {
|
|
|
17
17
|
* @inheritDoc
|
|
18
18
|
*/
|
|
19
19
|
async handler(args) {
|
|
20
|
+
CLIHelper.quiet = args.quiet;
|
|
20
21
|
const config = await CLIHelper.getConfiguration(args.contextName, args.config);
|
|
21
22
|
const settings = CLIHelper.getSettings();
|
|
22
23
|
config.set('debug', !!settings.verbose);
|
|
@@ -51,12 +52,15 @@ export class CompileCommand {
|
|
|
51
52
|
mkdirSync(dirname(outPath), { recursive: true });
|
|
52
53
|
writeFileSync(outPath, output);
|
|
53
54
|
writeFileSync(dtsPath, dts);
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (args.quiet) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
CLIHelper.info(colors.green(`Compiled functions generated to ${outPath} (${captured.length} functions)`));
|
|
59
|
+
CLIHelper.info(`\nExample usage in your ORM config:\n`);
|
|
56
60
|
const importPath = esm ? './compiled-functions.js' : './compiled-functions';
|
|
57
|
-
CLIHelper.
|
|
58
|
-
CLIHelper.
|
|
59
|
-
CLIHelper.
|
|
61
|
+
CLIHelper.info(` ${esm ? 'import' : 'const'} compiledFunctions ${esm ? 'from ' : '= require('}${colors.cyan(`'${importPath}'`)}${esm ? '' : ')'};`);
|
|
62
|
+
CLIHelper.info('');
|
|
63
|
+
CLIHelper.info(` export default defineConfig({ compiledFunctions });\n`);
|
|
60
64
|
}
|
|
61
65
|
static capture(metadata, config) {
|
|
62
66
|
const captured = [];
|
|
@@ -14,10 +14,11 @@ export class CreateSeederCommand {
|
|
|
14
14
|
* @inheritDoc
|
|
15
15
|
*/
|
|
16
16
|
async handler(args) {
|
|
17
|
+
CLIHelper.quiet = args.quiet;
|
|
17
18
|
const className = CreateSeederCommand.getSeederClassName(args.seeder);
|
|
18
19
|
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
19
20
|
const path = await orm.seeder.create(className);
|
|
20
|
-
CLIHelper.
|
|
21
|
+
CLIHelper.info(colors.green(`Seeder ${args.seeder} successfully created at ${path}`));
|
|
21
22
|
await orm.close(true);
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
@@ -15,10 +15,11 @@ export class DatabaseSeedCommand {
|
|
|
15
15
|
* @inheritDoc
|
|
16
16
|
*/
|
|
17
17
|
async handler(args) {
|
|
18
|
+
CLIHelper.quiet = args.quiet;
|
|
18
19
|
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
19
20
|
const className = args.class ?? orm.config.get('seeder').defaultSeeder;
|
|
20
21
|
await orm.seeder.seedString(className);
|
|
21
|
-
CLIHelper.
|
|
22
|
+
CLIHelper.info(colors.green(`Seeder ${className} successfully executed`));
|
|
22
23
|
await orm.close(true);
|
|
23
24
|
}
|
|
24
25
|
}
|
package/commands/DebugCommand.js
CHANGED
|
@@ -41,6 +41,7 @@ export class DiscoveryExportCommand {
|
|
|
41
41
|
* @inheritDoc
|
|
42
42
|
*/
|
|
43
43
|
handler = async (args) => {
|
|
44
|
+
CLIHelper.quiet = args.quiet;
|
|
44
45
|
const config = await CLIHelper.getConfiguration(args.contextName, args.config);
|
|
45
46
|
const paths = this.resolvePaths(args, config);
|
|
46
47
|
const baseDir = fs.absolutePath(config.get('baseDir') ?? process.cwd());
|
|
@@ -60,13 +61,16 @@ export class DiscoveryExportCommand {
|
|
|
60
61
|
const output = this.generateFile(discovered, outPath, esm, driverPackage);
|
|
61
62
|
mkdirSync(dirname(outPath), { recursive: true });
|
|
62
63
|
writeFileSync(outPath, output);
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
if (args.quiet) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
CLIHelper.info(colors.green(`Entity exports generated to ${outPath} (${discovered.length} entities)`));
|
|
68
|
+
CLIHelper.info(`\nExample usage in your ORM config:\n`);
|
|
65
69
|
const importExt = esm ? '.js' : '';
|
|
66
70
|
const importPath = `./${basename(outPath).replace(/\.ts$/, importExt)}`;
|
|
67
|
-
CLIHelper.
|
|
68
|
-
CLIHelper.
|
|
69
|
-
CLIHelper.
|
|
71
|
+
CLIHelper.info(` import { entities } from ${colors.cyan(`'${importPath}'`)};`);
|
|
72
|
+
CLIHelper.info('');
|
|
73
|
+
CLIHelper.info(' export default defineConfig({ entities });\n');
|
|
70
74
|
};
|
|
71
75
|
resolvePaths(args, config) {
|
|
72
76
|
if (args.path && args.path.length > 0) {
|
|
@@ -10,6 +10,7 @@ export class GenerateCacheCommand {
|
|
|
10
10
|
desc: `Generate development cache for '.ts' files`,
|
|
11
11
|
});
|
|
12
12
|
args.option('combined', {
|
|
13
|
+
type: 'string',
|
|
13
14
|
alias: 'c',
|
|
14
15
|
desc: `Generate production cache into a single JSON file that can be used with the GeneratedCacheAdapter.`,
|
|
15
16
|
});
|
|
@@ -19,7 +20,10 @@ export class GenerateCacheCommand {
|
|
|
19
20
|
* @inheritDoc
|
|
20
21
|
*/
|
|
21
22
|
async handler(args) {
|
|
22
|
-
|
|
23
|
+
CLIHelper.quiet = args.quiet;
|
|
24
|
+
const options = typeof args.combined !== 'undefined'
|
|
25
|
+
? { combined: args.combined === '' ? './metadata.json' : args.combined }
|
|
26
|
+
: {};
|
|
23
27
|
const config = await CLIHelper.getConfiguration(args.contextName, args.config, {
|
|
24
28
|
metadataCache: { enabled: true, adapter: FileCacheAdapter, options },
|
|
25
29
|
});
|
|
@@ -29,6 +33,6 @@ export class GenerateCacheCommand {
|
|
|
29
33
|
const discovery = new MetadataDiscovery(new MetadataStorage(), config.getDriver().getPlatform(), config);
|
|
30
34
|
await discovery.discover(args.ts ?? false);
|
|
31
35
|
const combined = args.combined && config.get('metadataCache').combined;
|
|
32
|
-
CLIHelper.
|
|
36
|
+
CLIHelper.info(colors.green(`${combined ? 'Combined ' : ''}${args.ts ? 'TS' : 'JS'} metadata cache was successfully generated${combined ? ' to ' + combined : ''}`));
|
|
33
37
|
}
|
|
34
38
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CLIHelper } from '../CLIHelper.js';
|
|
2
|
+
import { colors } from '@mikro-orm/core';
|
|
2
3
|
export class GenerateEntitiesCommand {
|
|
3
4
|
command = 'generate-entities';
|
|
4
5
|
describe = 'Generate entities based on current database schema';
|
|
@@ -31,6 +32,7 @@ export class GenerateEntitiesCommand {
|
|
|
31
32
|
* @inheritDoc
|
|
32
33
|
*/
|
|
33
34
|
async handler(args) {
|
|
35
|
+
CLIHelper.quiet = args.quiet;
|
|
34
36
|
if (!args.save && !args.dump) {
|
|
35
37
|
return CLIHelper.showHelp();
|
|
36
38
|
}
|
|
@@ -43,6 +45,9 @@ export class GenerateEntitiesCommand {
|
|
|
43
45
|
if (args.dump) {
|
|
44
46
|
CLIHelper.dump(dump.join('\n\n'));
|
|
45
47
|
}
|
|
48
|
+
else {
|
|
49
|
+
CLIHelper.info(colors.green(`Entities generated successfully`));
|
|
50
|
+
}
|
|
46
51
|
await orm.close(true);
|
|
47
52
|
}
|
|
48
53
|
}
|
|
@@ -8,10 +8,11 @@ export class ImportCommand {
|
|
|
8
8
|
* @inheritDoc
|
|
9
9
|
*/
|
|
10
10
|
async handler(args) {
|
|
11
|
+
CLIHelper.quiet = args.quiet;
|
|
11
12
|
const orm = await CLIHelper.getORM(args.contextName, args.config, { multipleStatements: true });
|
|
12
13
|
const buf = await readFile(args.file);
|
|
13
14
|
await orm.em.getConnection().executeDump(buf.toString());
|
|
14
|
-
CLIHelper.
|
|
15
|
+
CLIHelper.info(colors.green(`File ${args.file} successfully imported`));
|
|
15
16
|
await orm.close(true);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
@@ -98,6 +98,7 @@ export class MigrationCommandFactory {
|
|
|
98
98
|
return args;
|
|
99
99
|
}
|
|
100
100
|
static async handleMigrationCommand(args, method) {
|
|
101
|
+
CLIHelper.quiet = args.quiet;
|
|
101
102
|
// to be able to run have a master transaction, but run marked migrations outside of it, we need a second connection
|
|
102
103
|
const options = { pool: { min: 1, max: 2 } };
|
|
103
104
|
const orm = await CLIHelper.getORM(args.contextName, args.config, options);
|
|
@@ -146,7 +147,7 @@ export class MigrationCommandFactory {
|
|
|
146
147
|
const opts = MigrationCommandFactory.getUpDownOptions(args);
|
|
147
148
|
await migrator[method](opts);
|
|
148
149
|
const message = this.getUpDownSuccessMessage(method, opts);
|
|
149
|
-
CLIHelper.
|
|
150
|
+
CLIHelper.info(colors.green(message));
|
|
150
151
|
}
|
|
151
152
|
static async handlePendingCommand(migrator) {
|
|
152
153
|
const pending = await migrator.getPending();
|
|
@@ -171,10 +172,10 @@ export class MigrationCommandFactory {
|
|
|
171
172
|
static async handleCreateCommand(migrator, args, config) {
|
|
172
173
|
const ret = await migrator.create(args.path, args.blank, args.initial, args.name);
|
|
173
174
|
if (ret.diff.up.length === 0) {
|
|
174
|
-
return CLIHelper.
|
|
175
|
+
return CLIHelper.info(colors.green(`No changes required, schema is up-to-date`));
|
|
175
176
|
}
|
|
176
177
|
if (args.dump) {
|
|
177
|
-
CLIHelper.
|
|
178
|
+
CLIHelper.info(colors.green('Creating migration with following queries:'));
|
|
178
179
|
CLIHelper.dump(colors.green('up:'));
|
|
179
180
|
CLIHelper.dump(ret.diff.up.map(sql => ' ' + sql).join('\n'), config);
|
|
180
181
|
/* v8 ignore if */
|
|
@@ -187,11 +188,11 @@ export class MigrationCommandFactory {
|
|
|
187
188
|
CLIHelper.dump(colors.yellow(`(${config.getDriver().constructor.name} does not support automatic down migrations)`));
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
|
-
CLIHelper.
|
|
191
|
+
CLIHelper.info(colors.green(`${ret.fileName} successfully created`));
|
|
191
192
|
}
|
|
192
193
|
static async handleCheckCommand(migrator, orm) {
|
|
193
194
|
if (!(await migrator.checkSchema())) {
|
|
194
|
-
return CLIHelper.
|
|
195
|
+
return CLIHelper.info(colors.green(`No changes required, schema is up-to-date`));
|
|
195
196
|
}
|
|
196
197
|
await orm.close(true);
|
|
197
198
|
CLIHelper.dump(colors.yellow(`Changes detected. Please create migration to update schema.`));
|
|
@@ -199,25 +200,25 @@ export class MigrationCommandFactory {
|
|
|
199
200
|
}
|
|
200
201
|
static async handleFreshCommand(args, migrator, orm) {
|
|
201
202
|
await orm.schema.drop({ dropMigrationsTable: true, dropDb: args.dropDb });
|
|
202
|
-
CLIHelper.
|
|
203
|
+
CLIHelper.info(colors.green('Dropped schema successfully'));
|
|
203
204
|
const opts = MigrationCommandFactory.getUpDownOptions(args);
|
|
204
205
|
await migrator.up(opts);
|
|
205
206
|
const message = this.getUpDownSuccessMessage('up', opts);
|
|
206
|
-
CLIHelper.
|
|
207
|
+
CLIHelper.info(colors.green(message));
|
|
207
208
|
if (args.seed !== undefined) {
|
|
208
209
|
const seederClass = args.seed || orm.config.get('seeder').defaultSeeder;
|
|
209
210
|
await orm.seeder.seedString(seederClass);
|
|
210
|
-
CLIHelper.
|
|
211
|
+
CLIHelper.info(colors.green(`Database seeded successfully with seeder class ${seederClass}`));
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
static async handleLogUnlogCommand(args, migrator, method) {
|
|
214
215
|
await migrator[`${method}Migration`](args.name);
|
|
215
216
|
const action = method === 'log' ? 'logged' : 'unlogged';
|
|
216
|
-
CLIHelper.
|
|
217
|
+
CLIHelper.info(colors.green(`Successfully ${action} migration '${args.name}'`));
|
|
217
218
|
}
|
|
218
219
|
static async handleRollupCommand(migrator) {
|
|
219
220
|
const ret = await migrator.rollup();
|
|
220
|
-
CLIHelper.
|
|
221
|
+
CLIHelper.info(colors.green(`${ret.fileName} successfully created (rollup)`));
|
|
221
222
|
}
|
|
222
223
|
static getUpDownOptions(flags) {
|
|
223
224
|
const ret = !flags.to && !flags.from && flags.only ? { migrations: flags.only.split(/[, ]+/) } : {};
|
|
@@ -76,6 +76,7 @@ export class SchemaCommandFactory {
|
|
|
76
76
|
return args;
|
|
77
77
|
}
|
|
78
78
|
static async handleSchemaCommand(args, method, successMessage) {
|
|
79
|
+
CLIHelper.quiet = args.quiet;
|
|
79
80
|
if (!args.run && !args.dump) {
|
|
80
81
|
return CLIHelper.showHelp();
|
|
81
82
|
}
|
|
@@ -102,7 +103,7 @@ export class SchemaCommandFactory {
|
|
|
102
103
|
if (typeof args.seed !== 'undefined') {
|
|
103
104
|
await orm.seeder.seedString(args.seed || orm.config.get('seeder').defaultSeeder);
|
|
104
105
|
}
|
|
105
|
-
CLIHelper.
|
|
106
|
+
CLIHelper.info(colors.green(successMessage));
|
|
106
107
|
await orm.close(true);
|
|
107
108
|
}
|
|
108
109
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/cli",
|
|
3
|
-
"version": "7.2.0-dev.
|
|
3
|
+
"version": "7.2.0-dev.21",
|
|
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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"copy": "node ../../scripts/copy.mjs"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/core": "7.2.0-dev.
|
|
54
|
-
"mikro-orm": "7.2.0-dev.
|
|
53
|
+
"@mikro-orm/core": "7.2.0-dev.21",
|
|
54
|
+
"mikro-orm": "7.2.0-dev.21",
|
|
55
55
|
"yargs": "17.7.2"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|