@mikro-orm/knex 6.0.0-dev.32 → 6.0.0-dev.320

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.
Files changed (44) hide show
  1. package/AbstractSqlConnection.d.ts +22 -4
  2. package/AbstractSqlConnection.js +45 -20
  3. package/AbstractSqlDriver.d.ts +30 -24
  4. package/AbstractSqlDriver.js +606 -268
  5. package/AbstractSqlPlatform.d.ts +9 -5
  6. package/AbstractSqlPlatform.js +25 -29
  7. package/MonkeyPatchable.d.ts +1 -0
  8. package/MonkeyPatchable.js +3 -0
  9. package/PivotCollectionPersister.d.ts +17 -0
  10. package/PivotCollectionPersister.js +128 -0
  11. package/README.md +64 -107
  12. package/SqlEntityManager.d.ts +4 -8
  13. package/SqlEntityManager.js +8 -12
  14. package/SqlEntityRepository.d.ts +7 -5
  15. package/SqlEntityRepository.js +11 -7
  16. package/index.mjs +24 -3
  17. package/package.json +8 -8
  18. package/query/ArrayCriteriaNode.d.ts +3 -2
  19. package/query/ArrayCriteriaNode.js +7 -2
  20. package/query/CriteriaNode.d.ts +6 -4
  21. package/query/CriteriaNode.js +22 -9
  22. package/query/CriteriaNodeFactory.d.ts +1 -1
  23. package/query/CriteriaNodeFactory.js +27 -11
  24. package/query/ObjectCriteriaNode.d.ts +3 -2
  25. package/query/ObjectCriteriaNode.js +72 -28
  26. package/query/QueryBuilder.d.ts +69 -36
  27. package/query/QueryBuilder.js +469 -146
  28. package/query/QueryBuilderHelper.d.ts +13 -18
  29. package/query/QueryBuilderHelper.js +199 -171
  30. package/query/ScalarCriteriaNode.d.ts +3 -2
  31. package/query/ScalarCriteriaNode.js +14 -4
  32. package/query/enums.d.ts +7 -0
  33. package/query/enums.js +10 -2
  34. package/schema/DatabaseSchema.d.ts +5 -2
  35. package/schema/DatabaseSchema.js +26 -8
  36. package/schema/DatabaseTable.d.ts +12 -4
  37. package/schema/DatabaseTable.js +370 -42
  38. package/schema/SchemaComparator.d.ts +7 -5
  39. package/schema/SchemaComparator.js +69 -35
  40. package/schema/SchemaHelper.d.ts +7 -5
  41. package/schema/SchemaHelper.js +30 -11
  42. package/schema/SqlSchemaGenerator.d.ts +11 -48
  43. package/schema/SqlSchemaGenerator.js +84 -30
  44. package/typings.d.ts +27 -8
@@ -7,6 +7,9 @@ const core_1 = require("@mikro-orm/core");
7
7
  * Compares two Schemas and return an instance of SchemaDifference.
8
8
  */
