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

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.4",
3
+ "version": "7.1.11-dev.6",
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.4"
56
+ "@mikro-orm/core": "7.1.11-dev.6"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -219,6 +219,7 @@ export class DatabaseTable {
219
219
  skippedColumnNames.includes(index.columnNames[0]) || // Non-composite indexes for skipped columns are to be mapped as entity decorators.
220
220
  index.deferMode ||
221
221
  index.expression ||
222
+ index.where ||
222
223
  !(index.columnNames[0] in columnFks)) && // Trivial non-composite indexes for scalar props are to be mapped to the column.
223
224
  // ignore indexes that don't have all column names (this can happen in sqlite where there is no way to infer this for expressions)
224
225
  !(index.columnNames.some(col => !col) && !index.expression));
@@ -299,6 +300,19 @@ export class DatabaseTable {
299
300
  }
300
301
  schema.addIndex(ret);
301
302
  }
303
+ for (const check of this.getChecks()) {
304
+ // skip checks that were consumed by enum conversion — the enum property recreates an
305
+ // equivalent check under the conventional name during discovery (only on platforms that
306
+ // emulate enums via check constraints; mysql/mariadb enums are native and recreate nothing)
307
+ const enumItems = check.columnName ? this.getColumn(check.columnName)?.enumItems : undefined;
308
+ if (this.#platform.usesEnumCheckConstraints() &&
309
+ enumItems?.length &&
310
+ (check.expression === this.#platform.getEnumCheckConstraintExpression(check.columnName, enumItems) ||
311
+ check.name === this.#platform.getIndexName(this.name, [check.columnName], 'check'))) {
312
+ continue;
313
+ }
314
+ schema.meta.checks.push({ name: check.name, expression: check.expression });
315
+ }
302
316
  const addedStandaloneFkPropsBasedOnColumn = new Set();
303
317
  const nonSkippedColumns = this.getColumns().filter(column => !skippedColumnNames.includes(column.name));
304
318
  for (const column of nonSkippedColumns) {
@@ -507,7 +521,8 @@ export class DatabaseTable {
507
521
  findFkIndex(currentFk) {
508
522
  const fkColumnsLength = currentFk.columnNames.length;
509
523
  const possibleIndexes = this.#indexes.filter(index => {
510
- return (index.columnNames.length === fkColumnsLength &&
524
+ return (!index.where &&
525
+ index.columnNames.length === fkColumnsLength &&
511
526
  !currentFk.columnNames.some((columnName, i) => index.columnNames[i] !== columnName));
512
527
  });
513
528
  possibleIndexes.sort((a, b) => {
@@ -522,12 +537,20 @@ export class DatabaseTable {
522
537
  return possibleIndexes.at(0);
523
538
  }
524
539
  getIndexProperties(index, columnFks, fksOnColumnProps, fksOnStandaloneProps, namingStrategy) {
525
- const propBaseNames = new Set();
540
+ const propBaseNames = new Map();
526
541
  const columnNames = index.columnNames;
527
542
  const l = columnNames.length;
528
543
  if (columnNames.some(col => !col)) {
529
544
  return;
530
545
  }
546
+ const addPropBaseName = (baseName, position) => {
547
+ const positions = propBaseNames.get(baseName);
548
+ if (positions) {
549
+ positions.last = position;
550
+ return;
551
+ }
552
+ propBaseNames.set(baseName, { first: position, last: position });
553
+ };
531
554
  for (let i = 0; i < l; ++i) {
532
555
  const columnName = columnNames[i];
533
556
  // The column is not involved with FKs.
@@ -538,14 +561,14 @@ export class DatabaseTable {
538
561
  }
539
562
  // It has a prop named after it.
540
563
  // Add it and move on.
541
- propBaseNames.add(columnName);
564
+ addPropBaseName(columnName, i);
542
565
  continue;
543
566
  }
544
567
  // If the prop named after the column has a FK and the FK's columns are a subset of this index,
545
568
  // include this prop and move on.
546
569
  const columnPropFk = fksOnColumnProps.get(columnName);
547
570
  if (columnPropFk && !columnPropFk.columnNames.some(fkColumnName => !columnNames.includes(fkColumnName))) {
548
- propBaseNames.add(columnName);
571
+ addPropBaseName(columnName, i);
549
572
  continue;
550
573
  }
551
574
  // If there is at least one standalone FK featuring this column,
@@ -557,7 +580,7 @@ export class DatabaseTable {
557
580
  continue;
558
581
  }
559
582
  if (!fk.columnNames.some(fkColumnName => !columnNames.includes(fkColumnName))) {
560
- propBaseNames.add(propName);
583
+ addPropBaseName(propName, i);
561
584
  propAdded = true;
562
585
  }
563
586
  }
@@ -568,7 +591,10 @@ export class DatabaseTable {
568
591
  // Break the whole prop creation.
569
592
  return;
570
593
  }
571
- return Array.from(propBaseNames).map(baseName => this.getPropertyName(namingStrategy, baseName, fksOnColumnProps.get(baseName)));
594
+ // Props sharing their first column would otherwise follow FK discovery order, so break ties on the last one.
595
+ return Array.from(propBaseNames)
596
+ .sort(([, a], [, b]) => a.first - b.first || a.last - b.last)
597
+ .map(([baseName]) => this.getPropertyName(namingStrategy, baseName, fksOnColumnProps.get(baseName)));
572
598
  }
573
599
  getSafeBaseNameForFkProp(namingStrategy, currentFk, fks, columnName) {
574
600
  if (columnName &&
@@ -694,9 +720,9 @@ export class DatabaseTable {
694
720
  const prop = this.getPropertyName(namingStrategy, column.name, fk);
695
721
  const persist = !(column.name in columnFks && typeof fk === 'undefined');
696
722
  const index = compositeFkIndexes[prop] ||
697
- this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && !idx.unique && !idx.primary);
723
+ this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && !idx.unique && !idx.primary && !idx.where);
698
724
  const unique = compositeFkUniques[prop] ||
699
- this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary);
725
+ this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary && !idx.where);
700
726
  const kind = this.getReferenceKind(fk, unique);
701
727
  const runtimeType = this.getPropertyTypeForColumn(namingStrategy, column, fk);
702
728
  const type = fk
package/typings.d.ts CHANGED
@@ -368,9 +368,9 @@ type MaybeGenerated<TValue, TOptions, TProcessOnCreate extends boolean> = TOptio
368
368
  } ? TValue | null : TOptions extends {
369
369
  autoincrement: true;
370
370
  } ? Generated<TValue> : TOptions extends {
371
- default: true;
371
+ default: unknown;
372
372
  } ? Generated<TValue> : TOptions extends {
373
- defaultRaw: true;
373
+ defaultRaw: unknown;
374
374
  } ? Generated<TValue> : TProcessOnCreate extends false ? TValue : TOptions extends {
375
375
  onCreate: Function;
376
376
  } ? Generated<TValue> : TValue;