@mikro-orm/knex 6.0.0-dev.1 → 6.0.0-dev.11
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/{dist/AbstractSqlConnection.d.ts → AbstractSqlConnection.d.ts} +0 -0
- package/{dist/AbstractSqlConnection.js → AbstractSqlConnection.js} +5 -0
- package/AbstractSqlDriver.d.ts +66 -0
- package/{dist/AbstractSqlDriver.js → AbstractSqlDriver.js} +226 -70
- package/{dist/AbstractSqlPlatform.d.ts → AbstractSqlPlatform.d.ts} +7 -7
- package/{dist/AbstractSqlPlatform.js → AbstractSqlPlatform.js} +12 -14
- package/{dist/MonkeyPatchable.d.ts → MonkeyPatchable.d.ts} +0 -0
- package/{dist/MonkeyPatchable.js → MonkeyPatchable.js} +0 -0
- package/{dist/README.md → README.md} +2 -2
- package/{dist/SqlEntityManager.d.ts → SqlEntityManager.d.ts} +5 -5
- package/{dist/SqlEntityManager.js → SqlEntityManager.js} +0 -1
- package/{dist/SqlEntityRepository.d.ts → SqlEntityRepository.d.ts} +3 -3
- package/{dist/SqlEntityRepository.js → SqlEntityRepository.js} +1 -1
- package/{dist/index.d.ts → index.d.ts} +1 -0
- package/{dist/index.js → index.js} +6 -1
- package/index.mjs +192 -0
- package/package.json +18 -47
- package/{dist/query → query}/ArrayCriteriaNode.d.ts +0 -0
- package/{dist/query → query}/ArrayCriteriaNode.js +0 -0
- package/{dist/query → query}/CriteriaNode.d.ts +0 -0
- package/{dist/query → query}/CriteriaNode.js +7 -4
- package/{dist/query → query}/CriteriaNodeFactory.d.ts +0 -0
- package/{dist/query → query}/CriteriaNodeFactory.js +0 -0
- package/{dist/query → query}/ObjectCriteriaNode.d.ts +0 -0
- package/{dist/query → query}/ObjectCriteriaNode.js +14 -1
- package/{dist/query → query}/QueryBuilder.d.ts +61 -24
- package/{dist/query → query}/QueryBuilder.js +308 -84
- package/{dist/query → query}/QueryBuilderHelper.d.ts +19 -11
- package/{dist/query → query}/QueryBuilderHelper.js +206 -108
- package/{dist/query → query}/ScalarCriteriaNode.d.ts +0 -0
- package/{dist/query → query}/ScalarCriteriaNode.js +0 -0
- package/{dist/query → query}/enums.d.ts +0 -0
- package/{dist/query → query}/enums.js +0 -0
- package/{dist/query → query}/index.d.ts +0 -0
- package/{dist/query → query}/index.js +5 -1
- package/{dist/schema → schema}/DatabaseSchema.d.ts +1 -1
- package/{dist/schema → schema}/DatabaseSchema.js +8 -16
- package/{dist/schema → schema}/DatabaseTable.d.ts +8 -8
- package/{dist/schema → schema}/DatabaseTable.js +2 -1
- package/{dist/schema → schema}/SchemaComparator.d.ts +7 -5
- package/{dist/schema → schema}/SchemaComparator.js +58 -10
- package/{dist/schema → schema}/SchemaHelper.d.ts +15 -10
- package/{dist/schema → schema}/SchemaHelper.js +46 -8
- package/{dist/schema/SchemaGenerator.d.ts → schema/SqlSchemaGenerator.d.ts} +12 -12
- package/{dist/schema/SchemaGenerator.js → schema/SqlSchemaGenerator.js} +85 -34
- package/{dist/schema → schema}/index.d.ts +1 -1
- package/{dist/schema → schema}/index.js +6 -2
- package/{dist/typings.d.ts → typings.d.ts} +16 -12
- package/{dist/typings.js → typings.js} +0 -0
- package/CHANGELOG.md +0 -661
- package/dist/AbstractSqlDriver.d.ts +0 -55
- package/dist/LICENSE +0 -21
- package/dist/index.mjs +0 -26
- package/dist/package.json +0 -99
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaGenerator = void 0;
|
|
3
|
+
exports.SchemaGenerator = exports.SqlSchemaGenerator = void 0;
|
|
4
4
|
const core_1 = require("@mikro-orm/core");
|
|
5
5
|
const DatabaseSchema_1 = require("./DatabaseSchema");
|
|
6
6
|
const SchemaComparator_1 = require("./SchemaComparator");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
12
|
-
/**
|
|
13
|
-
* `orm.getSchemaGenerator()` should be preferred way of getting the SchemaGenerator instance.
|
|
14
|
-
*/
|
|
15
|
-
constructor(driver) {
|
|
16
|
-
super(driver instanceof SqlEntityManager_1.SqlEntityManager ? driver.getDriver() : driver);
|
|
7
|
+
class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
17
10
|
this.helper = this.platform.getSchemaHelper();
|
|
18
|
-
this.knex = this.connection.getKnex();
|
|
19
11
|
this.options = this.config.get('schemaGenerator');
|
|
20
12
|
}
|
|
13
|
+
static register(orm) {
|
|
14
|
+
orm.config.registerExtension('@mikro-orm/schema-generator', () => new SqlSchemaGenerator(orm.em));
|
|
15
|
+
}
|
|
16
|
+
/** @deprecated use `dropSchema` and `createSchema` commands respectively */
|
|
21
17
|
async generate() {
|
|
22
18
|
const [dropSchema, createSchema] = await Promise.all([
|
|
23
19
|
this.getDropSchemaSQL({ wrap: false }),
|
|
@@ -35,7 +31,11 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
35
31
|
*/
|
|
36
32
|
async ensureDatabase() {
|
|
37
33
|
const dbName = this.config.get('dbName');
|
|
34
|
+
if (this.lastEnsuredDatabase === dbName) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
38
37
|
const exists = await this.helper.databaseExists(this.connection, dbName);
|
|
38
|
+
this.lastEnsuredDatabase = dbName;
|
|
39
39
|
if (!exists) {
|
|
40
40
|
this.config.set('dbName', this.helper.getManagementDbName());
|
|
41
41
|
await this.driver.reconnect();
|
|
@@ -48,7 +48,8 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
48
48
|
}
|
|
49
49
|
getTargetSchema(schema) {
|
|
50
50
|
const metadata = this.getOrderedMetadata(schema);
|
|
51
|
-
|
|
51
|
+
const schemaName = schema ?? this.config.get('schema') ?? this.platform.getDefaultSchemaName();
|
|
52
|
+
return DatabaseSchema_1.DatabaseSchema.fromMetadata(metadata, this.platform, this.config, schemaName);
|
|
52
53
|
}
|
|
53
54
|
async getCreateSchemaSQL(options = {}) {
|
|
54
55
|
const wrap = options.wrap ?? this.options.disableForeignKeys;
|
|
@@ -69,7 +70,6 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
69
70
|
return this.wrapSchema(ret, { wrap });
|
|
70
71
|
}
|
|
71
72
|
async dropSchema(options = {}) {
|
|
72
|
-
options.wrap ?? (options.wrap = true);
|
|
73
73
|
if (options.dropDb) {
|
|
74
74
|
const name = this.config.get('dbName');
|
|
75
75
|
return this.dropDatabase(name);
|
|
@@ -77,10 +77,44 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
77
77
|
const sql = await this.getDropSchemaSQL(options);
|
|
78
78
|
await this.execute(sql);
|
|
79
79
|
}
|
|
80
|
+
async clearDatabase(options) {
|
|
81
|
+
// truncate by default, so no value is considered as true
|
|
82
|
+
/* istanbul ignore if */
|
|
83
|
+
if (options?.truncate === false) {
|
|
84
|
+
return super.clearDatabase(options);
|
|
85
|
+
}
|
|
86
|
+
await this.execute(this.helper.disableForeignKeysSQL());
|
|
87
|
+
for (const meta of this.getOrderedMetadata(options?.schema).reverse()) {
|
|
88
|
+
await this.driver.createQueryBuilder(meta.className, this.em?.getTransactionContext(), 'write', false)
|
|
89
|
+
.withSchema(options?.schema)
|
|
90
|
+
.truncate();
|
|
91
|
+
}
|
|
92
|
+
await this.execute(this.helper.enableForeignKeysSQL());
|
|
93
|
+
if (this.em) {
|
|
94
|
+
const allowGlobalContext = this.config.get('allowGlobalContext');
|
|
95
|
+
this.config.set('allowGlobalContext', true);
|
|
96
|
+
this.em.clear();
|
|
97
|
+
this.config.set('allowGlobalContext', allowGlobalContext);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
80
100
|
async getDropSchemaSQL(options = {}) {
|
|
101
|
+
await this.ensureDatabase();
|
|
81
102
|
const wrap = options.wrap ?? this.options.disableForeignKeys;
|
|
82
103
|
const metadata = this.getOrderedMetadata(options.schema).reverse();
|
|
104
|
+
const schema = await DatabaseSchema_1.DatabaseSchema.create(this.connection, this.platform, this.config, options.schema);
|
|
83
105
|
let ret = '';
|
|
106
|
+
// remove FKs explicitly if we can't use cascading statement and we don't disable FK checks (we need this for circular relations)
|
|
107
|
+
for (const meta of metadata) {
|
|
108
|
+
const table = schema.getTable(meta.tableName);
|
|
109
|
+
if (!this.platform.usesCascadeStatement() && table && !wrap) {
|
|
110
|
+
for (const fk of Object.values(table.getForeignKeys())) {
|
|
111
|
+
const builder = this.createSchemaBuilder(table.schema).alterTable(table.name, tbl => {
|
|
112
|
+
tbl.dropForeign(fk.columnNames, fk.constraintName);
|
|
113
|
+
});
|
|
114
|
+
ret += await this.dump(builder, '\n');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
84
118
|
for (const meta of metadata) {
|
|
85
119
|
ret += await this.dump(this.dropTable(meta.collection, this.getSchemaName(meta, options)), '\n');
|
|
86
120
|
}
|
|
@@ -90,20 +124,23 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
90
124
|
return this.wrapSchema(ret + '\n', { wrap });
|
|
91
125
|
}
|
|
92
126
|
getSchemaName(meta, options) {
|
|
127
|
+
const schemaName = options.schema ?? this.config.get('schema');
|
|
93
128
|
/* istanbul ignore next */
|
|
94
|
-
return meta.schema === '*' ?
|
|
129
|
+
return meta.schema && meta.schema === '*' ? schemaName : (meta.schema ?? schemaName);
|
|
95
130
|
}
|
|
96
131
|
async updateSchema(options = {}) {
|
|
97
132
|
const sql = await this.getUpdateSchemaSQL(options);
|
|
98
133
|
await this.execute(sql);
|
|
99
134
|
}
|
|
100
135
|
async getUpdateSchemaSQL(options = {}) {
|
|
136
|
+
await this.ensureDatabase();
|
|
101
137
|
const { fromSchema, toSchema } = await this.prepareSchemaForComparison(options);
|
|
102
138
|
const comparator = new SchemaComparator_1.SchemaComparator(this.platform);
|
|
103
139
|
const diffUp = comparator.compare(fromSchema, toSchema);
|
|
104
140
|
return this.diffToSQL(diffUp, options);
|
|
105
141
|
}
|
|
106
142
|
async getUpdateSchemaMigrationSQL(options = {}) {
|
|
143
|
+
await this.ensureDatabase();
|
|
107
144
|
const { fromSchema, toSchema } = await this.prepareSchemaForComparison(options);
|
|
108
145
|
const comparator = new SchemaComparator_1.SchemaComparator(this.platform);
|
|
109
146
|
const diffUp = comparator.compare(fromSchema, toSchema);
|
|
@@ -240,7 +277,7 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
240
277
|
}
|
|
241
278
|
for (const column of Object.values(diff.addedColumns)) {
|
|
242
279
|
const col = this.helper.createTableColumn(table, column, diff.fromTable);
|
|
243
|
-
this.configureColumn(column, col);
|
|
280
|
+
this.helper.configureColumn(column, col, this.knex);
|
|
244
281
|
const foreignKey = Object.values(diff.addedForeignKeys).find(fk => fk.columnNames.length === 1 && fk.columnNames[0] === column.name);
|
|
245
282
|
if (foreignKey && this.options.createForeignKeyConstraints) {
|
|
246
283
|
delete diff.addedForeignKeys[foreignKey.constraintName];
|
|
@@ -262,7 +299,7 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
262
299
|
continue;
|
|
263
300
|
}
|
|
264
301
|
const col = this.helper.createTableColumn(table, column, diff.fromTable, changedProperties).alter();
|
|
265
|
-
this.configureColumn(column, col, changedProperties);
|
|
302
|
+
this.helper.configureColumn(column, col, this.knex, changedProperties);
|
|
266
303
|
}
|
|
267
304
|
for (const { column } of Object.values(diff.changedColumns).filter(diff => diff.changedProperties.has('autoincrement'))) {
|
|
268
305
|
this.helper.pushTableQuery(table, this.helper.getAlterColumnAutoincrement(tableName, column));
|
|
@@ -274,7 +311,7 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
274
311
|
this.helper.pushTableQuery(table, this.helper.getChangeColumnCommentSQL(tableName, column));
|
|
275
312
|
}
|
|
276
313
|
for (const [oldColumnName, column] of Object.entries(diff.renamedColumns)) {
|
|
277
|
-
this.helper.pushTableQuery(table, this.helper.getRenameColumnSQL(tableName, oldColumnName, column));
|
|
314
|
+
this.helper.pushTableQuery(table, this.helper.getRenameColumnSQL(tableName, oldColumnName, column, schemaName));
|
|
278
315
|
}
|
|
279
316
|
for (const foreignKey of Object.values(diff.addedForeignKeys)) {
|
|
280
317
|
this.createForeignKey(table, foreignKey);
|
|
@@ -283,15 +320,15 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
283
320
|
this.createForeignKey(table, foreignKey);
|
|
284
321
|
}
|
|
285
322
|
for (const index of Object.values(diff.addedIndexes)) {
|
|
286
|
-
this.createIndex(table, index, diff.
|
|
323
|
+
this.createIndex(table, index, diff.toTable);
|
|
287
324
|
}
|
|
288
325
|
for (const index of Object.values(diff.changedIndexes)) {
|
|
289
|
-
this.createIndex(table, index, diff.
|
|
326
|
+
this.createIndex(table, index, diff.toTable, true);
|
|
290
327
|
}
|
|
291
328
|
for (const [oldIndexName, index] of Object.entries(diff.renamedIndexes)) {
|
|
292
329
|
if (index.unique) {
|
|
293
330
|
this.dropIndex(table, index, oldIndexName);
|
|
294
|
-
this.createIndex(table, index, diff.
|
|
331
|
+
this.createIndex(table, index, diff.toTable);
|
|
295
332
|
}
|
|
296
333
|
else {
|
|
297
334
|
this.helper.pushTableQuery(table, this.helper.getRenameIndexSQL(diff.name, index, oldIndexName));
|
|
@@ -304,7 +341,8 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
304
341
|
this.createCheck(table, check);
|
|
305
342
|
}
|
|
306
343
|
if ('changedComment' in diff) {
|
|
307
|
-
|
|
344
|
+
const comment = diff.changedComment ? this.platform.quoteValue(diff.changedComment).replace(/^'|'$/g, '') : '';
|
|
345
|
+
table.comment(comment);
|
|
308
346
|
}
|
|
309
347
|
}));
|
|
310
348
|
return ret;
|
|
@@ -325,9 +363,14 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
325
363
|
async execute(sql, options = {}) {
|
|
326
364
|
options.wrap ?? (options.wrap = false);
|
|
327
365
|
const lines = this.wrapSchema(sql, options).split('\n').filter(i => i.trim());
|
|
328
|
-
|
|
329
|
-
|
|
366
|
+
if (lines.length === 0) {
|
|
367
|
+
return;
|
|
330
368
|
}
|
|
369
|
+
if (this.platform.supportsMultipleStatements()) {
|
|
370
|
+
const query = lines.join('\n');
|
|
371
|
+
return void await this.driver.execute(query);
|
|
372
|
+
}
|
|
373
|
+
await core_1.Utils.runSerial(lines, line => this.driver.execute(line));
|
|
331
374
|
}
|
|
332
375
|
wrapSchema(sql, options = {}) {
|
|
333
376
|
options.wrap ?? (options.wrap = this.options.disableForeignKeys);
|
|
@@ -350,16 +393,18 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
350
393
|
return this.createSchemaBuilder(tableDef.schema).createTable(tableDef.name, table => {
|
|
351
394
|
tableDef.getColumns().forEach(column => {
|
|
352
395
|
const col = this.helper.createTableColumn(table, column, tableDef);
|
|
353
|
-
this.configureColumn(column, col);
|
|
396
|
+
this.helper.configureColumn(column, col, this.knex);
|
|
354
397
|
});
|
|
355
398
|
for (const index of tableDef.getIndexes()) {
|
|
356
|
-
|
|
399
|
+
const createPrimary = !tableDef.getColumns().some(c => c.autoincrement && c.primary) || this.helper.hasNonDefaultPrimaryKeyName(tableDef);
|
|
400
|
+
this.createIndex(table, index, tableDef, createPrimary);
|
|
357
401
|
}
|
|
358
402
|
for (const check of tableDef.getChecks()) {
|
|
359
403
|
this.createCheck(table, check);
|
|
360
404
|
}
|
|
361
405
|
if (tableDef.comment) {
|
|
362
|
-
|
|
406
|
+
const comment = this.platform.quoteValue(tableDef.comment).replace(/^'|'$/g, '');
|
|
407
|
+
table.comment(comment);
|
|
363
408
|
}
|
|
364
409
|
if (!this.helper.supportsSchemaConstraints()) {
|
|
365
410
|
for (const fk of Object.values(tableDef.getForeignKeys())) {
|
|
@@ -369,13 +414,12 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
369
414
|
this.helper.finalizeTable(table, this.config.get('charset'), this.config.get('collate'));
|
|
370
415
|
});
|
|
371
416
|
}
|
|
372
|
-
createIndex(table, index,
|
|
417
|
+
createIndex(table, index, tableDef, createPrimary = false) {
|
|
373
418
|
if (index.primary && !createPrimary) {
|
|
374
419
|
return;
|
|
375
420
|
}
|
|
376
421
|
if (index.primary) {
|
|
377
|
-
|
|
378
|
-
const keyName = tableName.includes('.') ? tableName.split('.').pop() + '_pkey' : undefined;
|
|
422
|
+
const keyName = this.helper.hasNonDefaultPrimaryKeyName(tableDef) ? index.keyName : undefined;
|
|
379
423
|
table.primary(index.columnNames, keyName);
|
|
380
424
|
}
|
|
381
425
|
else if (index.unique) {
|
|
@@ -384,6 +428,12 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
384
428
|
else if (index.expression) {
|
|
385
429
|
this.helper.pushTableQuery(table, index.expression);
|
|
386
430
|
}
|
|
431
|
+
else if (index.type === 'fulltext') {
|
|
432
|
+
const columns = index.columnNames.map(name => ({ name, type: tableDef.getColumn(name).type }));
|
|
433
|
+
if (this.platform.supportsCreatingFullTextIndex()) {
|
|
434
|
+
this.helper.pushTableQuery(table, this.platform.getFullTextIndexExpression(index.keyName, tableDef.schema, tableDef.name, columns));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
387
437
|
else {
|
|
388
438
|
table.index(index.columnNames, index.keyName, index.type);
|
|
389
439
|
}
|
|
@@ -412,9 +462,6 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
412
462
|
}
|
|
413
463
|
return builder;
|
|
414
464
|
}
|
|
415
|
-
configureColumn(column, col, changedProperties) {
|
|
416
|
-
return this.helper.configureColumn(column, col, this.knex, changedProperties);
|
|
417
|
-
}
|
|
418
465
|
createForeignKeys(table, tableDef, schema) {
|
|
419
466
|
if (!this.helper.supportsSchemaConstraints()) {
|
|
420
467
|
return;
|
|
@@ -433,5 +480,9 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
433
480
|
const tmp = dump.replace(/pragma table_.+/ig, '').replace(/\n\n+/g, '\n').trim();
|
|
434
481
|
return tmp ? tmp + append : '';
|
|
435
482
|
}
|
|
483
|
+
get knex() {
|
|
484
|
+
return this.connection.getKnex();
|
|
485
|
+
}
|
|
436
486
|
}
|
|
437
|
-
exports.
|
|
487
|
+
exports.SqlSchemaGenerator = SqlSchemaGenerator;
|
|
488
|
+
exports.SchemaGenerator = SqlSchemaGenerator;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -12,6 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./DatabaseSchema"), exports);
|
|
14
18
|
__exportStar(require("./DatabaseTable"), exports);
|
|
15
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./SqlSchemaGenerator"), exports);
|
|
16
20
|
__exportStar(require("./SchemaHelper"), exports);
|
|
17
21
|
__exportStar(require("./SchemaComparator"), exports);
|
|
@@ -7,10 +7,11 @@ export interface Table {
|
|
|
7
7
|
schema_name?: string;
|
|
8
8
|
table_comment?: string;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export type KnexStringRef = Knex.Ref<string, {
|
|
11
11
|
[alias: string]: string;
|
|
12
12
|
}>;
|
|
13
|
-
|
|
13
|
+
type AnyString = string & {};
|
|
14
|
+
export type Field<T> = AnyString | keyof T | KnexStringRef | Knex.QueryBuilder;
|
|
14
15
|
export interface JoinOptions {
|
|
15
16
|
table: string;
|
|
16
17
|
schema?: string;
|
|
@@ -42,6 +43,7 @@ export interface Column {
|
|
|
42
43
|
unique?: boolean;
|
|
43
44
|
/** mysql only */
|
|
44
45
|
extra?: string;
|
|
46
|
+
ignoreSchemaChanges?: ('type' | 'extra')[];
|
|
45
47
|
}
|
|
46
48
|
export interface ForeignKey {
|
|
47
49
|
columnNames: string[];
|
|
@@ -52,7 +54,7 @@ export interface ForeignKey {
|
|
|
52
54
|
updateRule?: string;
|
|
53
55
|
deleteRule?: string;
|
|
54
56
|
}
|
|
55
|
-
export interface
|
|
57
|
+
export interface IndexDef {
|
|
56
58
|
columnNames: string[];
|
|
57
59
|
keyName: string;
|
|
58
60
|
unique: boolean;
|
|
@@ -65,7 +67,7 @@ export interface Index {
|
|
|
65
67
|
predicate?: Knex.QueryBuilder;
|
|
66
68
|
}>;
|
|
67
69
|
}
|
|
68
|
-
export interface
|
|
70
|
+
export interface CheckDef<T = unknown> {
|
|
69
71
|
name: string;
|
|
70
72
|
expression: string | CheckCallback<T>;
|
|
71
73
|
definition?: string;
|
|
@@ -81,17 +83,18 @@ export interface TableDifference {
|
|
|
81
83
|
name: string;
|
|
82
84
|
changedComment?: string;
|
|
83
85
|
fromTable: DatabaseTable;
|
|
86
|
+
toTable: DatabaseTable;
|
|
84
87
|
addedColumns: Dictionary<Column>;
|
|
85
88
|
changedColumns: Dictionary<ColumnDifference>;
|
|
86
89
|
removedColumns: Dictionary<Column>;
|
|
87
90
|
renamedColumns: Dictionary<Column>;
|
|
88
|
-
addedIndexes: Dictionary<
|
|
89
|
-
changedIndexes: Dictionary<
|
|
90
|
-
removedIndexes: Dictionary<
|
|
91
|
-
renamedIndexes: Dictionary<
|
|
92
|
-
addedChecks: Dictionary<
|
|
93
|
-
changedChecks: Dictionary<
|
|
94
|
-
removedChecks: Dictionary<
|
|
91
|
+
addedIndexes: Dictionary<IndexDef>;
|
|
92
|
+
changedIndexes: Dictionary<IndexDef>;
|
|
93
|
+
removedIndexes: Dictionary<IndexDef>;
|
|
94
|
+
renamedIndexes: Dictionary<IndexDef>;
|
|
95
|
+
addedChecks: Dictionary<CheckDef>;
|
|
96
|
+
changedChecks: Dictionary<CheckDef>;
|
|
97
|
+
removedChecks: Dictionary<CheckDef>;
|
|
95
98
|
addedForeignKeys: Dictionary<ForeignKey>;
|
|
96
99
|
changedForeignKeys: Dictionary<ForeignKey>;
|
|
97
100
|
removedForeignKeys: Dictionary<ForeignKey>;
|
|
@@ -107,7 +110,7 @@ export interface SchemaDifference {
|
|
|
107
110
|
}
|
|
108
111
|
export interface IQueryBuilder<T> {
|
|
109
112
|
readonly alias: string;
|
|
110
|
-
readonly type
|
|
113
|
+
readonly type?: QueryType;
|
|
111
114
|
_fields?: Field<T>[];
|
|
112
115
|
select(fields: Field<T> | Field<T>[], distinct?: boolean): this;
|
|
113
116
|
addSelect(fields: string | string[]): this;
|
|
@@ -148,3 +151,4 @@ export interface ICriteriaNode {
|
|
|
148
151
|
getPath(addIndex?: boolean): string;
|
|
149
152
|
getPivotPath(path: string): string;
|
|
150
153
|
}
|
|
154
|
+
export {};
|
|
File without changes
|