dbgate-tools 5.4.4 → 5.4.5-alpha.3

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.
@@ -31,6 +31,7 @@ export declare class SqlDumper implements AlterProcessor {
31
31
  columnDefault(column: ColumnInfo): void;
32
32
  putCollection<T>(delimiter: string, collection: T[], lambda: (col: T) => void): void;
33
33
  createTable(table: TableInfo): void;
34
+ tableOptions(table: TableInfo): void;
34
35
  createTablePrimaryKeyCore(table: TableInfo): void;
35
36
  createForeignKeyFore(fk: ForeignKeyInfo): void;
36
37
  transform(type: TransformType, dumpExpr: any): void;
@@ -111,5 +112,7 @@ export declare class SqlDumper implements AlterProcessor {
111
112
  createSqlObject(obj: SqlObjectInfo): void;
112
113
  getSqlObjectSqlName(ojectTypeField: string): "PROCEDURE" | "VIEW" | "FUNCTION" | "TRIGGER" | "MATERIALIZED VIEW";
113
114
  dropSqlObject(obj: SqlObjectInfo): void;
115
+ setTableOption(table: TableInfo, optionName: string, optionValue: string): void;
116
+ setTableOptionCore(table: TableInfo, optionName: string, optionValue: string, formatString: string): void;
114
117
  fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
115
118
  }
package/lib/SqlDumper.js CHANGED
@@ -215,7 +215,7 @@ class SqlDumper {
215
215
  }
216
216
  }
