@mikro-orm/knex 6.1.9-dev.1 → 6.1.9-dev.11
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/README.md +1 -0
- package/package.json +2 -2
- package/schema/SchemaHelper.d.ts +1 -0
- package/schema/SchemaHelper.js +3 -0
- package/schema/SqlSchemaGenerator.js +24 -3
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-or
|
|
|
9
9
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
10
10
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
11
11
|
[](https://join.slack.com/t/mikroorm/shared_invite/enQtNTM1ODYzMzM4MDk3LWM4ZDExMjU5ZDhmNjA2MmM3MWMwZmExNjhhNDdiYTMwNWM0MGY5ZTE3ZjkyZTMzOWExNDgyYmMzNDE1NDI5NjA)
|
|
12
|
+
[](https://discord.gg/ynAmaVDV)
|
|
12
13
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
13
14
|
[](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
|
|
14
15
|
[](https://codeclimate.com/github/mikro-orm/mikro-orm/maintainability)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.1.9-dev.
|
|
3
|
+
"version": "6.1.9-dev.11",
|
|
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",
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.1.8"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.1.9-dev.
|
|
69
|
+
"@mikro-orm/core": "6.1.9-dev.11"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare abstract class SchemaHelper {
|
|
|
18
18
|
getForeignKeys(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<Dictionary>;
|
|
19
19
|
protected getTableKey(t: Table): string;
|
|
20
20
|
getEnumDefinitions(connection: AbstractSqlConnection, checks: CheckDef[], tableName: string, schemaName?: string): Promise<Dictionary<string[]>>;
|
|
21
|
+
getCreateNativeEnumSQL(name: string, values: unknown[], schema?: string): string;
|
|
21
22
|
getDropNativeEnumSQL(name: string, schema?: string): string;
|
|
22
23
|
getAlterNativeEnumSQL(name: string, schema?: string, value?: string): string;
|
|
23
24
|
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -47,6 +47,9 @@ class SchemaHelper {
|
|
|
47
47
|
async getEnumDefinitions(connection, checks, tableName, schemaName) {
|
|
48
48
|
return {};
|
|
49
49
|
}
|
|
50
|
+
getCreateNativeEnumSQL(name, values, schema) {
|
|
51
|
+
throw new Error('Not supported by given driver');
|
|
52
|
+
}
|
|
50
53
|
getDropNativeEnumSQL(name, schema) {
|
|
51
54
|
throw new Error('Not supported by given driver');
|
|
52
55
|
}
|
|
@@ -60,6 +60,17 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
60
60
|
}
|
|
61
61
|
ret += await this.dump(this.knex.schema.createSchemaIfNotExists(namespace));
|
|
62
62
|
}
|
|
63
|
+
if (this.platform.supportsNativeEnums()) {
|
|
64
|
+
const created = [];
|
|
65
|
+
for (const [enumName, enumOptions] of Object.entries(toSchema.getNativeEnums())) {
|
|
66
|
+
if (created.includes(enumName)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
created.push(enumName);
|
|
70
|
+
const sql = this.helper.getCreateNativeEnumSQL(enumName, enumOptions, options.schema ?? this.config.get('schema'));
|
|
71
|
+
ret += await this.dump(this.knex.schema.raw(sql), '\n');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
for (const tableDef of toSchema.getTables()) {
|
|
64
75
|
ret += await this.dump(this.createTable(tableDef));
|
|
65
76
|
}
|
|
@@ -284,12 +295,22 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
284
295
|
const ret = [];
|
|
285
296
|
const [schemaName, tableName] = this.splitTableName(diff.name);
|
|
286
297
|
if (this.platform.supportsNativeEnums()) {
|
|
298
|
+
const createdNativeEnums = [];
|
|
287
299
|
const changedNativeEnums = [];
|
|
288
|
-
for (const { column, changedProperties } of Object.values(diff.changedColumns)) {
|
|
289
|
-
if (column.nativeEnumName
|
|
300
|
+
for (const { column, changedProperties, fromColumn } of Object.values(diff.changedColumns)) {
|
|
301
|
+
if (!column.nativeEnumName) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (changedProperties.has('enumItems') && column.nativeEnumName in diff.fromTable.nativeEnums) {
|
|
290
305
|
changedNativeEnums.push([column.nativeEnumName, column.enumItems, diff.fromTable.getColumn(column.name).enumItems]);
|
|
291
306
|
}
|
|
307
|
+
else if (changedProperties.has('type') && !(column.nativeEnumName in diff.fromTable.nativeEnums)) {
|
|
308
|
+
createdNativeEnums.push([column.nativeEnumName, column.enumItems]);
|
|
309
|
+
}
|
|
292
310
|
}
|
|
311
|
+
core_1.Utils.removeDuplicates(createdNativeEnums).forEach(([enumName, items]) => {
|
|
312
|
+
ret.push(this.knex.schema.raw(this.helper.getCreateNativeEnumSQL(enumName, items, schemaName)));
|
|
313
|
+
});
|
|
293
314
|
core_1.Utils.removeDuplicates(changedNativeEnums).forEach(([enumName, itemsNew, itemsOld]) => {
|
|
294
315
|
// postgres allows only adding new items, the values are case insensitive
|
|
295
316
|
itemsOld = itemsOld.map(v => v.toLowerCase());
|
|
@@ -331,7 +352,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
331
352
|
.onDelete(foreignKey.deleteRule);
|
|
332
353
|
}
|
|
333
354
|
}
|
|
334
|
-
for (const { column, changedProperties } of Object.values(diff.changedColumns)) {
|
|
355
|
+
for (const { column, changedProperties, fromColumn } of Object.values(diff.changedColumns)) {
|
|
335
356
|
if (changedProperties.size === 1 && changedProperties.has('comment')) {
|
|
336
357
|
continue;
|
|
337
358
|
}
|