@mikro-orm/sql 7.1.12-dev.10 → 7.1.12-dev.12

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.
@@ -75,8 +75,7 @@ export class SqlEntityManager extends EntityManager {
75
75
  */
76
76
  async countBy(entityName, groupBy, options = {}) {
77
77
  const em = this.getContext(false);
78
- options = { ...options };
79
- em.prepareOptions(options);
78
+ options = em.prepareOptions(options);
80
79
  const meta = em.getMetadata().find(entityName);
81
80
  const fields = Utils.asArray(groupBy);
82
81
  const { where: rawWhere, ...countOptions } = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.1.12-dev.10",
3
+ "version": "7.1.12-dev.12",
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.11"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.12-dev.10"
56
+ "@mikro-orm/core": "7.1.12-dev.12"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -152,11 +152,10 @@ type ContextFilterKeys<Context> = {
152
152
  type RawFilterKeys<RawAliases extends string> = {
153
153
  [K in RawAliases]?: AliasedFilterValue;
154
154
  };
155
- type NestedFilterCondition<Entity, RootAlias extends string, Context, RawAliases extends string> = ObjectQuery<Entity> & (IsNever<RootAlias> extends true ? {} : string extends RootAlias ? {} : RootAliasFilterKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextFilterKeys<Context>) & (IsNever<RawAliases> extends true ? {} : string extends RawAliases ? {} : RawFilterKeys<RawAliases>);
156
155
  type GroupOperators<RootAlias extends string, Context, Entity, RawAliases extends string> = {
157
- $and?: NestedFilterCondition<Entity, RootAlias, Context, RawAliases>[];
158
- $or?: NestedFilterCondition<Entity, RootAlias, Context, RawAliases>[];
159
- $not?: NestedFilterCondition<Entity, RootAlias, Context, RawAliases>;
156
+ $and?: QBFilterQuery<Entity, RootAlias, Context, RawAliases>[];
157
+ $or?: QBFilterQuery<Entity, RootAlias, Context, RawAliases>[];
158
+ $not?: QBFilterQuery<Entity, RootAlias, Context, RawAliases>;
160
159
  };
161
160
  export type AliasedFilterCondition<RootAlias extends string, Context, Entity, RawAliases extends string = never> = (IsNever<RootAlias> extends true ? {} : string extends RootAlias ? {} : RootAliasFilterKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextFilterKeys<Context>) & (IsNever<RawAliases> extends true ? {} : string extends RawAliases ? {} : RawFilterKeys<RawAliases>) & GroupOperators<RootAlias, Context, Entity, RawAliases>;
162
161
  export type QBFilterQuery<Entity, RootAlias extends string = never, Context = never, RawAliases extends string = never> = FilterObject<Entity> & AliasedFilterCondition<RootAlias, Context, Entity, RawAliases>;
@@ -308,22 +308,6 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
308
308
  for (const newTable of Object.values(schemaDiff.newTables)) {
309
309
  this.append(ret, this.helper.createTable(newTable, true), true);
310
310
  }
311
- if (this.helper.supportsSchemaConstraints()) {
312
- for (const newTable of Object.values(schemaDiff.newTables)) {
313
- const sql = [];
314
- if (this.options.createForeignKeyConstraints) {
315
- const fks = Object.values(newTable.getForeignKeys()).map(fk => this.helper.createForeignKey(newTable, fk));
316
- this.append(sql, fks);
317
- }
318
- for (const check of newTable.getChecks()) {
319
- this.append(sql, this.helper.createCheck(newTable, check));
320
- }
321
- for (const trigger of newTable.getTriggers()) {
322
- this.append(sql, this.helper.createTrigger(newTable, trigger));
323
- }
324
- this.append(ret, sql, true);
325
- }
326
- }
327
311
  if (options.dropTables && !options.safe) {
328
312
  for (const table of Object.values(schemaDiff.removedTables)) {
329
313
  // Drop triggers before the table so driver-specific cleanup runs (e.g. PostgreSQL function removal)
@@ -353,6 +337,23 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
353
337
  for (const changedTable of alteredTables) {
354
338
  this.append(ret, this.helper.getPostAlterTable(changedTable, options.safe), true);
355
339
  }
340
+ // after the alters, so a new table's FK can reference a unique constraint an existing table gains in the same diff
341
+ if (this.helper.supportsSchemaConstraints()) {
342
+ for (const newTable of Object.values(schemaDiff.newTables)) {
343
+ const sql = [];
344
+ if (this.options.createForeignKeyConstraints) {
345
+ const fks = Object.values(newTable.getForeignKeys()).map(fk => this.helper.createForeignKey(newTable, fk));
346
+ this.append(sql, fks);
347
+ }
348
+ for (const check of newTable.getChecks()) {
349
+ this.append(sql, this.helper.createCheck(newTable, check));
350
+ }
351
+ for (const trigger of newTable.getTriggers()) {
352
+ this.append(sql, this.helper.createTrigger(newTable, trigger));
353
+ }
354
+ this.append(ret, sql, true);
355
+ }
356
+ }
356
357
  if (!options.safe && this.platform.supportsNativeEnums()) {
357
358
  for (const removedNativeEnum of schemaDiff.removedNativeEnums) {
358
359
  this.append(ret, this.helper.getDropNativeEnumSQL(removedNativeEnum.name, removedNativeEnum.schema));