217
217
  columnDefinition(column, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
218
- var _a;
218
+ var _a, _b;
219
219
  if (column.computedExpression) {
220
220
  this.put('^as %s', column.computedExpression);
221
221
  if (column.isPersisted)
@@ -228,10 +228,10 @@ class SqlDumper {
228
228
  }
229
229
  this.putRaw(' ');
230
230
  this.specialColumnOptions(column);
231
- if (includeNullable) {
231
+ if (includeNullable && !((_a = this.dialect) === null || _a === void 0 ? void 0 : _a.specificNullabilityImplementation)) {
232
232
  this.put(column.notNull ? '^not ^null' : '^null');
233
233
  }
234
- if (includeDefault && ((_a = column.defaultValue) === null || _a === void 0 ? void 0 : _a.trim())) {
234
+ if (includeDefault && ((_b = column.defaultValue) === null || _b === void 0 ? void 0 : _b.trim())) {
235
235
  this.columnDefault(column);
236
236
  }
237
237
  }
@@ -274,11 +274,22 @@ class SqlDumper {
274
274
  this.createCheckCore(chk);
275
275
  });
276
276
  this.put('&<&n)');
277
+ this.tableOptions(table);
277
278
  this.endCommand();
278
279
  (table.indexes || []).forEach(ix => {
279
280
  this.createIndex(ix);
280
281
  });
281
282
  }
283
+ tableOptions(table) {
284
+ var _a, _b, _c;
285
+ const options = ((_c = (_b = (_a = this.driver) === null || _a === void 0 ? void 0 : _a.dialect) === null || _b === void 0 ? void 0 : _b.getTableFormOptions) === null || _c === void 0 ? void 0 : _c.call(_b, 'sqlCreateTable')) || [];
286
+ for (const option of options) {
287
+ if (table[option.name]) {
288
+ this.put('&n');
289
+ this.put(option.sqlFormatString, table[option.name]);
290
+ }
291
+ }
292
+ }
282
293
  createTablePrimaryKeyCore(table) {
283
294
  if (table.primaryKey) {
284
295
  this.put(',&n');
@@ -482,7 +493,10 @@ class SqlDumper {
482
493
  }
483
494
  renameConstraint(constraint, newName) { }
484
495
  createColumn(column, constraints) {
485
- this.put('^alter ^table %f ^add %i ', column, column.columnName);
496
+ this.put('^alter ^table %f ^add ', column);
497
+ if (this.dialect.createColumnWithColumnKeyword)
498
+ this.put('^column ');
499
+ this.put(' %i ', column.columnName);
486
500
  this.columnDefinition(column);
487
501
  this.inlineConstraints(constraints);
488
502
  this.endCommand();
@@ -545,29 +559,36 @@ class SqlDumper {
545
559
  throw new Error('Recreate is not possible: oldTable.paringId != newTable.paringId');
546
560
  }
547
561
  const tmpTable = `temp_${(0, v1_1.default)()}`;
548
- // console.log('oldTable', oldTable);
549
- // console.log('newTable', newTable);
550
562
  const columnPairs = oldTable.columns
551
563
  .map(oldcol => ({
552
564
  oldcol,
553
565
  newcol: newTable.columns.find(x => x.pairingId == oldcol.pairingId),
554
566
  }))
555
567
  .filter(x => x.newcol);
556
- this.dropConstraints(oldTable, true);
557
- this.renameTable(oldTable, tmpTable);
558
- this.createTable(newTable);
559
- const autoinc = newTable.columns.find(x => x.autoIncrement);
560
- if (autoinc) {
561
- this.allowIdentityInsert(newTable, true);
562
- }
563
- this.putCmd('^insert ^into %f (%,i) select %,s ^from %f', newTable, columnPairs.map(x => x.newcol.columnName), columnPairs.map(x => x.oldcol.columnName), Object.assign(Object.assign({}, oldTable), { pureName: tmpTable }));
564
- if (autoinc) {
565
- this.allowIdentityInsert(newTable, false);
568
+ if (this.driver.supportsTransactions) {
569
+ this.dropConstraints(oldTable, true);
570
+ this.renameTable(oldTable, tmpTable);
571
+ this.createTable(newTable);
572
+ const autoinc = newTable.columns.find(x => x.autoIncrement);
573
+ if (autoinc) {
574
+ this.allowIdentityInsert(newTable, true);
575
+ }
576
+ this.putCmd('^insert ^into %f (%,i) select %,s ^from %f', newTable, columnPairs.map(x => x.newcol.columnName), columnPairs.map(x => x.oldcol.columnName), Object.assign(Object.assign({}, oldTable), { pureName: tmpTable }));
577
+ if (autoinc) {
578
+ this.allowIdentityInsert(newTable, false);
579
+ }
580
+ if (this.dialect.dropForeignKey) {
581
+ newTable.dependencies.forEach(cnt => this.createConstraint(cnt));
582
+ }
583
+ this.dropTable(Object.assign(Object.assign({}, oldTable), { pureName: tmpTable }));
566
584
  }
567
- if (this.dialect.dropForeignKey) {
568
- newTable.dependencies.forEach(cnt => this.createConstraint(cnt));
585
+ else {
586
+ // we have to preserve old table as long as possible
587
+ this.createTable(Object.assign(Object.assign({}, newTable), { pureName: tmpTable }));
588
+ this.putCmd('^insert ^into %f (%,i) select %,s ^from %f', Object.assign(Object.assign({}, newTable), { pureName: tmpTable }), columnPairs.map(x => x.newcol.columnName), columnPairs.map(x => x.oldcol.columnName), oldTable);
589
+ this.dropTable(oldTable);
590
+ this.renameTable(Object.assign(Object.assign({}, newTable), { pureName: tmpTable }), newTable.pureName);
569
591
  }
570
- this.dropTable(Object.assign(Object.assign({}, oldTable), { pureName: tmpTable }));
571
592
  }
572
593
  createSqlObject(obj) {
573
594
  this.putCmd(obj.createSql);
@@ -589,6 +610,20 @@ class SqlDumper {
589
610
  dropSqlObject(obj) {
590
611
  this.putCmd('^drop %s %f', this.getSqlObjectSqlName(obj.objectTypeField), obj);
591
612
  }
613
+ setTableOption(table, optionName, optionValue) {
614
+ var _a, _b;
615
+ const options = (_b = (_a = this === null || this === void 0 ? void 0 : this.dialect) === null || _a === void 0 ? void 0 : _a.getTableFormOptions) === null || _b === void 0 ? void 0 : _b.call(_a, 'sqlAlterTable');
616
+ const option = options === null || options === void 0 ? void 0 : options.find(x => x.name == optionName && !x.disabled);
617
+ if (!option) {
618
+ return;
619
+ }
620
+ this.setTableOptionCore(table, optionName, optionValue, option.sqlFormatString);
621
+ this.endCommand();
622
+ }
623
+ setTableOptionCore(table, optionName, optionValue, formatString) {
624
+ this.put('^alter ^table %f ', table);
625
+ this.put(formatString, optionValue);
626
+ }
592
627
  fillPreloadedRows(table, oldRows, newRows, key, insertOnly, autoIncrementColumn) {
593
628
  let was = false;
594
629
  for (const row of newRows) {
@@ -71,7 +71,13 @@ interface AlterOperation_FillPreloadedRows {
71
71
  insertOnly: string[];
72
72
  autoIncrementColumn: string;
73
73
  }
74
- type AlterOperation = AlterOperation_CreateColumn | AlterOperation_ChangeColumn | AlterOperation_DropColumn | AlterOperation_CreateConstraint | AlterOperation_ChangeConstraint | AlterOperation_DropConstraint | AlterOperation_CreateTable | AlterOperation_DropTable | AlterOperation_RenameTable | AlterOperation_RenameColumn | AlterOperation_RenameConstraint | AlterOperation_CreateSqlObject | AlterOperation_DropSqlObject | AlterOperation_RecreateTable | AlterOperation_FillPreloadedRows;
74
+ interface AlterOperation_SetTableOption {
75
+ operationType: 'setTableOption';
76
+ table: TableInfo;
77
+ optionName: string;
78
+ optionValue: string;
79
+ }
80
+ type AlterOperation = AlterOperation_CreateColumn | AlterOperation_ChangeColumn | AlterOperation_DropColumn | AlterOperation_CreateConstraint | AlterOperation_ChangeConstraint | AlterOperation_DropConstraint | AlterOperation_CreateTable | AlterOperation_DropTable | AlterOperation_RenameTable | AlterOperation_RenameColumn | AlterOperation_RenameConstraint | AlterOperation_CreateSqlObject | AlterOperation_DropSqlObject | AlterOperation_RecreateTable | AlterOperation_FillPreloadedRows | AlterOperation_SetTableOption;
75
81
  export declare class AlterPlan {
76
82
  wholeOldDb: DatabaseInfo;
77
83
  wholeNewDb: DatabaseInfo;
@@ -99,6 +105,7 @@ export declare class AlterPlan {
99
105
  renameConstraint(constraint: ConstraintInfo, newName: string): void;
100
106
  recreateTable(table: TableInfo, operations: AlterOperation[]): void;
101
107
  fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
108
+ setTableOption(table: TableInfo, optionName: string, optionValue: string): void;
102
109
  run(processor: AlterProcessor): void;
103
110
  _getDependendColumnConstraints(column: ColumnInfo, dependencyDefinition: any): import("dbgate-types/dbinfo").PrimaryKeyInfo[];
104
111
  _addLogicalDependencies(): AlterOperation[];
package/lib/alterPlan.js CHANGED
@@ -123,6 +123,14 @@ class AlterPlan {
123
123
  autoIncrementColumn,
124
124
  });
125
125
  }
126
+ setTableOption(table, optionName, optionValue) {
127
+ this.operations.push({
128
+ operationType: 'setTableOption',
129
+ table,
130
+ optionName,
131
+ optionValue,
132
+ });
133
+ }
126
134
  run(processor) {
127
135
  for (const op of this.operations) {
128
136
  runAlterOperation(op, processor);
@@ -137,6 +145,7 @@ class AlterPlan {
137
145
  : [];
138
146
  const constraints = lodash_1.default.compact([
139
147
  (dependencyDefinition === null || dependencyDefinition === void 0 ? void 0 : dependencyDefinition.includes('primaryKey')) ? table.primaryKey : null,
148
+ (dependencyDefinition === null || dependencyDefinition === void 0 ? void 0 : dependencyDefinition.includes('sortingKey')) ? table.sortingKey : null,
140
149
  ...((dependencyDefinition === null || dependencyDefinition === void 0 ? void 0 : dependencyDefinition.includes('foreignKeys')) ? table.foreignKeys : []),
141
150
  ...((dependencyDefinition === null || dependencyDefinition === void 0 ? void 0 : dependencyDefinition.includes('indexes')) ? table.indexes : []),
142
151
  ...((dependencyDefinition === null || dependencyDefinition === void 0 ? void 0 : dependencyDefinition.includes('uniques')) ? table.uniques : []),
@@ -236,6 +245,8 @@ class AlterPlan {
236
245
  _canCreateConstraint(cnt) {
237
246
  if (cnt.constraintType == 'primaryKey')
238
247
  return this.dialect.createPrimaryKey;
248
+ if (cnt.constraintType == 'sortingKey')
249
+ return this.dialect.createPrimaryKey;
239
250
  if (cnt.constraintType == 'foreignKey')
240
251
  return this.dialect.createForeignKey;
241
252
  if (cnt.constraintType == 'index')
@@ -249,6 +260,8 @@ class AlterPlan {
249
260
  _canDropConstraint(cnt) {
250
261
  if (cnt.constraintType == 'primaryKey')
251
262
  return this.dialect.dropPrimaryKey;
263
+ if (cnt.constraintType == 'sortingKey')
264
+ return this.dialect.dropPrimaryKey;
252
265
  if (cnt.constraintType == 'foreignKey')
253
266
  return this.dialect.dropForeignKey;
254
267
  if (cnt.constraintType == 'index')
@@ -408,6 +421,9 @@ function runAlterOperation(op, processor) {
408
421
  case 'dropSqlObject':
409
422
  processor.dropSqlObject(op.oldObject);
410
423
  break;
424
+ case 'setTableOption':
425
+ processor.setTableOption(op.table, op.optionName, op.optionValue);
426
+ break;
411
427
  case 'fillPreloadedRows':
412
428
  processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key, op.insertOnly, op.autoIncrementColumn);
413
429
  break;
@@ -17,4 +17,5 @@ export declare class DatabaseInfoAlterProcessor {
17
17
  renameConstraint(constraint: ConstraintInfo, newName: string): void;
18
18
  recreateTable(oldTable: TableInfo, newTable: TableInfo): void;
19
19
  fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
20
+ setTableOption(table: TableInfo, optionName: string, optionValue: string): void;
20
21
  }
@@ -45,6 +45,9 @@ class DatabaseInfoAlterProcessor {
45
45
  case 'primaryKey':
46
46
  table.primaryKey = constraint;
47
47
  break;
48
+ case 'sortingKey':
49
+ table.sortingKey = constraint;
50
+ break;
48
51
  case 'foreignKey':
49
52
  table.foreignKeys.push(constraint);
50
53
  break;
@@ -68,6 +71,9 @@ class DatabaseInfoAlterProcessor {
68
71
  case 'primaryKey':
69
72
  table.primaryKey = null;
70
73
  break;
74
+ case 'sortingKey':
75
+ table.sortingKey = null;
76
+ break;
71
77
  case 'foreignKey':
72
78
  table.foreignKeys = table.foreignKeys.filter(x => x.constraintName != constraint.constraintName);
73
79
  break;
@@ -99,5 +105,9 @@ class DatabaseInfoAlterProcessor {
99
105
  tableInfo.preloadedRowsKey = key;
100
106
  tableInfo.preloadedRowsInsertOnly = insertOnly;
101
107
  }
108
+ setTableOption(table, optionName, optionValue) {
109
+ const tableInfo = this.db.tables.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName);
110
+ tableInfo[optionName] = optionValue;
111
+ }
102
112
  }
103
113
  exports.DatabaseInfoAlterProcessor = DatabaseInfoAlterProcessor;
package/lib/diffTools.js CHANGED
@@ -16,7 +16,7 @@ function generateTablePairingId(table) {
16
16
  if (!table)
17
17
  return table;
18
18
  if (!table.pairingId) {
19
- return Object.assign(Object.assign({}, table), { columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { pairingId: col.pairingId || (0, v1_1.default)() }))), foreignKeys: (_b = table.foreignKeys) === null || _b === void 0 ? void 0 : _b.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), checks: (_c = table.checks) === null || _c === void 0 ? void 0 : _c.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), indexes: (_d = table.indexes) === null || _d === void 0 ? void 0 : _d.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), uniques: (_e = table.uniques) === null || _e === void 0 ? void 0 : _e.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), pairingId: table.pairingId || (0, v1_1.default)() });
19
+ return Object.assign(Object.assign({}, table), { primaryKey: table.primaryKey && Object.assign(Object.assign({}, table.primaryKey), { pairingId: table.primaryKey.pairingId || (0, v1_1.default)() }), sortingKey: table.sortingKey && Object.assign(Object.assign({}, table.sortingKey), { pairingId: table.sortingKey.pairingId || (0, v1_1.default)() }), columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { pairingId: col.pairingId || (0, v1_1.default)() }))), foreignKeys: (_b = table.foreignKeys) === null || _b === void 0 ? void 0 : _b.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), checks: (_c = table.checks) === null || _c === void 0 ? void 0 : _c.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), indexes: (_d = table.indexes) === null || _d === void 0 ? void 0 : _d.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), uniques: (_e = table.uniques) === null || _e === void 0 ? void 0 : _e.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), pairingId: table.pairingId || (0, v1_1.default)() });
20
20
  }
21
21
  return table;
22
22
  }
@@ -217,6 +217,8 @@ function getTableConstraints(table) {
217
217
  const res = [];
218
218
  if (table.primaryKey)
219
219
  res.push(table.primaryKey);
220
+ if (table.sortingKey)
221
+ res.push(table.sortingKey);
220
222
  if (table.foreignKeys)
221
223
  res.push(...table.foreignKeys);
222
224
  if (table.indexes)
@@ -230,7 +232,7 @@ function getTableConstraints(table) {
230
232
  function createPairs(oldList, newList, additionalCondition = null) {
231
233
  const res = [];
232
234
  for (const a of oldList) {
233
- const b = newList.find(x => x.pairingId == a.pairingId || (additionalCondition && additionalCondition(a, x)));
235
+ const b = newList.find(x => (a.pairingId && x.pairingId == a.pairingId) || (additionalCondition && additionalCondition(a, x)));
234
236
  if (b) {
235
237
  res.push([a, b]);
236
238
  }
@@ -255,8 +257,12 @@ function planTablePreload(plan, oldTable, newTable) {
255
257
  function planAlterTable(plan, oldTable, newTable, opts) {
256
258
  // if (oldTable.primaryKey)
257
259
  const columnPairs = createPairs(oldTable.columns, newTable.columns);
258
- const constraintPairs = createPairs(getTableConstraints(oldTable), getTableConstraints(newTable), (a, b) => a.constraintType == 'primaryKey' && b.constraintType == 'primaryKey');
259
- // console.log('constraintPairs SOURCE', getTableConstraints(oldTable), getTableConstraints(newTable));
260
+ const constraintPairs = createPairs(getTableConstraints(oldTable), getTableConstraints(newTable), (a, b) => (a.constraintType == 'primaryKey' && b.constraintType == 'primaryKey') ||
261
+ (a.constraintType == 'sortingKey' && b.constraintType == 'sortingKey'));
262
+ // console.log('constraintPairs OLD TABLE', oldTable);
263
+ // console.log('constraintPairs NEW TABLE', newTable);
264
+ // console.log('constraintPairs SOURCE OLD', getTableConstraints(oldTable));
265
+ // console.log('constraintPairs SOURCE NEW', getTableConstraints(newTable));
260
266
  // console.log('constraintPairs', constraintPairs);
261
267
  if (!opts.noDropConstraint) {
262
268
  constraintPairs.filter(x => x[1] == null).forEach(x => plan.dropConstraint(x[0]));
@@ -277,7 +283,7 @@ function planAlterTable(plan, oldTable, newTable, opts) {
277
283
  plan.renameColumn(x[0], x[1].columnName);
278
284
  }
279
285
  else {
280
- // console.log('PLAN CHANGE COLUMN')
286
+ // console.log('PLAN CHANGE COLUMN', x[0], x[1]);
281
287
  plan.changeColumn(x[0], x[1]);
282
288
  }
283
289
  }
@@ -292,6 +298,24 @@ function planAlterTable(plan, oldTable, newTable, opts) {
292
298
  });
293
299
  constraintPairs.filter(x => x[0] == null).forEach(x => plan.createConstraint(x[1]));
294
300
  planTablePreload(plan, oldTable, newTable);
301
+ planChangeTableOptions(plan, oldTable, newTable, opts);
302
+ // console.log('oldTable', oldTable);
303
+ // console.log('newTable', newTable);
304
+ // console.log('plan.operations', plan.operations);
305
+ }
306
+ function planChangeTableOptions(plan, oldTable, newTable, opts) {
307
+ var _a, _b;
308
+ for (const option of ((_b = (_a = plan.dialect) === null || _a === void 0 ? void 0 : _a.getTableFormOptions) === null || _b === void 0 ? void 0 : _b.call(_a, 'sqlAlterTable')) || []) {
309
+ if (option.disabled) {
310
+ continue;
311
+ }
312
+ const name = option.name;
313
+ if (oldTable[name] != newTable[name] &&
314
+ (oldTable[name] || newTable[name]) &&
315
+ (newTable[name] || option.allowEmptyValue)) {
316
+ plan.setTableOption(newTable, name, newTable[name]);
317
+ }
318
+ }
295
319
  }
296
320
  function testEqualTables(a, b, opts, wholeOldDb, wholeNewDb, driver) {
297
321
  const plan = new alterPlan_1.AlterPlan(wholeOldDb, wholeNewDb, driver.dialect, opts);
@@ -46,4 +46,5 @@ export declare const driverBase: {
46
46
  parseSqlNull: boolean;
47
47
  parseHexAsBuffer: boolean;
48
48
  };
49
+ createSaveChangeSetScript(changeSet: any, dbinfo: any, defaultCreator: any): any;
49
50
  };
package/lib/driverBase.js CHANGED
@@ -84,7 +84,7 @@ exports.driverBase = {
84
84
  },
85
85
  script(pool, sql, options) {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
- if (options === null || options === void 0 ? void 0 : options.useTransaction) {
87
+ if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
88
88
  runCommandOnDriver(pool, this, dmp => dmp.beginTransaction());
89
89
  }
90
90
  for (const sqlItem of (0, dbgate_query_splitter_1.splitQuery)(sql, this.getQuerySplitterOptions('script'))) {
@@ -92,13 +92,13 @@ exports.driverBase = {
92
92
  yield this.query(pool, sqlItem, { discardResult: true });
93
93
  }
94
94
  catch (err) {
95
- if (options === null || options === void 0 ? void 0 : options.useTransaction) {
95
+ if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
96
96
  runCommandOnDriver(pool, this, dmp => dmp.rollbackTransaction());
97
97
  }
98
98
  throw err;
99
99
  }
100
100
  }
101
- if (options === null || options === void 0 ? void 0 : options.useTransaction) {
101
+ if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
102
102
  runCommandOnDriver(pool, this, dmp => dmp.commitTransaction());
103
103
  }
104
104
  });
@@ -191,4 +191,7 @@ exports.driverBase = {
191
191
  parseSqlNull: true,
192
192
  parseHexAsBuffer: true,
193
193
  },
194
+ createSaveChangeSetScript(changeSet, dbinfo, defaultCreator) {
195
+ return defaultCreator(changeSet, dbinfo);
196
+ },
194
197
  };
@@ -125,6 +125,9 @@ function editorAddConstraint(table, constraint) {
125
125
  if (constraint.constraintType == 'primaryKey') {
126
126
  res.primaryKey = Object.assign({ pairingId: (0, v1_1.default)() }, constraint);
127
127
  }
128
+ if (constraint.constraintType == 'sortingKey') {
129
+ res.sortingKey = Object.assign({ pairingId: (0, v1_1.default)() }, constraint);
130
+ }
128
131
  if (constraint.constraintType == 'foreignKey') {
129
132
  res.foreignKeys = [
130
133
  ...(res.foreignKeys || []),
@@ -151,6 +154,9 @@ function editorModifyConstraint(table, constraint) {
151
154
  if (constraint.constraintType == 'primaryKey') {
152
155
  res.primaryKey = Object.assign(Object.assign({}, res.primaryKey), constraint);
153
156
  }
157
+ if (constraint.constraintType == 'sortingKey') {
158
+ res.sortingKey = Object.assign(Object.assign({}, res.sortingKey), constraint);
159
+ }
154
160
  if (constraint.constraintType == 'foreignKey') {
155
161
  res.foreignKeys = table.foreignKeys.map(fk => fk.pairingId == constraint.pairingId ? Object.assign(Object.assign({}, fk), constraint) : fk);
156
162
  }
@@ -168,6 +174,9 @@ function editorDeleteConstraint(table, constraint) {
168
174
  if (constraint.constraintType == 'primaryKey') {
169
175
  res.primaryKey = null;
170
176
  }
177
+ if (constraint.constraintType == 'sortingKey') {
178
+ res.sortingKey = null;
179
+ }
171
180
  if (constraint.constraintType == 'foreignKey') {
172
181
  res.foreignKeys = table.foreignKeys.filter(x => x.pairingId != constraint.pairingId);
173
182
  }
@@ -15,7 +15,8 @@ function addTableDependencies(db) {
15
15
  exports.addTableDependencies = addTableDependencies;
16
16
  function extendTableInfo(table) {
17
17
  return Object.assign(Object.assign({}, table), { objectTypeField: 'tables', columns: (table.columns || []).map(column => (Object.assign({ pureName: table.pureName, schemaName: table.schemaName }, column))), primaryKey: table.primaryKey
18
- ? Object.assign(Object.assign({}, table.primaryKey), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'primaryKey' }) : undefined, foreignKeys: (table.foreignKeys || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'foreignKey' }))), indexes: (table.indexes || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'index' }))), checks: (table.checks || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'check' }))), uniques: (table.uniques || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'unique' }))) });
18
+ ? Object.assign(Object.assign({}, table.primaryKey), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'primaryKey' }) : undefined, sortingKey: table.sortingKey
19
+ ? Object.assign(Object.assign({}, table.sortingKey), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'sortingKey' }) : undefined, foreignKeys: (table.foreignKeys || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'foreignKey' }))), indexes: (table.indexes || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'index' }))), checks: (table.checks || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'check' }))), uniques: (table.uniques || []).map(cnt => (Object.assign(Object.assign({}, cnt), { pureName: table.pureName, schemaName: table.schemaName, constraintType: 'unique' }))) });
19
20
  }
