@mikro-orm/knex 6.0.0-dev.182 → 6.0.0-dev.184

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.0.0-dev.182",
3
+ "version": "6.0.0-dev.184",
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": "^5.9.2"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.0.0-dev.182"
69
+ "@mikro-orm/core": "6.0.0-dev.184"
70
70
  }
71
71
  }
@@ -164,7 +164,7 @@ class DatabaseTable {
164
164
  || skippedColumnNames.includes(index.columnNames[0]) // Non-composite indexes for skipped columns are to be mapped as entity decorators.
165
165
  )
166
166
  // ignore indexes that don't have all column names (this can happen in sqlite where there is no way to infer this for expressions)
167
- && !index.columnNames.some(col => col === null));
167
+ && !(index.columnNames.some(col => !col) && !index.expression));
168
168
  for (const index of potentiallyUnmappedIndexes) {
169
169
  const ret = { name: index.keyName };
170
170
  // Index is for FK. Map to the FK prop and move on.
@@ -365,6 +365,9 @@ class DatabaseTable {
365
365
  const propBaseNames = new Set();
366
366
  const columnNames = index.columnNames;
367
367
  const l = columnNames.length;
368
+ if (columnNames.some(col => !col)) {
369
+ return;
370
+ }
368
371
  for (let i = 0; i < l; ++i) {
369
372
  const columnName = columnNames[i];
370
373
  // The column is not involved with FKs.
@@ -459,8 +459,8 @@ class SchemaComparator {
459
459
  return defaultValueFrom === defaultValueTo;
460
460
  }
461
461
  if (to.mappedType instanceof core_1.JsonType) {
462
- const defaultValueFrom = (0, core_1.parseJsonSafe)(from.default.replace(/^'(.*)'$/, '$1'));
463
- const defaultValueTo = (0, core_1.parseJsonSafe)(to.default?.replace(/^'(.*)'$/, '$1'));
462
+ const defaultValueFrom = (0, core_1.parseJsonSafe)(from.default.replace(/^(_\w+\\)?'(.*?)\\?'$/, '$2'));
463
+ const defaultValueTo = (0, core_1.parseJsonSafe)(to.default?.replace(/^\(?'(.*?)'\)?$/, '$1'));
464
464
  return core_1.Utils.equals(defaultValueFrom, defaultValueTo);
465
465
  }
466
466
  if (to.mappedType instanceof core_1.DateTimeType && from.default && to.default) {
@@ -23,7 +23,7 @@ export declare abstract class SchemaHelper {
23
23
  loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
24
24
  getListTablesSQL(schemaName?: string): string;
25
25
  getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column, schemaName?: string): string;
26
- getCreateIndexSQL(tableName: string, index: IndexDef): string;
26
+ getCreateIndexSQL(tableName: string, index: IndexDef, partialExpression?: boolean): string;
27
27
  getDropIndexSQL(tableName: string, index: IndexDef): string;
28
28
  getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string;
29
29
  hasNonDefaultPrimaryKeyName(table: DatabaseTable): boolean;
@@ -77,14 +77,17 @@ class SchemaHelper {
77
77
  const tableReference = schemaReference + tableName;
78
78
  return `alter table ${tableReference} rename column ${oldColumnName} to ${columnName}`;
79
79
  }
80
- getCreateIndexSQL(tableName, index) {
81
- /* istanbul ignore if */
82
- if (index.expression) {
80
+ getCreateIndexSQL(tableName, index, partialExpression = false) {
81
+ if (index.expression && !partialExpression) {
83
82
  return index.expression;
84
83
  }
85
84
  tableName = this.platform.quoteIdentifier(tableName);
86
85
  const keyName = this.platform.quoteIdentifier(index.keyName);
87
- return `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName} (${index.columnNames.map(c => this.platform.quoteIdentifier(c)).join(', ')})`;
86
+ const sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName} `;
87
+ if (index.expression && partialExpression) {
88
+ return `${sql}(${index.expression})`;
89
+ }
90
+ return `${sql}(${index.columnNames.map(c => this.platform.quoteIdentifier(c)).join(', ')})`;
88
91
  }
89
92
  getDropIndexSQL(tableName, index) {
90
93
  return `drop index ${this.platform.quoteIdentifier(index.keyName)}`;