dbgate-tools 5.5.7-alpha.53 → 5.5.7-alpha.68

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.
@@ -117,5 +117,6 @@ export declare class SqlDumper implements AlterProcessor {
117
117
  dropSqlObject(obj: SqlObjectInfo): void;
118
118
  setTableOption(table: TableInfo, optionName: string, optionValue: string): void;
119
119
  setTableOptionCore(table: TableInfo, optionName: string, optionValue: string, formatString: string): void;
120
+ fillNewNotNullDefaults(col: ColumnInfo): void;
120
121
  fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
121
122
  }
package/lib/SqlDumper.js CHANGED
@@ -242,7 +242,8 @@ class SqlDumper {
242
242
  }
243
243
  }
244
244
  columnDefault(column) {
245
- if (column.defaultConstraint != null) {
245
+ var _a;
246
+ if (column.defaultConstraint != null && ((_a = this.dialect) === null || _a === void 0 ? void 0 : _a.namedDefaultConstraint)) {
246
247
  this.put(' ^constraint %i ^default %s ', column.defaultConstraint, column.defaultValue);
247
248
  }
248
249
  else {
@@ -583,7 +584,7 @@ class SqlDumper {
583
584
  if (autoinc) {
584
585
  this.allowIdentityInsert(newTable, true);
585
586
  }
586
- 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 }));
587
+ this.putCmd('^insert ^into %f (%,i) select %,i ^from %f', newTable, columnPairs.map(x => x.newcol.columnName), columnPairs.map(x => x.oldcol.columnName), Object.assign(Object.assign({}, oldTable), { pureName: tmpTable }));
587
588
  if (autoinc) {
588
589
  this.allowIdentityInsert(newTable, false);
589
590
  }
@@ -635,6 +636,11 @@ class SqlDumper {
635
636
  this.put('^alter ^table %f ', table);
636
637
  this.put(formatString, optionValue);
637
638
  }
639
+ fillNewNotNullDefaults(col) {
640
+ if (col.notNull && col.defaultValue != null) {
641
+ this.putCmd('^update %f ^set %i = %s ^where %i ^is ^null', col, col.columnName, col.defaultValue, col.columnName);
642
+ }
643
+ }
638
644
  fillPreloadedRows(table, oldRows, newRows, key, insertOnly, autoIncrementColumn) {
639
645
  let was = false;
640
646
  for (const row of newRows) {
package/lib/alterPlan.js CHANGED
@@ -253,6 +253,12 @@ class AlterPlan {
253
253
  this._testTableRecreate(op, 'createConstraint', obj => this._canCreateConstraint(obj), 'newObject') ||
254
254
  this._testTableRecreate(op, 'dropConstraint', obj => this._canDropConstraint(obj), 'oldObject') ||
255
255
  this._testTableRecreate(op, 'changeColumn', this.dialect.changeColumn, 'newObject') ||
256
+ // this._testTableRecreate(
257
+ // op,
258
+ // 'changeColumn',
259
+ // obj => this._canChangeAutoIncrement(obj, op as AlterOperation_ChangeColumn),
260
+ // 'newObject'
261
+ // ) ||
256
262
  this._testTableRecreate(op, 'renameColumn', true, 'object') || [op]);
257
263
  });
258
264
  return lodash_1.default.flatten(lists);
@@ -287,6 +293,12 @@ class AlterPlan {
287
293
  return this.dialect.dropCheck;
288
294
  return null;
289
295
  }
296
+ // _canChangeAutoIncrement(column: ColumnInfo, op: AlterOperation_ChangeColumn) {
297
+ // if (!!column.autoIncrement != !!op.oldObject.autoIncrement) {
298
+ // return this.dialect.changeAutoIncrement;
299
+ // }
300
+ // return null;
301
+ // }
290
302
  _testTableRecreate(op, operationType, isAllowed, objectField) {
291
303
  if (op.operationType == operationType) {
292
304
  if (lodash_1.default.isFunction(isAllowed)) {
@@ -299,7 +311,7 @@ class AlterPlan {
299
311
  }
300
312
  // console.log('*****************RECREATED NEEDED', op, operationType, isAllowed);
301
313
  // console.log(this.dialect);
302
- if (this.opts.noDropTable && !this.opts.allowTableRecreateWhenNoDrop) {
314
+ if (this.opts.noDropTable && !this.opts.allowTableRecreate) {
303
315
  // skip this operation, as it cannot be achieved
304
316
  return [];
305
317
  }
@@ -92,8 +92,8 @@ function computeTableDiffColumns(sourceTable, targetTable, opts, driver) {
92
92
  if (!driver)
93
93
  return [];
94
94
  return computeDiffRowsCore((sourceTable === null || sourceTable === void 0 ? void 0 : sourceTable.columns) || [], (targetTable === null || targetTable === void 0 ? void 0 : targetTable.columns) || [], (a, b) => (0, diffTools_1.testEqualColumns)(a, b, true, true, opts)).map(row => {
95
- var _a, _b, _c, _d, _e, _f;
96
- return (Object.assign(Object.assign({}, row), { sourceColumnName: (_a = row === null || row === void 0 ? void 0 : row.source) === null || _a === void 0 ? void 0 : _a.columnName, targetColumnName: (_b = row === null || row === void 0 ? void 0 : row.target) === null || _b === void 0 ? void 0 : _b.columnName, sourceDataType: (_c = row === null || row === void 0 ? void 0 : row.source) === null || _c === void 0 ? void 0 : _c.dataType, targetDataType: (_d = row === null || row === void 0 ? void 0 : row.target) === null || _d === void 0 ? void 0 : _d.dataType, sourceNotNull: (_e = row === null || row === void 0 ? void 0 : row.source) === null || _e === void 0 ? void 0 : _e.notNull, targetNotNull: (_f = row === null || row === void 0 ? void 0 : row.target) === null || _f === void 0 ? void 0 : _f.notNull }));
95
+ var _a, _b, _c, _d, _e, _f, _g, _h;
96
+ return (Object.assign(Object.assign({}, row), { sourceColumnName: (_a = row === null || row === void 0 ? void 0 : row.source) === null || _a === void 0 ? void 0 : _a.columnName, targetColumnName: (_b = row === null || row === void 0 ? void 0 : row.target) === null || _b === void 0 ? void 0 : _b.columnName, sourceDataType: (_c = row === null || row === void 0 ? void 0 : row.source) === null || _c === void 0 ? void 0 : _c.dataType, targetDataType: (_d = row === null || row === void 0 ? void 0 : row.target) === null || _d === void 0 ? void 0 : _d.dataType, sourceAutoIncrement: (_e = row === null || row === void 0 ? void 0 : row.source) === null || _e === void 0 ? void 0 : _e.autoIncrement, targetAutoIncrement: (_f = row === null || row === void 0 ? void 0 : row.target) === null || _f === void 0 ? void 0 : _f.autoIncrement, sourceNotNull: (_g = row === null || row === void 0 ? void 0 : row.source) === null || _g === void 0 ? void 0 : _g.notNull, targetNotNull: (_h = row === null || row === void 0 ? void 0 : row.target) === null || _h === void 0 ? void 0 : _h.notNull }));
97
97
  });
98
98
  }
99
99
  exports.computeTableDiffColumns = computeTableDiffColumns;
@@ -8,7 +8,7 @@ export interface DbDiffOptions {
8
8
  rightImplicitSchema?: string;
9
9
  ignoreConstraintNames?: boolean;
10
10
  noDropTable?: boolean;
11
- allowTableRecreateWhenNoDrop?: boolean;
11
+ allowTableRecreate?: boolean;
12
12
  deletedTablePrefix?: string;
13
13
  noDropColumn?: boolean;
14
14
  deletedColumnPrefix?: string;
package/lib/diffTools.js CHANGED
@@ -549,14 +549,22 @@ function createAlterDatabasePlan(oldDb, newDb, opts, wholeOldDb, wholeNewDb, dri
549
549
  }
550
550
  else {
551
551
  if (opts.deletedSqlObjectPrefix && hasDeletedPrefix(oldobj.pureName, opts, opts.deletedSqlObjectPrefix)) {
552
- plan.dropSqlObject(oldobj);
553
- plan.createSqlObject(newobj);
552
+ if (driver.dialect.renameSqlObject && testEqualSqlObjects(oldobj, newobj, opts)) {
553
+ plan.renameSqlObject(oldobj, newobj.pureName);
554
+ }
555
+ else {
556
+ plan.dropSqlObject(oldobj);
557
+ plan.createSqlObject(newobj);
558
+ }
554
559
  }
555
560
  else if (!testEqualSqlObjects(oldobj, newobj, opts)) {
556
561
  plan.recreates.sqlObjects += 1;
557
562
  plan.dropSqlObject(oldobj);
558
563
  plan.createSqlObject(newobj);
559
564
  }
565
+ else if (!testEqualFullNames(oldobj, newobj, opts)) {
566
+ plan.renameSqlObject(oldobj, newobj.pureName);
567
+ }
560
568
  }
561
569
  }
562
570
  }
@@ -41,6 +41,9 @@ function extractShellApiFunctionName(functionName) {
41
41
  }
42
42
  exports.extractShellApiFunctionName = extractShellApiFunctionName;
43
43
  function findEngineDriver(connection, extensions) {
44
+ if (!extensions) {
45
+ return null;
46
+ }
44
47
  if ((0, isString_1.default)(connection)) {
45
48
  return extensions.drivers.find(x => x.engine == connection);
46
49
  }
@@ -96,7 +96,7 @@ function skipNamesInStructureByRegex(db, regex) {
96
96
  if (!db) {
97
97
  return db;
98
98
  }
99
- return Object.assign(Object.assign({}, db), { tables: (db.tables || []).filter(tbl => !regex.test(tbl.pureName)), views: (db.views || []).filter(tbl => !regex.test(tbl.pureName)), collections: (db.collections || []).filter(tbl => !regex.test(tbl.pureName)), matviews: (db.matviews || []).filter(tbl => !regex.test(tbl.pureName)), procedures: (db.procedures || []).filter(tbl => !regex.test(tbl.pureName)), functions: (db.functions || []).filter(tbl => !regex.test(tbl.pureName)), triggers: (db.triggers || []).filter(tbl => !regex.test(tbl.pureName)) });
99
+ return Object.assign(Object.assign({}, db), { tables: (db.tables || []).filter(x => !regex.test(x.pureName)), views: (db.views || []).filter(x => !regex.test(x.pureName)), collections: (db.collections || []).filter(x => !regex.test(x.pureName)), matviews: (db.matviews || []).filter(x => !regex.test(x.pureName)), procedures: (db.procedures || []).filter(x => !regex.test(x.pureName)), functions: (db.functions || []).filter(x => !regex.test(x.pureName)), triggers: (db.triggers || []).filter(x => !regex.test(x.pureName)) });
100
100
  }
101
101
  exports.skipNamesInStructureByRegex = skipNamesInStructureByRegex;
102
102
  function detectChangesInPreloadedRows(oldTable, newTable) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.5.7-alpha.53",
2
+ "version": "5.5.7-alpha.68",
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.5.7-alpha.53",
28
+ "dbgate-types": "^5.5.7-alpha.68",
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.11.2",
35
- "dbgate-sqltree": "^5.5.7-alpha.53",
35
+ "dbgate-sqltree": "^5.5.7-alpha.68",
36
36
  "debug": "^4.3.4",
37
37
  "json-stable-stringify": "^1.0.1",
38
38
  "lodash": "^4.17.21",