9
9
  class SchemaComparator {
10
+ platform;
11
+ helper;
12
+ logger;
10
13
  constructor(platform) {
11
14
  this.platform = platform;
12
15
  this.helper = this.platform.getSchemaHelper();
@@ -19,7 +22,7 @@ class SchemaComparator {
19
22
  * operations to change the schema stored in fromSchema to the schema that is
20
23
  * stored in toSchema.
21
24
  */
22
- compare(fromSchema, toSchema) {
25
+ compare(fromSchema, toSchema, inverseDiff) {
23
26
  const diff = { newTables: {}, removedTables: {}, changedTables: {}, orphanedForeignKeys: [], newNamespaces: new Set(), removedNamespaces: new Set(), fromSchema };
24
27
  const foreignKeysToTable = {};
25
28
  for (const namespace of toSchema.getNamespaces()) {
@@ -40,7 +43,7 @@ class SchemaComparator {
40
43
  diff.newTables[tableName] = toSchema.getTable(tableName);
41
44
  }
42
45
  else {
43
- const tableDifferences = this.diffTable(fromSchema.getTable(tableName), toSchema.getTable(tableName));
46
+ const tableDifferences = this.diffTable(fromSchema.getTable(tableName), toSchema.getTable(tableName), inverseDiff?.changedTables[tableName]);
44
47
  if (tableDifferences !== false) {
45
48
  diff.changedTables[tableName] = tableDifferences;
46
49
  }
@@ -88,7 +91,7 @@ class SchemaComparator {
88
91
  * Returns the difference between the tables fromTable and toTable.
89
92
  * If there are no differences this method returns the boolean false.
90
93
  */
91
- diffTable(fromTable, toTable) {
94
+ diffTable(fromTable, toTable, inverseTableDiff) {
92
95
  let changes = 0;
93
96
  const tableDifferences = {
94
97
  name: fromTable.getShortestName(),
@@ -139,6 +142,12 @@ class SchemaComparator {
139
142
  if (changedProperties.size === 0) {
140
143
  continue;
141
144
  }
145
+ if (changedProperties.size === 1 && changedProperties.has('generated')) {
146
+ tableDifferences.addedColumns[column.name] = toTable.getColumn(column.name);
147
+ tableDifferences.removedColumns[column.name] = column;
148
+ changes++;
149
+ continue;
150
+ }
142
151
  tableDifferences.changedColumns[column.name] = {
143
152
  oldColumnName: column.name,
144
153
  fromColumn: column,
@@ -148,7 +157,7 @@ class SchemaComparator {
148
157
  this.log(`column ${tableDifferences.name}.${column.name} changed`, { changedProperties });
149
158
  changes++;
150
159
  }
151
- this.detectColumnRenamings(tableDifferences);
160
+ this.detectColumnRenamings(tableDifferences, inverseTableDiff);
152
161
  const fromTableIndexes = fromTable.getIndexes();
153
162
  const toTableIndexes = toTable.getIndexes();
154
163
  // See if all the indexes in "from" table exist in "to" table
@@ -200,7 +209,7 @@ class SchemaComparator {
200
209
  }
201
210
  // See if index has changed in "to" table
202
211
  const toTableCheck = toTable.getCheck(check.name);
203
- if (!this.diffCheck(check, toTableCheck)) {
212
+ if (!this.diffExpression(check.expression, toTableCheck.expression)) {
204
213
  continue;
205
214
  }
206
215
  this.log(`check constraint ${check.name} changed in table ${tableDifferences.name}`, { fromTableCheck: check, toTableCheck });
@@ -240,7 +249,7 @@ class SchemaComparator {
240
249
  * Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
241
250
  * however ambiguities between different possibilities should not lead to renaming at all.
242
251
  */
243
- detectColumnRenamings(tableDifferences) {
252
+ detectColumnRenamings(tableDifferences, inverseTableDiff) {
244
253
  const renameCandidates = {};
245
254
  for (const addedColumn of Object.values(tableDifferences.addedColumns)) {
246
255
  for (const removedColumn of Object.values(tableDifferences.removedColumns)) {
@@ -248,6 +257,10 @@ class SchemaComparator {
248
257
  if (diff.size !== 0) {
249
258
  continue;
250
259
  }
260
+ const renamedColumn = inverseTableDiff?.renamedColumns[addedColumn.name];
261
+ if (renamedColumn && renamedColumn?.name !== removedColumn.name) {
262
+ continue;
263
+ }
251
264
  renameCandidates[addedColumn.name] = renameCandidates[addedColumn.name] ?? [];
252
265
  renameCandidates[addedColumn.name].push([removedColumn, addedColumn]);
253
266
  }
@@ -324,12 +337,12 @@ class SchemaComparator {
324
337
  * Returns the difference between the columns
325
338
  * If there are differences this method returns field2, otherwise the boolean false.
326
339
  */
327
- diffColumn(column1, column2, tableName) {
340
+ diffColumn(fromColumn, toColumn, tableName) {
328
341
  const changedProperties = new Set();
329
- const prop1 = this.mapColumnToProperty({ ...column1, autoincrement: false });
330
- const prop2 = this.mapColumnToProperty({ ...column2, autoincrement: false });
331
- const columnType1 = column1.mappedType.getColumnType(prop1, this.platform).toLowerCase();
332
- const columnType2 = column2.mappedType.getColumnType(prop2, this.platform).toLowerCase();
342
+ const fromProp = this.mapColumnToProperty({ ...fromColumn, autoincrement: false });
343
+ const toProp = this.mapColumnToProperty({ ...toColumn, autoincrement: false });
344
+ const fromColumnType = fromColumn.mappedType.getColumnType(fromProp, this.platform).toLowerCase();
345
+ const toColumnType = toColumn.mappedType.getColumnType(toProp, this.platform).toLowerCase();
333
346
  const log = (msg, params) => {
334
347
  if (tableName) {
335
348
  const copy = core_1.Utils.copy(params);
@@ -337,40 +350,46 @@ class SchemaComparator {
337
350
  this.log(msg, copy);
338
351
  }
339
352
  };
340
- if (columnType1 !== columnType2 &&
341
- !(column1.ignoreSchemaChanges?.includes('type') ||
342
- column2.ignoreSchemaChanges?.includes('type'))) {
343
- log(`'type' changed for column ${tableName}.${column1.name}`, { columnType1, columnType2 });
353
+ if (fromColumnType !== toColumnType &&
354
+ !(fromColumn.ignoreSchemaChanges?.includes('type') ||
355
+ toColumn.ignoreSchemaChanges?.includes('type'))) {
356
+ log(`'type' changed for column ${tableName}.${fromColumn.name}`, { fromColumnType, toColumnType });
344
357
  changedProperties.add('type');
345
358
  }
346
- if (column1.nullable !== column2.nullable) {
347
- log(`'nullable' changed for column ${tableName}.${column1.name}`, { column1, column2 });
359
+ if (fromColumn.nullable !== toColumn.nullable && !fromColumn.generated && !toColumn.generated) {
360
+ log(`'nullable' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
348
361
  changedProperties.add('nullable');
349
362
  }
350
- if (!!column1.autoincrement !== !!column2.autoincrement) {
351
- log(`'autoincrement' changed for column ${tableName}.${column1.name}`, { column1, column2 });
363
+ if (this.diffExpression(fromColumn.generated, toColumn.generated)) {
364
+ log(`'generated' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
365
+ changedProperties.add('generated');
366
+ }
367
+ if (!!fromColumn.autoincrement !== !!toColumn.autoincrement) {
368
+ log(`'autoincrement' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
352
369
  changedProperties.add('autoincrement');
353
370
  }
354
- if (column1.unsigned !== column2.unsigned && this.platform.supportsUnsigned()) {
355
- log(`'unsigned' changed for column ${tableName}.${column1.name}`, { column1, column2 });
371
+ if (fromColumn.unsigned !== toColumn.unsigned && this.platform.supportsUnsigned()) {
372
+ log(`'unsigned' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
356
373
  changedProperties.add('unsigned');
357
374
  }
358
- if (!this.hasSameDefaultValue(column1, column2)) {
359
- log(`'default' changed for column ${tableName}.${column1.name}`, { column1, column2 });
375
+ if (!this.hasSameDefaultValue(fromColumn, toColumn)) {
376
+ log(`'default' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
360
377
  changedProperties.add('default');
361
378
  }
362
- if (this.diffComment(column1.comment, column2.comment)) {
363
- log(`'comment' changed for column ${tableName}.${column1.name}`, { column1, column2 });
379
+ if (this.diffComment(fromColumn.comment, toColumn.comment)) {
380
+ log(`'comment' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
364
381
  changedProperties.add('comment');
365
382
  }
366
- if (this.diffEnumItems(column1.enumItems, column2.enumItems)) {
367
- log(`'enumItems' changed for column ${tableName}.${column1.name}`, { column1, column2 });
383
+ if (!(fromColumn.mappedType instanceof core_1.ArrayType) &&
384
+ !(toColumn.mappedType instanceof core_1.ArrayType) &&
385
+ this.diffEnumItems(fromColumn.enumItems, toColumn.enumItems)) {
386
+ log(`'enumItems' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
368
387
  changedProperties.add('enumItems');
369
388
  }
370
- if ((column1.extra || '').toLowerCase() !== (column2.extra || '').toLowerCase() &&
371
- !(column1.ignoreSchemaChanges?.includes('extra') ||
372
- column2.ignoreSchemaChanges?.includes('extra'))) {
373
- log(`'extra' changed for column ${tableName}.${column1.name}`, { column1, column2 });
389
+ if ((fromColumn.extra || '').toLowerCase() !== (toColumn.extra || '').toLowerCase() &&
390
+ !(fromColumn.ignoreSchemaChanges?.includes('extra') ||
391
+ toColumn.ignoreSchemaChanges?.includes('extra'))) {
392
+ log(`'extra' changed for column ${tableName}.${fromColumn.name}`, { fromColumn, toColumn });
374
393
  changedProperties.add('extra');
375
394
  }
376
395
  return changedProperties;
@@ -424,11 +443,21 @@ class SchemaComparator {
424
443
  }
425
444
  return index1.primary === index2.primary && index1.unique === index2.unique;
426
445
  }
427
- diffCheck(check1, check2) {
428
- // check constraint definition might be normalized by the driver,
446
+ diffExpression(expr1, expr2) {
447
+ // expressions like check constraints might be normalized by the driver,
429
448
  // e.g. quotes might be added (https://github.com/mikro-orm/mikro-orm/issues/3827)
430
- const simplify = (str) => str?.replace(/['"`()]/g, '').toLowerCase();
431
- return simplify(check1.expression) !== simplify(check2.expression);
449
+ const simplify = (str) => str?.replace(/_\w+\\'(.*?)\\'/g, '$1').replace(/['"`()]|::\w+| +/g, '').toLowerCase();
450
+ return simplify(expr1) !== simplify(expr2);
451
+ }
452
+ parseJsonDefault(defaultValue) {
453
+ /* istanbul ignore next */
454
+ if (!defaultValue) {
455
+ return null;
456
+ }
457
+ const val = defaultValue
458
+ .replace(/^(_\w+\\)?'(.*?)\\?'$/, '$2')
459
+ .replace(/^\(?'(.*?)'\)?$/, '$1');
460
+ return (0, core_1.parseJsonSafe)(val);
432
461
  }
433
462
  hasSameDefaultValue(from, to) {
434
463
  if (from.default == null || from.default.toString().toLowerCase() === 'null' || from.default.toString().startsWith('nextval(')) {
@@ -439,6 +468,11 @@ class SchemaComparator {
439
468
  const defaultValueTo = !['0', 'false', 'f', 'n', 'no', 'off'].includes('' + to.default);
440
469
  return defaultValueFrom === defaultValueTo;
441
470
  }
471
+ if (to.mappedType instanceof core_1.JsonType) {
472
+ const defaultValueFrom = this.parseJsonDefault(from.default);
473
+ const defaultValueTo = this.parseJsonDefault(to.default);
474
+ return core_1.Utils.equals(defaultValueFrom, defaultValueTo);
475
+ }
442
476
  if (to.mappedType instanceof core_1.DateTimeType && from.default && to.default) {
443
477
  // normalize now/current_timestamp defaults, also remove `()` from the end of default expression
444
478
  const defaultValueFrom = from.default.toLowerCase().replace('current_timestamp', 'now').replace(/\(\)$/, '');
@@ -1,5 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { Connection, Dictionary } from '@mikro-orm/core';
2
+ import { type Connection, type Dictionary } from '@mikro-orm/core';
3
3
  import type { AbstractSqlConnection } from '../AbstractSqlConnection';
4
4
  import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
5
5
  import type { CheckDef, Column, IndexDef, Table, TableDifference } from '../typings';
@@ -18,10 +18,12 @@ export declare abstract class SchemaHelper {
18
18
  getForeignKeys(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<Dictionary>;
19
19
  protected getTableKey(t: Table): string;
20
20
  getEnumDefinitions(connection: AbstractSqlConnection, checks: CheckDef[], tableName: string, schemaName?: string): Promise<Dictionary<string[]>>;
21
- loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
21
+ getDropNativeEnumSQL(name: string, schema?: string): string;
22
+ getAlterNativeEnumSQL(name: string, schema?: string, value?: string): string;
23
+ loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
22
24
  getListTablesSQL(schemaName?: string): string;
23
25
  getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column, schemaName?: string): string;
24
- getCreateIndexSQL(tableName: string, index: IndexDef): string;
26
+ getCreateIndexSQL(tableName: string, index: IndexDef, partialExpression?: boolean): string;
25
27
  getDropIndexSQL(tableName: string, index: IndexDef): string;
26
28
  getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string;
27
29
  hasNonDefaultPrimaryKeyName(table: DatabaseTable): boolean;
@@ -29,8 +31,8 @@ export declare abstract class SchemaHelper {
29
31
  configureColumn(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
30
32
  configureColumnDefault(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
31
33
  getPreAlterTable(tableDiff: TableDifference, safe: boolean): string;
32
- getAlterColumnAutoincrement(tableName: string, column: Column): string;
33
- getChangeColumnCommentSQL(tableName: string, to: Column): string;
34
+ getAlterColumnAutoincrement(tableName: string, column: Column, schemaName?: string): string;
35
+ getChangeColumnCommentSQL(tableName: string, to: Column, schemaName?: string): string;
34
36
  getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
35
37
  getColumns(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<Column[]>;
36
38
  getIndexes(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<IndexDef[]>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SchemaHelper = void 0;
4
4
  const core_1 = require("@mikro-orm/core");
5
5
  class SchemaHelper {
6
+ platform;
6
7
  constructor(platform) {
7
8
  this.platform = platform;
8
9
  }
@@ -46,7 +47,13 @@ class SchemaHelper {
46
47
  async getEnumDefinitions(connection, checks, tableName, schemaName) {
47
48
  return {};
48
49
  }
49
- async loadInformationSchema(schema, connection, tables) {
50
+ getDropNativeEnumSQL(name, schema) {
51
+ throw new Error('Not supported by given driver');
52
+ }
53
+ getAlterNativeEnumSQL(name, schema, value) {
54
+ throw new Error('Not supported by given driver');
55
+ }
56
+ async loadInformationSchema(schema, connection, tables, schemas) {
50
57
  for (const t of tables) {
51
58
  const table = schema.addTable(t.table_name, t.schema_name);
52
59
  table.comment = t.table_comment;
@@ -70,14 +77,18 @@ class SchemaHelper {
70
77
  const tableReference = schemaReference + tableName;
71
78
  return `alter table ${tableReference} rename column ${oldColumnName} to ${columnName}`;
72
79
  }
73
- getCreateIndexSQL(tableName, index) {
74
- /* istanbul ignore if */
75
- if (index.expression) {
80
+ getCreateIndexSQL(tableName, index, partialExpression = false) {
81
+ /* istanbul ignore next */
82
+ if (index.expression && !partialExpression) {
76
83
  return index.expression;
77
84
  }
78
85
  tableName = this.platform.quoteIdentifier(tableName);
79
86
  const keyName = this.platform.quoteIdentifier(index.keyName);
80
- return `create index ${keyName} on ${tableName} (${index.columnNames.map(c => this.platform.quoteIdentifier(c)).join(', ')})`;
87
+ const sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName} `;
88
+ if (index.expression && partialExpression) {
89
+ return `${sql}(${index.expression})`;
90
+ }
91
+ return `${sql}(${index.columnNames.map(c => this.platform.quoteIdentifier(c)).join(', ')})`;
81
92
  }
82
93
  getDropIndexSQL(tableName, index) {
83
94
  return `drop index ${this.platform.quoteIdentifier(index.keyName)}`;
@@ -95,7 +106,7 @@ class SchemaHelper {
95
106
  }
96
107
  createTableColumn(table, column, fromTable, changedProperties) {
97
108
  const compositePK = fromTable.getPrimaryKey()?.composite;
98
- if (column.autoincrement && !compositePK && (!changedProperties || changedProperties.has('autoincrement') || changedProperties.has('type'))) {
109
+ if (column.autoincrement && !column.generated && !compositePK && (!changedProperties || changedProperties.has('autoincrement') || changedProperties.has('type'))) {
99
110
  const primaryKey = !changedProperties && !this.hasNonDefaultPrimaryKeyName(fromTable);
100
111
  if (column.mappedType instanceof core_1.BigIntType) {
101
112
  return table.bigIncrements(column.name, { primaryKey });
@@ -105,12 +116,16 @@ class SchemaHelper {
105
116
  if (column.mappedType instanceof core_1.EnumType && column.enumItems?.every(item => core_1.Utils.isString(item))) {
106
117
  return table.enum(column.name, column.enumItems);
107
118
  }
108
- return table.specificType(column.name, column.type);
119
+ let columnType = column.type;
120
+ if (column.generated) {
121
+ columnType += ` generated always as ${column.generated}`;
122
+ }
123
+ return table.specificType(column.name, columnType);
109
124
  }
110
125
  configureColumn(column, col, knex, changedProperties) {
111
126
  const guard = (key) => !changedProperties || changedProperties.has(key);
112
127
  core_1.Utils.runIfNotEmpty(() => col.nullable(), column.nullable && guard('nullable'));
113
- core_1.Utils.runIfNotEmpty(() => col.notNullable(), !column.nullable);
128
+ core_1.Utils.runIfNotEmpty(() => col.notNullable(), !column.nullable && !column.generated);
114
129
  core_1.Utils.runIfNotEmpty(() => col.unsigned(), column.unsigned);
115
130
  core_1.Utils.runIfNotEmpty(() => col.comment(column.comment), column.comment);
116
131
  this.configureColumnDefault(column, col, knex, changedProperties);
@@ -122,17 +137,17 @@ class SchemaHelper {
122
137
  core_1.Utils.runIfNotEmpty(() => col.defaultTo(column.default == null ? null : knex.raw(column.default)), guard('default'));
123
138
  }
124
139
  else {
125
- core_1.Utils.runIfNotEmpty(() => col.defaultTo(column.default == null ? null : knex.raw(column.default)), column.default !== undefined);
140
+ core_1.Utils.runIfNotEmpty(() => col.defaultTo(knex.raw(column.default)), column.default != null && column.default !== 'null');
126
141
  }
127
142
  return col;
128
143
  }
129
144
  getPreAlterTable(tableDiff, safe) {
130
145
  return '';
131
146
  }
132
- getAlterColumnAutoincrement(tableName, column) {
147
+ getAlterColumnAutoincrement(tableName, column, schemaName) {
133
148
  return '';
134
149
  }
135
- getChangeColumnCommentSQL(tableName, to) {
150
+ getChangeColumnCommentSQL(tableName, to, schemaName) {
136
151
  return '';
137
152
  }
138
153
  async getNamespaces(connection) {
@@ -187,6 +202,10 @@ class SchemaHelper {
187
202
  if (defaultValue == null) {
188
203
  return defaultValue;
189
204
  }
205
+ const raw = core_1.RawQueryFragment.getKnownFragment(defaultValue);
206
+ if (raw) {
207
+ return this.platform.formatQuery(raw.sql, raw.params);
208
+ }
190
209
  const genericValue = defaultValue.replace(/\(\d+\)/, '(?)').toLowerCase();
191
210
  const norm = defaultValues[genericValue];
192
211
  if (!norm) {
@@ -1,5 +1,4 @@
1
- import type { MikroORM, ISchemaGenerator } from '@mikro-orm/core';
2
- import { AbstractSchemaGenerator } from '@mikro-orm/core';
1
+ import { AbstractSchemaGenerator, type MikroORM, type ISchemaGenerator, type ClearDatabaseOptions, type CreateSchemaOptions, type EnsureDatabaseOptions, type DropSchemaOptions, type UpdateSchemaOptions } from '@mikro-orm/core';
3
2
  import type { SchemaDifference } from '../typings';
4
3
  import { DatabaseSchema } from './DatabaseSchema';
5
4
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
@@ -8,56 +7,20 @@ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<Abstract
8
7
  private readonly options;
9
8
  protected lastEnsuredDatabase?: string;
10
9
  static register(orm: MikroORM): void;
11
- createSchema(options?: {
12
- wrap?: boolean;
13
- schema?: string;
14
- }): Promise<void>;
10
+ createSchema(options?: CreateSchemaOptions): Promise<void>;
15
11
  /**
16
12
  * Returns true if the database was created.
17
13
  */
18
- ensureDatabase(): Promise<boolean>;
14
+ ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
19
15
  getTargetSchema(schema?: string): DatabaseSchema;
20
- getCreateSchemaSQL(options?: {
21
- wrap?: boolean;
22
- schema?: string;
23
- }): Promise<string>;
24
- dropSchema(options?: {
25
- wrap?: boolean;
26
- dropMigrationsTable?: boolean;
27
- dropDb?: boolean;
28
- schema?: string;
29
- }): Promise<void>;
30
- clearDatabase(options?: {
31
- schema?: string;
32
- truncate?: boolean;
33
- }): Promise<void>;
34
- getDropSchemaSQL(options?: {
35
- wrap?: boolean;
36
- dropMigrationsTable?: boolean;
37
- schema?: string;
38
- }): Promise<string>;
16
+ getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
17
+ dropSchema(options?: DropSchemaOptions): Promise<void>;
18
+ clearDatabase(options?: ClearDatabaseOptions): Promise<void>;
19
+ getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
39
20
  private getSchemaName;
40
- updateSchema(options?: {
41
- wrap?: boolean;
42
- safe?: boolean;
43
- dropTables?: boolean;
44
- fromSchema?: DatabaseSchema;
45
- schema?: string;
46
- }): Promise<void>;
47
- getUpdateSchemaSQL(options?: {
48
- wrap?: boolean;
49
- safe?: boolean;
50
- dropTables?: boolean;
51
- fromSchema?: DatabaseSchema;
52
- schema?: string;
53
- }): Promise<string>;
54
- getUpdateSchemaMigrationSQL(options?: {
55
- wrap?: boolean;
56
- safe?: boolean;
57
- dropTables?: boolean;
58
- fromSchema?: DatabaseSchema;
59
- schema?: string;
60
- }): Promise<{
21
+ updateSchema(options?: UpdateSchemaOptions<DatabaseSchema>): Promise<void>;
22
+ getUpdateSchemaSQL(options?: UpdateSchemaOptions<DatabaseSchema>): Promise<string>;
23
+ getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions<DatabaseSchema>): Promise<{
61
24
  up: string;
62
25
  down: string;
63
26
  }>;
@@ -80,7 +43,7 @@ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<Abstract
80
43
  * creates new database and connects to it
81
44
  */
82
45
  createDatabase(name: string): Promise<void>;
83
- dropDatabase(name: string): Promise<void>;
46
+ dropDatabase(name?: string): Promise<void>;
84
47
  execute(sql: string, options?: {
85
48
  wrap?: boolean;
86
49
  }): Promise<void>;