@mikro-orm/cli 7.1.0-dev.3 → 7.1.0-dev.31
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.js
CHANGED
|
@@ -73,5 +73,6 @@ export async function configure() {
|
|
|
73
73
|
.command(MigrationCommandFactory.create('fresh'))
|
|
74
74
|
.command(MigrationCommandFactory.create('log'))
|
|
75
75
|
.command(MigrationCommandFactory.create('unlog'))
|
|
76
|
+
.command(MigrationCommandFactory.create('rollup'))
|
|
76
77
|
.command(new DebugCommand());
|
|
77
78
|
}
|
package/CLIHelper.js
CHANGED
|
@@ -24,7 +24,6 @@ export class CLIHelper {
|
|
|
24
24
|
}
|
|
25
25
|
contextName ??= process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default';
|
|
26
26
|
const env = await this.loadEnvironmentVars();
|
|
27
|
-
await loadOptionalDependencies(options);
|
|
28
27
|
// oxfmt-ignore
|
|
29
28
|
const configFinder = (cfg) => {
|
|
30
29
|
return typeof cfg === 'object' && cfg !== null && ('contextName' in cfg ? cfg.contextName === contextName : contextName === 'default');
|
|
@@ -35,7 +34,9 @@ export class CLIHelper {
|
|
|
35
34
|
const result = await this.getConfigFile(paths);
|
|
36
35
|
if (!result[0]) {
|
|
37
36
|
if (Utils.hasObjectKeys(env)) {
|
|
38
|
-
|
|
37
|
+
const merged = Utils.mergeConfig({ contextName }, options.preferEnvVars ? options : env, options.preferEnvVars ? env : options);
|
|
38
|
+
await loadOptionalDependencies(merged);
|
|
39
|
+
return new Configuration(merged);
|
|
39
40
|
}
|
|
40
41
|
throw new Error(`MikroORM config file not found in ['${paths.join(`', '`)}']`);
|
|
41
42
|
}
|
|
@@ -209,6 +210,15 @@ export class CLIHelper {
|
|
|
209
210
|
case 'postgresql':
|
|
210
211
|
ret.driver ??= await import('@mikro-orm/postgresql').then(m => m.PostgreSqlDriver);
|
|
211
212
|
break;
|
|
213
|
+
case 'pglite': {
|
|
214
|
+
// Variable specifier (instead of a literal) keeps `@electric-sql/pglite`'s
|
|
215
|
+
// d.ts — which references DOM/Emscripten ambient globals not in our TS
|
|
216
|
+
// lib — out of the CLI's compile graph. Safe here: the CLI is a Node
|
|
217
|
+
// binary, not bundled into end-user apps.
|
|
218
|
+
const name = '@mikro-orm/pglite';
|
|
219
|
+
ret.driver ??= (await import(name)).PgliteDriver;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
212
222
|
case 'sqlite':
|
|
213
223
|
ret.driver ??= await import('@mikro-orm/sqlite').then(m => m.SqliteDriver);
|
|
214
224
|
break;
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL (including CockroachDB and PGlite), SQLite (including libSQL), MSSQL and Oracle databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
@@ -19,6 +19,7 @@ Install a driver package for your database:
|
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
npm install @mikro-orm/postgresql # PostgreSQL
|
|
22
|
+
npm install @mikro-orm/pglite # PGlite (embedded PostgreSQL in WASM)
|
|
22
23
|
npm install @mikro-orm/mysql # MySQL
|
|
23
24
|
npm install @mikro-orm/mariadb # MariaDB
|
|
24
25
|
npm install @mikro-orm/sqlite # SQLite
|
|
@@ -5,6 +5,7 @@ import { fs } from '@mikro-orm/core/fs-utils';
|
|
|
5
5
|
import { CLIHelper } from '../CLIHelper.js';
|
|
6
6
|
const driverPackageMap = {
|
|
7
7
|
PostgreSqlDriver: '@mikro-orm/postgresql',
|
|
8
|
+
PgliteDriver: '@mikro-orm/pglite',
|
|
8
9
|
MySqlDriver: '@mikro-orm/mysql',
|
|
9
10
|
MariaDbDriver: '@mikro-orm/mariadb',
|
|
10
11
|
SqliteDriver: '@mikro-orm/sqlite',
|
|
@@ -11,6 +11,7 @@ export declare class MigrationCommandFactory {
|
|
|
11
11
|
fresh: string;
|
|
12
12
|
log: string;
|
|
13
13
|
unlog: string;
|
|
14
|
+
rollup: string;
|
|
14
15
|
};
|
|
15
16
|
static create<const T extends MigratorMethod>(command: T): {
|
|
16
17
|
command: string;
|
|
@@ -24,6 +25,7 @@ export declare class MigrationCommandFactory {
|
|
|
24
25
|
fresh: string;
|
|
25
26
|
log: string;
|
|
26
27
|
unlog: string;
|
|
28
|
+
rollup: string;
|
|
27
29
|
}[T];
|
|
28
30
|
builder: (args: Argv<BaseArgs>) => Argv<MigrationOptionsMap[T]>;
|
|
29
31
|
handler: (args: ArgumentsCamelCase<MigrationOptionsMap[T]>) => Promise<void>;
|
|
@@ -41,6 +43,7 @@ export declare class MigrationCommandFactory {
|
|
|
41
43
|
private static handleCheckCommand;
|
|
42
44
|
private static handleFreshCommand;
|
|
43
45
|
private static handleLogUnlogCommand;
|
|
46
|
+
private static handleRollupCommand;
|
|
44
47
|
private static getUpDownOptions;
|
|
45
48
|
private static getUpDownSuccessMessage;
|
|
46
49
|
}
|
|
@@ -48,6 +51,7 @@ type CliUpDownOptions = BaseArgs & {
|
|
|
48
51
|
to?: string | number;
|
|
49
52
|
from?: string | number;
|
|
50
53
|
only?: string;
|
|
54
|
+
schema?: string;
|
|
51
55
|
};
|
|
52
56
|
type MigratorFreshOptions = BaseArgs & {
|
|
53
57
|
dropDb?: boolean;
|
|
@@ -73,6 +77,7 @@ type MigrationOptionsMap = {
|
|
|
73
77
|
fresh: MigratorFreshOptions;
|
|
74
78
|
log: MigratorLogUnlogOptions;
|
|
75
79
|
unlog: MigratorLogUnlogOptions;
|
|
80
|
+
rollup: BaseArgs;
|
|
76
81
|
};
|
|
77
82
|
type MigratorMethod = keyof MigrationOptionsMap;
|
|
78
83
|
type Opts = BaseArgs & MigratorCreateOptions & CliUpDownOptions & MigratorFreshOptions & MigratorLogUnlogOptions;
|
|
@@ -11,6 +11,7 @@ export class MigrationCommandFactory {
|
|
|
11
11
|
fresh: 'Clear the database and rerun all migrations',
|
|
12
12
|
log: 'Mark a migration as executed without running it',
|
|
13
13
|
unlog: 'Remove a migration from the executed list without reverting it',
|
|
14
|
+
rollup: 'Combine multiple migrations into a single migration',
|
|
14
15
|
};
|
|
15
16
|
static create(command) {
|
|
16
17
|
// oxfmt-ignore
|
|
@@ -61,6 +62,11 @@ export class MigrationCommandFactory {
|
|
|
61
62
|
type: 'string',
|
|
62
63
|
desc: 'Migrate only specified versions',
|
|
63
64
|
});
|
|
65
|
+
args.option('s', {
|
|
66
|
+
alias: 'schema',
|
|
67
|
+
type: 'string',
|
|
68
|
+
desc: 'Target schema to run the migration against (PostgreSQL, MySQL, Oracle)',
|
|
69
|
+
});
|
|
64
70
|
return args;
|
|
65
71
|
}
|
|
66
72
|
static configureCreateCommand(args) {
|
|
@@ -119,6 +125,9 @@ export class MigrationCommandFactory {
|
|
|
119
125
|
case 'unlog':
|
|
120
126
|
await this.handleLogUnlogCommand(args, orm.migrator, method);
|
|
121
127
|
break;
|
|
128
|
+
case 'rollup':
|
|
129
|
+
await this.handleRollupCommand(orm.migrator);
|
|
130
|
+
break;
|
|
122
131
|
}
|
|
123
132
|
await orm.close(true);
|
|
124
133
|
}
|
|
@@ -206,12 +215,16 @@ export class MigrationCommandFactory {
|
|
|
206
215
|
const action = method === 'log' ? 'logged' : 'unlogged';
|
|
207
216
|
CLIHelper.dump(colors.green(`Successfully ${action} migration '${args.name}'`));
|
|
208
217
|
}
|
|
218
|
+
static async handleRollupCommand(migrator) {
|
|
219
|
+
const ret = await migrator.rollup();
|
|
220
|
+
CLIHelper.dump(colors.green(`${ret.fileName} successfully created (rollup)`));
|
|
221
|
+
}
|
|
209
222
|
static getUpDownOptions(flags) {
|
|
210
|
-
|
|
211
|
-
return { migrations: flags.only.split(/[, ]+/) };
|
|
212
|
-
}
|
|
213
|
-
const ret = {};
|
|
223
|
+
const ret = !flags.to && !flags.from && flags.only ? { migrations: flags.only.split(/[, ]+/) } : {};
|
|
214
224
|
['from', 'to'].filter(k => flags[k]).forEach(k => (ret[k] = flags[k] === '0' ? 0 : flags[k]));
|
|
225
|
+
if (flags.schema) {
|
|
226
|
+
ret.schema = flags.schema;
|
|
227
|
+
}
|
|
215
228
|
return ret;
|
|
216
229
|
}
|
|
217
230
|
static getUpDownSuccessMessage(method, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/cli",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.31",
|
|
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.1.0-dev.
|
|
54
|
-
"mikro-orm": "7.1.0-dev.
|
|
53
|
+
"@mikro-orm/core": "7.1.0-dev.31",
|
|
54
|
+
"mikro-orm": "7.1.0-dev.31",
|
|
55
55
|
"yargs": "17.7.2"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|