dbgate-tools 4.4.3 → 4.5.1
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/lib/SqlDumper.d.ts +1 -1
- package/lib/SqlDumper.js +2 -2
- package/lib/alterPlan.d.ts +2 -1
- package/lib/alterPlan.js +3 -2
- package/lib/database-info-alter-processor.d.ts +1 -1
- package/lib/database-info-alter-processor.js +2 -1
- package/lib/diffTools.js +1 -1
- package/lib/driverBase.d.ts +4 -0
- package/lib/driverBase.js +7 -0
- package/lib/preloadedRowsTools.js +2 -2
- package/lib/yamlModelConv.d.ts +2 -0
- package/lib/yamlModelConv.js +2 -1
- package/package.json +3 -3
package/lib/SqlDumper.d.ts
CHANGED
|
@@ -101,5 +101,5 @@ export declare class SqlDumper implements AlterProcessor {
|
|
|
101
101
|
createSqlObject(obj: SqlObjectInfo): void;
|
|
102
102
|
getSqlObjectSqlName(ojectTypeField: string): "PROCEDURE" | "VIEW" | "FUNCTION" | "TRIGGER" | "MATERIALIZED VIEW";
|
|
103
103
|
dropSqlObject(obj: SqlObjectInfo): void;
|
|
104
|
-
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[]): void;
|
|
104
|
+
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]): void;
|
|
105
105
|
}
|
package/lib/SqlDumper.js
CHANGED
|
@@ -532,7 +532,7 @@ class SqlDumper {
|
|
|
532
532
|
dropSqlObject(obj) {
|
|
533
533
|
this.putCmd('^drop %s %f', this.getSqlObjectSqlName(obj.objectTypeField), obj);
|
|
534
534
|
}
|
|
535
|
-
fillPreloadedRows(table, oldRows, newRows, key) {
|
|
535
|
+
fillPreloadedRows(table, oldRows, newRows, key, insertOnly) {
|
|
536
536
|
let was = false;
|
|
537
537
|
for (const row of newRows) {
|
|
538
538
|
const old = oldRows === null || oldRows === void 0 ? void 0 : oldRows.find(r => key.every(col => r[col] == row[col]));
|
|
@@ -540,7 +540,7 @@ class SqlDumper {
|
|
|
540
540
|
if (old) {
|
|
541
541
|
const updated = [];
|
|
542
542
|
for (const col of rowKeys) {
|
|
543
|
-
if (row[col] != old[col]) {
|
|
543
|
+
if (row[col] != old[col] && !(insertOnly === null || insertOnly === void 0 ? void 0 : insertOnly.includes(col))) {
|
|
544
544
|
updated.push(col);
|
|
545
545
|
}
|
|
546
546
|
}
|
package/lib/alterPlan.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ interface AlterOperation_FillPreloadedRows {
|
|
|
68
68
|
oldRows: any[];
|
|
69
69
|
newRows: any[];
|
|
70
70
|
key: string[];
|
|
71
|
+
insertOnly: string[];
|
|
71
72
|
}
|
|
72
73
|
declare 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;
|
|
73
74
|
export declare class AlterPlan {
|
|
@@ -96,7 +97,7 @@ export declare class AlterPlan {
|
|
|
96
97
|
renameColumn(column: ColumnInfo, newName: string): void;
|
|
97
98
|
renameConstraint(constraint: ConstraintInfo, newName: string): void;
|
|
98
99
|
recreateTable(table: TableInfo, operations: AlterOperation[]): void;
|
|
99
|
-
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[]): void;
|
|
100
|
+
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]): void;
|
|
100
101
|
run(processor: AlterProcessor): void;
|
|
101
102
|
_getDependendColumnConstraints(column: ColumnInfo, dependencyDefinition: any): import("dbgate-types/dbinfo").PrimaryKeyInfo[];
|
|
102
103
|
_addLogicalDependencies(): AlterOperation[];
|
package/lib/alterPlan.js
CHANGED
|
@@ -112,13 +112,14 @@ class AlterPlan {
|
|
|
112
112
|
});
|
|
113
113
|
this.recreates.tables += 1;
|
|
114
114
|
}
|
|
115
|
-
fillPreloadedRows(table, oldRows, newRows, key) {
|
|
115
|
+
fillPreloadedRows(table, oldRows, newRows, key, insertOnly) {
|
|
116
116
|
this.operations.push({
|
|
117
117
|
operationType: 'fillPreloadedRows',
|
|
118
118
|
table,
|
|
119
119
|
oldRows,
|
|
120
120
|
newRows,
|
|
121
121
|
key,
|
|
122
|
+
insertOnly,
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
125
|
run(processor) {
|
|
@@ -407,7 +408,7 @@ function runAlterOperation(op, processor) {
|
|
|
407
408
|
processor.dropSqlObject(op.oldObject);
|
|
408
409
|
break;
|
|
409
410
|
case 'fillPreloadedRows':
|
|
410
|
-
processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key);
|
|
411
|
+
processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key, op.insertOnly);
|
|
411
412
|
break;
|
|
412
413
|
case 'recreateTable':
|
|
413
414
|
{
|
|
@@ -16,5 +16,5 @@ export declare class DatabaseInfoAlterProcessor {
|
|
|
16
16
|
renameColumn(column: ColumnInfo, newName: string): void;
|
|
17
17
|
renameConstraint(constraint: ConstraintInfo, newName: string): void;
|
|
18
18
|
recreateTable(oldTable: TableInfo, newTable: TableInfo): void;
|
|
19
|
-
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[]): void;
|
|
19
|
+
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]): void;
|
|
20
20
|
}
|
|
@@ -93,10 +93,11 @@ class DatabaseInfoAlterProcessor {
|
|
|
93
93
|
recreateTable(oldTable, newTable) {
|
|
94
94
|
throw new Error('recreateTable not implemented for DatabaseInfoAlterProcessor');
|
|
95
95
|
}
|
|
96
|
-
fillPreloadedRows(table, oldRows, newRows, key) {
|
|
96
|
+
fillPreloadedRows(table, oldRows, newRows, key, insertOnly) {
|
|
97
97
|
const tableInfo = this.db.tables.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName);
|
|
98
98
|
tableInfo.preloadedRows = newRows;
|
|
99
99
|
tableInfo.preloadedRowsKey = key;
|
|
100
|
+
tableInfo.preloadedRowsInsertOnly = insertOnly;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
exports.DatabaseInfoAlterProcessor = DatabaseInfoAlterProcessor;
|
package/lib/diffTools.js
CHANGED
|
@@ -238,7 +238,7 @@ function planTablePreload(plan, oldTable, newTable) {
|
|
|
238
238
|
var _a, _b, _c;
|
|
239
239
|
const key = newTable.preloadedRowsKey || ((_b = (_a = newTable.primaryKey) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(x => x.columnName));
|
|
240
240
|
if (((_c = newTable.preloadedRows) === null || _c === void 0 ? void 0 : _c.length) > 0 && (key === null || key === void 0 ? void 0 : key.length) > 0) {
|
|
241
|
-
plan.fillPreloadedRows(newTable, oldTable === null || oldTable === void 0 ? void 0 : oldTable.preloadedRows, newTable.preloadedRows, key);
|
|
241
|
+
plan.fillPreloadedRows(newTable, oldTable === null || oldTable === void 0 ? void 0 : oldTable.preloadedRows, newTable.preloadedRows, key, newTable.preloadedRowsInsertOnly);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
function planAlterTable(plan, oldTable, newTable, opts) {
|
package/lib/driverBase.d.ts
CHANGED
|
@@ -16,4 +16,8 @@ export declare const driverBase: {
|
|
|
16
16
|
analyseIncremental(pool: any, structure: any, version: any): Promise<any>;
|
|
17
17
|
createDumper(options?: any): any;
|
|
18
18
|
script(pool: any, sql: any): Promise<void>;
|
|
19
|
+
getNewObjectTemplates(): {
|
|
20
|
+
label: string;
|
|
21
|
+
sql: string;
|
|
22
|
+
}[];
|
|
19
23
|
};
|
package/lib/driverBase.js
CHANGED
|
@@ -57,4 +57,11 @@ exports.driverBase = {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
|
+
getNewObjectTemplates() {
|
|
61
|
+
var _a;
|
|
62
|
+
if (!((_a = this.dialect) === null || _a === void 0 ? void 0 : _a.nosql)) {
|
|
63
|
+
return [{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }];
|
|
64
|
+
}
|
|
65
|
+
return [];
|
|
66
|
+
},
|
|
60
67
|
};
|
|
@@ -21,7 +21,7 @@ function enrichWithPreloadedRows(dbModel, dbTarget, conn, driver) {
|
|
|
21
21
|
const repl = {};
|
|
22
22
|
for (const tableTarget of dbTarget.tables) {
|
|
23
23
|
const tableModel = dbModel.tables.find(x => x.pairingId == tableTarget.pairingId);
|
|
24
|
-
if ((((_a = tableModel.preloadedRows) === null || _a === void 0 ? void 0 : _a.length) || 0) == 0)
|
|
24
|
+
if ((((_a = tableModel === null || tableModel === void 0 ? void 0 : tableModel.preloadedRows) === null || _a === void 0 ? void 0 : _a.length) || 0) == 0)
|
|
25
25
|
continue;
|
|
26
26
|
const keyColumns = tableModel.preloadedRowsKey || ((_c = (_b = tableModel.primaryKey) === null || _b === void 0 ? void 0 : _b.columns) === null || _c === void 0 ? void 0 : _c.map(x => x.columnName));
|
|
27
27
|
if (((keyColumns === null || keyColumns === void 0 ? void 0 : keyColumns.length) || 0) == 0)
|
|
@@ -32,7 +32,7 @@ function enrichWithPreloadedRows(dbModel, dbTarget, conn, driver) {
|
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
dmp.put('^select * ^from %f ^where', tableTarget);
|
|
35
|
-
dmp.putCollection(' ^or ',
|
|
35
|
+
dmp.putCollection(' ^or ', tableModel.preloadedRows, row => {
|
|
36
36
|
dmp.put('(');
|
|
37
37
|
dmp.putCollection(' ^and ', keyColumns, col => dmp.put('%i=%v', col, row[col]));
|
|
38
38
|
dmp.put(')');
|
package/lib/yamlModelConv.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export interface ColumnInfoYaml {
|
|
|
3
3
|
name: string;
|
|
4
4
|
type: string;
|
|
5
5
|
notNull?: boolean;
|
|
6
|
+
length?: number;
|
|
6
7
|
autoIncrement?: boolean;
|
|
7
8
|
references?: string;
|
|
8
9
|
primaryKey?: boolean;
|
|
@@ -17,6 +18,7 @@ export interface TableInfoYaml {
|
|
|
17
18
|
columns: ColumnInfoYaml[];
|
|
18
19
|
primaryKey?: string[];
|
|
19
20
|
insertKey?: string[];
|
|
21
|
+
insertOnly?: string[];
|
|
20
22
|
data?: any[];
|
|
21
23
|
}
|
|
22
24
|
export interface ForeignKeyInfoYaml {
|
package/lib/yamlModelConv.js
CHANGED
|
@@ -36,7 +36,7 @@ function columnInfoFromYaml(column, table) {
|
|
|
36
36
|
const res = {
|
|
37
37
|
pureName: table.name,
|
|
38
38
|
columnName: column.name,
|
|
39
|
-
dataType: column.type,
|
|
39
|
+
dataType: column.length ? `${column.type}(${column.length})` : column.type,
|
|
40
40
|
autoIncrement: column.autoIncrement,
|
|
41
41
|
notNull: column.notNull || (table.primaryKey && table.primaryKey.includes(column.name)),
|
|
42
42
|
};
|
|
@@ -87,6 +87,7 @@ function tableInfoFromYaml(table, allTables) {
|
|
|
87
87
|
}
|
|
88
88
|
res.preloadedRows = table.data;
|
|
89
89
|
res.preloadedRowsKey = table.insertKey;
|
|
90
|
+
res.preloadedRowsInsertOnly = table.insertOnly;
|
|
90
91
|
return res;
|
|
91
92
|
}
|
|
92
93
|
exports.tableInfoFromYaml = tableInfoFromYaml;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.
|
|
2
|
+
"version": "4.5.1",
|
|
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": "^4.
|
|
28
|
+
"dbgate-types": "^4.5.1",
|
|
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
|
"lodash": "^4.17.21",
|
|
35
|
-
"dbgate-query-splitter": "^4.
|
|
35
|
+
"dbgate-query-splitter": "^4.5.1",
|
|
36
36
|
"uuid": "^3.4.0"
|
|
37
37
|
}
|
|
38
38
|
}
|