@mikro-orm/knex 6.1.9-dev.9 → 6.1.10-dev.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.10-dev.0",
|
|
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,9 +63,9 @@
|
|
|
63
63
|
"sqlstring": "2.3.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@mikro-orm/core": "^6.1.
|
|
66
|
+
"@mikro-orm/core": "^6.1.9"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.1.
|
|
69
|
+
"@mikro-orm/core": "6.1.10-dev.0"
|
|
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,18 @@ 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
|
+
/* istanbul ignore if */
|
|
67
|
+
if (created.includes(enumName)) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
created.push(enumName);
|
|
71
|
+
const sql = this.helper.getCreateNativeEnumSQL(enumName, enumOptions, options.schema ?? this.config.get('schema'));
|
|
72
|
+
ret += await this.dump(this.knex.schema.raw(sql), '\n');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
63
75
|
for (const tableDef of toSchema.getTables()) {
|
|
64
76
|
ret += await this.dump(this.createTable(tableDef));
|
|
65
77
|
}
|
|
@@ -284,12 +296,22 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
284
296
|
const ret = [];
|
|
285
297
|
const [schemaName, tableName] = this.splitTableName(diff.name);
|
|
286
298
|
if (this.platform.supportsNativeEnums()) {
|
|
299
|
+
const createdNativeEnums = [];
|
|
287
300
|
const changedNativeEnums = [];
|
|
288
|
-
for (const { column, changedProperties } of Object.values(diff.changedColumns)) {
|
|
289
|
-
if (column.nativeEnumName
|
|
301
|
+
for (const { column, changedProperties, fromColumn } of Object.values(diff.changedColumns)) {
|
|
302
|
+
if (!column.nativeEnumName) {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (changedProperties.has('enumItems') && column.nativeEnumName in diff.fromTable.nativeEnums) {
|
|
290
306
|
changedNativeEnums.push([column.nativeEnumName, column.enumItems, diff.fromTable.getColumn(column.name).enumItems]);
|
|
291
307
|
}
|
|
308
|
+
else if (changedProperties.has('type') && !(column.nativeEnumName in diff.fromTable.nativeEnums)) {
|
|
309
|
+
createdNativeEnums.push([column.nativeEnumName, column.enumItems]);
|
|
310
|
+
}
|
|
292
311
|
}
|
|
312
|
+
core_1.Utils.removeDuplicates(createdNativeEnums).forEach(([enumName, items]) => {
|
|
313
|
+
ret.push(this.knex.schema.raw(this.helper.getCreateNativeEnumSQL(enumName, items, schemaName)));
|
|
314
|
+
});
|
|
293
315
|
core_1.Utils.removeDuplicates(changedNativeEnums).forEach(([enumName, itemsNew, itemsOld]) => {
|
|
294
316
|
// postgres allows only adding new items, the values are case insensitive
|
|
295
317
|
itemsOld = itemsOld.map(v => v.toLowerCase());
|
|
@@ -331,7 +353,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
331
353
|
.onDelete(foreignKey.deleteRule);
|
|
332
354
|
}
|
|
333
355
|
}
|
|
334
|
-
for (const { column, changedProperties } of Object.values(diff.changedColumns)) {
|
|
356
|
+
for (const { column, changedProperties, fromColumn } of Object.values(diff.changedColumns)) {
|
|
335
357
|
if (changedProperties.size === 1 && changedProperties.has('comment')) {
|
|
336
358
|
continue;
|
|
337
359
|
}
|