@mikro-orm/sql 7.1.11-dev.6 → 7.1.11-dev.8

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/sql",
3
- "version": "7.1.11-dev.6",
3
+ "version": "7.1.11-dev.8",
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",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.1.10"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.11-dev.6"
56
+ "@mikro-orm/core": "7.1.11-dev.8"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -49,6 +49,8 @@ export declare class DatabaseTable {
49
49
  getEntityDeclaration(namingStrategy: NamingStrategy, schemaHelper: SchemaHelper, scalarPropertiesForRelations: 'always' | 'never' | 'smart'): EntityMetadata;
50
50
  private foreignKeysToProps;
51
51
  private findFkIndex;
52
+ /** Advanced options require an entity-level declaration, as the property-level `index`/`unique` cannot carry them. */
53
+ private hasAdvancedIndexOptions;
52
54
  private getIndexProperties;
53
55
  private getSafeBaseNameForFkProp;
54
56
  /**
@@ -220,6 +220,7 @@ export class DatabaseTable {
220
220
  index.deferMode ||
221
221
  index.expression ||
222
222
  index.where ||
223
+ this.hasAdvancedIndexOptions(index) ||
223
224
  !(index.columnNames[0] in columnFks)) && // Trivial non-composite indexes for scalar props are to be mapped to the column.
224
225
  // ignore indexes that don't have all column names (this can happen in sqlite where there is no way to infer this for expressions)
225
226
  !(index.columnNames.some(col => !col) && !index.expression));
@@ -255,14 +256,7 @@ export class DatabaseTable {
255
256
  }
256
257
  }
257
258
  // An index is trivial if it has no special options that require entity-level declaration
258
- const hasAdvancedOptions = index.columns?.length ||
259
- index.include?.length ||
260
- index.fillFactor ||
261
- index.type ||
262
- index.invisible ||
263
- index.disabled ||
264
- index.clustered;
265
- const isTrivial = !index.deferMode && !index.expression && !index.where && !hasAdvancedOptions;
259
+ const isTrivial = !index.deferMode && !index.expression && !index.where && !this.hasAdvancedIndexOptions(index);
266
260
  if (isTrivial) {
267
261
  // Index is for FK. Map to the FK prop and move on.
268
262
  const fkForIndex = fkIndexes.get(index);
@@ -522,6 +516,7 @@ export class DatabaseTable {
522
516
  const fkColumnsLength = currentFk.columnNames.length;
523
517
  const possibleIndexes = this.#indexes.filter(index => {
524
518
  return (!index.where &&
519
+ !this.hasAdvancedIndexOptions(index) &&
525
520
  index.columnNames.length === fkColumnsLength &&
526
521
  !currentFk.columnNames.some((columnName, i) => index.columnNames[i] !== columnName));
527
522
  });
@@ -536,6 +531,16 @@ export class DatabaseTable {
536
531
  });
537
532
  return possibleIndexes.at(0);
538
533
  }
534
+ /** Advanced options require an entity-level declaration, as the property-level `index`/`unique` cannot carry them. */
535
+ hasAdvancedIndexOptions(index) {
536
+ return !!(index.columns?.length ||
537
+ index.include?.length ||
538
+ index.fillFactor ||
539
+ index.type ||
540
+ index.invisible ||
541
+ index.disabled ||
542
+ index.clustered);
543
+ }
539
544
  getIndexProperties(index, columnFks, fksOnColumnProps, fksOnStandaloneProps, namingStrategy) {
540
545
  const propBaseNames = new Map();
541
546
  const columnNames = index.columnNames;
@@ -720,9 +725,19 @@ export class DatabaseTable {
720
725
  const prop = this.getPropertyName(namingStrategy, column.name, fk);
721
726
  const persist = !(column.name in columnFks && typeof fk === 'undefined');
722
727
  const index = compositeFkIndexes[prop] ||
723
- this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && !idx.unique && !idx.primary && !idx.where);
728
+ this.#indexes.find(idx => idx.columnNames[0] === column.name &&
729
+ !idx.composite &&
730
+ !idx.unique &&
731
+ !idx.primary &&
732
+ !idx.where &&
733
+ !this.hasAdvancedIndexOptions(idx));
724
734
  const unique = compositeFkUniques[prop] ||
725
- this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary && !idx.where);
735
+ this.#indexes.find(idx => idx.columnNames[0] === column.name &&
736
+ !idx.composite &&
737
+ idx.unique &&
738
+ !idx.primary &&
739
+ !idx.where &&
740
+ !this.hasAdvancedIndexOptions(idx));
726
741
  const kind = this.getReferenceKind(fk, unique);
727
742
  const runtimeType = this.getPropertyTypeForColumn(namingStrategy, column, fk);
728
743
  const type = fk