20
21
  exports.extendTableInfo = extendTableInfo;
21
22
  function fillDatabaseExtendedInfo(db) {
@@ -15,6 +15,7 @@ function prepareTableForImport(table) {
15
15
  res.checks = [];
16
16
  if (res.primaryKey)
17
17
  res.primaryKey.constraintName = null;
18
+ res.tableEngine = null;
18
19
  return res;
19
20
  }
20
21
  exports.prepareTableForImport = prepareTableForImport;
@@ -20,6 +20,7 @@ export interface TableInfoYaml {
20
20
  name: string;
21
21
  columns: ColumnInfoYaml[];
22
22
  primaryKey?: string[];
23
+ sortingKey?: string[];
23
24
  insertKey?: string[];
24
25
  insertOnly?: string[];
25
26
  data?: any[];
@@ -54,6 +54,9 @@ function tableInfoToYaml(table) {
54
54
  if (tableCopy.primaryKey && !tableCopy.primaryKey['_dumped']) {
55
55
  res.primaryKey = tableCopy.primaryKey.columns.map(x => x.columnName);
56
56
  }
57
+ if (tableCopy.sortingKey && !tableCopy.sortingKey['_dumped']) {
58
+ res.sortingKey = tableCopy.sortingKey.columns.map(x => x.columnName);
59
+ }
57
60
  // const foreignKeys = (tableCopy.foreignKeys || []).filter(x => !x['_dumped']).map(foreignKeyInfoToYaml);
58
61
  return res;
59
62
  }
@@ -89,6 +92,13 @@ function tableInfoFromYaml(table, allTables) {
89
92
  columns: table.primaryKey.map(columnName => ({ columnName })),
90
93
  };
91
94
  }
95
+ if (table.sortingKey) {
96
+ res.sortingKey = {
97
+ pureName: table.name,
98
+ constraintType: 'sortingKey',
99
+ columns: table.sortingKey.map(columnName => ({ columnName })),
100
+ };
101
+ }
92
102
  res.preloadedRows = table.data;
93
103
  res.preloadedRowsKey = table.insertKey;
94
104
  res.preloadedRowsInsertOnly = table.insertOnly;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.4.4",
2
+ "version": "5.4.5-alpha.3",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -25,14 +25,14 @@
25
25
  ],
26
26
  "devDependencies": {
27
27
  "@types/node": "^13.7.0",
28
- "dbgate-types": "^5.4.4",
28
+ "dbgate-types": "^5.4.5-alpha.3",
29
29
  "jest": "^24.9.0",
30
30
  "ts-jest": "^25.2.1",
31
31
  "typescript": "^4.4.3"
32
32
  },
33
33
  "dependencies": {
34
34
  "dbgate-query-splitter": "^4.10.3",
35
- "dbgate-sqltree": "^5.4.4",
35
+ "dbgate-sqltree": "^5.4.5-alpha.3",
36
36
  "debug": "^4.3.4",
37
37
  "json-stable-stringify": "^1.0.1",
38
38
  "lodash": "^4.17.21",