@mikro-orm/cli 7.0.4-dev.8 → 7.0.4
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 +7 -6
- package/CLIConfigurator.js +51 -51
- package/CLIHelper.d.ts +58 -45
- package/CLIHelper.js +325 -313
- package/README.md +1 -1
- package/cli.js +1 -1
- package/commands/ClearCacheCommand.d.ts +6 -6
- package/commands/ClearCacheCommand.js +16 -14
- package/commands/CompileCommand.d.ts +16 -13
- package/commands/CompileCommand.js +88 -83
- package/commands/CreateDatabaseCommand.d.ts +6 -6
- package/commands/CreateDatabaseCommand.js +10 -10
- package/commands/CreateSeederCommand.d.ts +12 -12
- package/commands/CreateSeederCommand.js +28 -27
- package/commands/DatabaseSeedCommand.d.ts +8 -8
- package/commands/DatabaseSeedCommand.js +20 -20
- package/commands/DebugCommand.d.ts +7 -7
- package/commands/DebugCommand.js +74 -71
- package/commands/GenerateCacheCommand.d.ts +9 -9
- package/commands/GenerateCacheCommand.js +33 -29
- package/commands/GenerateEntitiesCommand.d.ts +14 -14
- package/commands/GenerateEntitiesCommand.js +43 -43
- package/commands/ImportCommand.d.ts +7 -7
- package/commands/ImportCommand.js +12 -12
- package/commands/MigrationCommandFactory.d.ts +58 -53
- package/commands/MigrationCommandFactory.js +192 -191
- package/commands/SchemaCommandFactory.d.ts +42 -32
- package/commands/SchemaCommandFactory.js +97 -100
- package/package.json +3 -3
|
@@ -1,108 +1,105 @@
|
|
|
1
1
|
import { colors } from '@mikro-orm/core';
|
|
2
2
|
import { CLIHelper } from '../CLIHelper.js';
|
|
3
3
|
export class SchemaCommandFactory {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
static DESCRIPTIONS = {
|
|
5
|
+
create: 'Create database schema based on current metadata',
|
|
6
|
+
update: 'Update database schema based on current metadata',
|
|
7
|
+
drop: 'Drop database schema based on current metadata',
|
|
8
|
+
fresh: 'Drop and recreate database schema based on current metadata',
|
|
9
|
+
};
|
|
10
|
+
static SUCCESS_MESSAGES = {
|
|
11
|
+
create: 'Schema successfully created',
|
|
12
|
+
update: 'Schema successfully updated',
|
|
13
|
+
drop: 'Schema successfully dropped',
|
|
14
|
+
fresh: 'Schema successfully dropped and recreated',
|
|
15
|
+
};
|
|
16
|
+
static create(command) {
|
|
17
|
+
const successMessage = SchemaCommandFactory.SUCCESS_MESSAGES[command];
|
|
18
|
+
return {
|
|
19
|
+
command: `schema:${command}`,
|
|
20
|
+
describe: SchemaCommandFactory.DESCRIPTIONS[command],
|
|
21
|
+
builder: args => SchemaCommandFactory.configureSchemaCommand(args, command),
|
|
22
|
+
handler: args => SchemaCommandFactory.handleSchemaCommand(args, command, successMessage),
|
|
9
23
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
}
|
|
25
|
+
static configureSchemaCommand(args, command) {
|
|
26
|
+
args.option('r', {
|
|
27
|
+
alias: 'run',
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
desc: 'Runs queries',
|
|
30
|
+
});
|
|
31
|
+
if (command !== 'fresh') {
|
|
32
|
+
args.option('d', {
|
|
33
|
+
alias: 'dump',
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
desc: 'Dumps all queries to console',
|
|
36
|
+
});
|
|
37
|
+
args.option('fk-checks', {
|
|
38
|
+
type: 'boolean',
|
|
39
|
+
desc: 'Do not skip foreign key checks',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
args.option('schema', {
|
|
43
|
+
type: 'string',
|
|
44
|
+
desc: 'Set the current schema for wildcard schema entities',
|
|
45
|
+
});
|
|
46
|
+
if (['create', 'fresh'].includes(command)) {
|
|
47
|
+
args.option('seed', {
|
|
48
|
+
type: 'string',
|
|
49
|
+
desc: 'Allows to seed the database on create or drop and recreate',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (command === 'update') {
|
|
53
|
+
args.option('safe', {
|
|
54
|
+
type: 'boolean',
|
|
55
|
+
desc: 'Allows to disable table and column dropping',
|
|
56
|
+
default: false,
|
|
57
|
+
});
|
|
58
|
+
args.option('drop-tables', {
|
|
59
|
+
type: 'boolean',
|
|
60
|
+
desc: 'Allows to disable table dropping',
|
|
61
|
+
default: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (command === 'drop') {
|
|
65
|
+
args.option('drop-migrations-table', {
|
|
66
|
+
type: 'boolean',
|
|
67
|
+
desc: 'Drop also migrations table',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (['drop', 'fresh'].includes(command)) {
|
|
71
|
+
args.option('drop-db', {
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
desc: 'Drop the whole database',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return args;
|
|
77
|
+
}
|
|
78
|
+
static async handleSchemaCommand(args, method, successMessage) {
|
|
79
|
+
if (!args.run && !args.dump) {
|
|
80
|
+
return CLIHelper.showHelp();
|
|
24
81
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
args.option('schema', {
|
|
43
|
-
type: 'string',
|
|
44
|
-
desc: 'Set the current schema for wildcard schema entities',
|
|
45
|
-
});
|
|
46
|
-
if (['create', 'fresh'].includes(command)) {
|
|
47
|
-
args.option('seed', {
|
|
48
|
-
type: 'string',
|
|
49
|
-
desc: 'Allows to seed the database on create or drop and recreate',
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
if (command === 'update') {
|
|
53
|
-
args.option('safe', {
|
|
54
|
-
type: 'boolean',
|
|
55
|
-
desc: 'Allows to disable table and column dropping',
|
|
56
|
-
default: false,
|
|
57
|
-
});
|
|
58
|
-
args.option('drop-tables', {
|
|
59
|
-
type: 'boolean',
|
|
60
|
-
desc: 'Allows to disable table dropping',
|
|
61
|
-
default: true,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (command === 'drop') {
|
|
65
|
-
args.option('drop-migrations-table', {
|
|
66
|
-
type: 'boolean',
|
|
67
|
-
desc: 'Drop also migrations table',
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (['drop', 'fresh'].includes(command)) {
|
|
71
|
-
args.option('drop-db', {
|
|
72
|
-
type: 'boolean',
|
|
73
|
-
desc: 'Drop the whole database',
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return args;
|
|
82
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
83
|
+
const params = { wrap: args.fkChecks == null ? undefined : !args.fkChecks, ...args };
|
|
84
|
+
if (args.dump) {
|
|
85
|
+
const m = `get${method.substring(0, 1).toUpperCase()}${method.substring(1)}SchemaSQL`;
|
|
86
|
+
const dump = await orm.schema[m](params);
|
|
87
|
+
/* v8 ignore if */
|
|
88
|
+
if (dump) {
|
|
89
|
+
CLIHelper.dump(dump, orm.config);
|
|
90
|
+
successMessage = '';
|
|
91
|
+
} else {
|
|
92
|
+
successMessage = 'Schema is up-to-date';
|
|
93
|
+
}
|
|
94
|
+
} else if (method === 'fresh') {
|
|
95
|
+
await orm.schema.refresh(params);
|
|
96
|
+
} else {
|
|
97
|
+
await orm.schema[method](params);
|
|
77
98
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return CLIHelper.showHelp();
|
|
81
|
-
}
|
|
82
|
-
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
83
|
-
const params = { wrap: args.fkChecks == null ? undefined : !args.fkChecks, ...args };
|
|
84
|
-
if (args.dump) {
|
|
85
|
-
const m = `get${method.substring(0, 1).toUpperCase()}${method.substring(1)}SchemaSQL`;
|
|
86
|
-
const dump = await orm.schema[m](params);
|
|
87
|
-
/* v8 ignore if */
|
|
88
|
-
if (dump) {
|
|
89
|
-
CLIHelper.dump(dump, orm.config);
|
|
90
|
-
successMessage = '';
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
successMessage = 'Schema is up-to-date';
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else if (method === 'fresh') {
|
|
97
|
-
await orm.schema.refresh(params);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
await orm.schema[method](params);
|
|
101
|
-
}
|
|
102
|
-
if (typeof args.seed !== 'undefined') {
|
|
103
|
-
await orm.seeder.seedString(args.seed || orm.config.get('seeder').defaultSeeder);
|
|
104
|
-
}
|
|
105
|
-
CLIHelper.dump(colors.green(successMessage));
|
|
106
|
-
await orm.close(true);
|
|
99
|
+
if (typeof args.seed !== 'undefined') {
|
|
100
|
+
await orm.seeder.seedString(args.seed || orm.config.get('seeder').defaultSeeder);
|
|
107
101
|
}
|
|
102
|
+
CLIHelper.dump(colors.green(successMessage));
|
|
103
|
+
await orm.close(true);
|
|
104
|
+
}
|
|
108
105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/cli",
|
|
3
|
-
"version": "7.0.4
|
|
3
|
+
"version": "7.0.4",
|
|
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.0.4
|
|
54
|
-
"mikro-orm": "7.0.4
|
|
53
|
+
"@mikro-orm/core": "7.0.4",
|
|
54
|
+
"mikro-orm": "7.0.4",
|
|
55
55
|
"yargs": "17.7.2"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|