@mikro-orm/knex 6.2.2-dev.8 → 6.2.2

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.
@@ -122,7 +122,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
122
122
  if (res instanceof query_1.QueryBuilder) {
123
123
  return this.wrapVirtualExpressionInSubquery(meta, res.getFormattedQuery(), where, options, type);
124
124
  }
125
- if (core_1.Utils.isObject(res)) {
125
+ if (!(res instanceof Promise) && core_1.Utils.isObject(res)) {
126
126
  const { sql, bindings } = res.toSQL();
127
127
  const query = this.platform.formatQuery(sql, bindings);
128
128
  return this.wrapVirtualExpressionInSubquery(meta, query, where, options, type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.2.2-dev.8",
3
+ "version": "6.2.2",
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.2.1"
66
+ "@mikro-orm/core": "^6.2.2"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.2.2-dev.8"
69
+ "@mikro-orm/core": "^6.0.0"
70
70
  }
71
71
  }
@@ -38,7 +38,11 @@ class DatabaseSchema {
38
38
  }
39
39
  setNativeEnums(nativeEnums) {
40
40
  this.nativeEnums = nativeEnums;
41
- this.tables.forEach(t => t.nativeEnums = nativeEnums);
41
+ for (const nativeEnum of Object.values(nativeEnums)) {
42
+ if (nativeEnum.schema && nativeEnum.schema !== '*') {
43
+ this.namespaces.add(nativeEnum.schema);
44
+ }
45
+ }
42
46
  }
43
47
  getNativeEnums() {
44
48
  return this.nativeEnums;
@@ -72,13 +76,20 @@ class DatabaseSchema {
72
76
  for (const prop of meta.props) {
73
77
  if (prop.nativeEnumName) {
74
78
  let key = prop.nativeEnumName;
75
- const s = meta.schema ?? schema.name;
76
- if (s && s !== platform.getDefaultSchemaName()) {
77
- key = s + '.' + key;
79
+ let enumName = prop.nativeEnumName;
80
+ let enumSchema = meta.schema ?? schema.name;
81
+ if (key.includes('.')) {
82
+ const [explicitSchema, ...parts] = prop.nativeEnumName.split('.');
83
+ enumName = parts.join('.');
84
+ key = enumName;
85
+ enumSchema = explicitSchema;
86
+ }
87
+ if (enumSchema && enumSchema !== '*' && enumSchema !== platform.getDefaultSchemaName()) {
88
+ key = enumSchema + '.' + key;
78
89
  }
79
90
  nativeEnums[key] = {
80
- name: prop.nativeEnumName,
81
- schema: meta.schema ?? schema.name,
91
+ name: enumName,
92
+ schema: enumSchema,
82
93
  items: prop.items?.map(val => '' + val) ?? [],
83
94
  };
84
95
  }
@@ -135,7 +146,11 @@ class DatabaseSchema {
135
146
  || (!schema && !wildcardSchemaTables.includes(table.name)); // no schema specified and the table has fixed one provided
136
147
  });
137
148
  // remove namespaces of ignored tables
138
- this.namespaces.forEach(ns => !this.tables.find(t => t.schema === ns) && this.namespaces.delete(ns));
149
+ for (const ns of this.namespaces) {
150
+ if (!this.tables.some(t => t.schema === ns) && !Object.values(this.nativeEnums).some(e => e.schema === ns)) {
151
+ this.namespaces.delete(ns);
152
+ }
153
+ }
139
154
  }
140
155
  }
141
156
  exports.DatabaseSchema = DatabaseSchema;
@@ -39,7 +39,7 @@ export declare class SchemaComparator {
39
39
  * Returns the difference between the columns
40
40
  * If there are differences this method returns field2, otherwise the boolean false.
41
41
  */
42
- diffColumn(fromColumn: Column, toColumn: Column, tableName?: string): Set<string>;
42
+ diffColumn(fromColumn: Column, toColumn: Column, fromTable: DatabaseTable, tableName?: string): Set<string>;
43
43
  diffEnumItems(items1?: string[], items2?: string[]): boolean;
44
44
  diffComment(comment1?: string, comment2?: string): boolean;
45
45
  /**
@@ -47,17 +47,23 @@ class SchemaComparator {
47
47
  }
48
48
  diff.removedNamespaces.add(namespace);
49
49
  }
50
- for (const nativeEnum of Object.keys(toSchema.getNativeEnums())) {
51
- if (fromSchema.hasNativeEnum(nativeEnum)) {
50
+ for (const [key, nativeEnum] of Object.entries(toSchema.getNativeEnums())) {
51
+ if (fromSchema.hasNativeEnum(key)) {
52
52
  continue;
53
53
  }
54
- diff.newNativeEnums.push(toSchema.getNativeEnum(nativeEnum));
54
+ if (nativeEnum.schema === '*' && fromSchema.hasNativeEnum(`${toSchema.name}.${key}`)) {
55
+ continue;
56
+ }
57
+ diff.newNativeEnums.push(nativeEnum);
55
58
  }
56
- for (const nativeEnum of Object.keys(fromSchema.getNativeEnums())) {
57
- if (toSchema.hasNativeEnum(nativeEnum)) {
59
+ for (const [key, nativeEnum] of Object.entries(fromSchema.getNativeEnums())) {
60
+ if (toSchema.hasNativeEnum(key)) {
61
+ continue;
62
+ }
63
+ if (key.startsWith(`${fromSchema.name}.`) && (fromSchema.name !== toSchema.name || toSchema.getNativeEnum(key.substring(fromSchema.name.length + 1))?.schema === '*')) {
58
64
  continue;
59
65
  }
60
- diff.removedNativeEnums.push(fromSchema.getNativeEnum(nativeEnum));
66
+ diff.removedNativeEnums.push(nativeEnum);
61
67
  }
62
68
  for (const table of toSchema.getTables()) {
63
69
  const tableName = table.getShortestName();
@@ -160,7 +166,7 @@ class SchemaComparator {
160
166
  continue;
161
167
  }
162
168
  // See if column has changed properties in "to" table.
163
- const changedProperties = this.diffColumn(column, toTable.getColumn(column.name), tableName);
169
+ const changedProperties = this.diffColumn(column, toTable.getColumn(column.name), fromTable, tableName);
164
170
  if (changedProperties.size === 0) {
165
171
  continue;
166
172
  }
@@ -277,7 +283,7 @@ class SchemaComparator {
277
283
  const newFKs = Object.values(tableDifferences.toTable.getForeignKeys());
278
284
  for (const addedColumn of Object.values(tableDifferences.addedColumns)) {
279
285
  for (const removedColumn of Object.values(tableDifferences.removedColumns)) {
280
- const diff = this.diffColumn(addedColumn, removedColumn);
286
+ const diff = this.diffColumn(addedColumn, removedColumn, tableDifferences.fromTable);
281
287
  if (diff.size !== 0) {
282
288
  continue;
283
289
  }
@@ -372,11 +378,12 @@ class SchemaComparator {
372
378
  * Returns the difference between the columns
373
379
  * If there are differences this method returns field2, otherwise the boolean false.
374
380
  */
375
- diffColumn(fromColumn, toColumn, tableName) {
381
+ diffColumn(fromColumn, toColumn, fromTable, tableName) {
376
382
  const changedProperties = new Set();
377
383
  const fromProp = this.mapColumnToProperty({ ...fromColumn, autoincrement: false });
378
384
  const toProp = this.mapColumnToProperty({ ...toColumn, autoincrement: false });
379
385
  const fromColumnType = fromColumn.mappedType.getColumnType(fromProp, this.platform).toLowerCase();
386
+ const fromNativeEnum = fromTable.nativeEnums[fromColumnType] ?? Object.values(fromTable.nativeEnums).find(e => e.name === fromColumnType && e.schema !== '*');
380
387
  const toColumnType = toColumn.mappedType.getColumnType(toProp, this.platform).toLowerCase();
381
388
  const log = (msg, params) => {
382
389
  if (tableName) {
@@ -386,6 +393,7 @@ class SchemaComparator {
386
393
  }
387
394
  };
388
395
  if (fromColumnType !== toColumnType &&
396
+ (!fromNativeEnum || `${fromNativeEnum.schema}.${fromNativeEnum.name}` !== toColumnType) &&
389
397
  !(fromColumn.ignoreSchemaChanges?.includes('type') || toColumn.ignoreSchemaChanges?.includes('type')) &&
390
398
  !fromColumn.generated && !toColumn.generated) {
391
399
  log(`'type' changed for column ${tableName}.${fromColumn.name}`, { fromColumnType, toColumnType });
@@ -69,7 +69,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
69
69
  continue;
70
70
  }
71
71
  created.push(enumName);
72
- const sql = this.helper.getCreateNativeEnumSQL(enumName, enumOptions.items, options.schema ?? this.config.get('schema'));
72
+ const sql = this.helper.getCreateNativeEnumSQL(enumOptions.name, enumOptions.items, this.getSchemaName(enumOptions, options));
73
73
  ret += await this.dump(this.knex.schema.raw(sql), '\n');
74
74
  }
75
75
  }
@@ -196,7 +196,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
196
196
  }
197
197
  if (this.platform.supportsNativeEnums()) {
198
198
  for (const newNativeEnum of schemaDiff.newNativeEnums) {
199
- const sql = this.helper.getCreateNativeEnumSQL(newNativeEnum.name, newNativeEnum.items, newNativeEnum.schema ?? options.schema ?? this.config.get('schema'));
199
+ const sql = this.helper.getCreateNativeEnumSQL(newNativeEnum.name, newNativeEnum.items, this.getSchemaName(newNativeEnum, options));
200
200
  ret += await this.dump(this.knex.schema.raw(sql), '\n');
201
201
  }
202
202
  }