dbgate-tools 4.4.5-alpha.1 → 4.6.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.
|
@@ -39,18 +39,18 @@ function createBulkInsertStreamBase(driver, stream, pool, name, options) {
|
|
|
39
39
|
// console.log('ANALYSING', name, structure);
|
|
40
40
|
if (structure && options.dropIfExists) {
|
|
41
41
|
console.log(`Dropping table ${fullNameQuoted}`);
|
|
42
|
-
yield driver.
|
|
42
|
+
yield driver.script(pool, `DROP TABLE ${fullNameQuoted}`);
|
|
43
43
|
}
|
|
44
44
|
if (options.createIfNotExists && (!structure || options.dropIfExists)) {
|
|
45
45
|
console.log(`Creating table ${fullNameQuoted}`);
|
|
46
46
|
const dmp = driver.createDumper();
|
|
47
47
|
dmp.createTable((0, tableTransforms_1.prepareTableForImport)(Object.assign(Object.assign({}, writable.structure), name)));
|
|
48
48
|
console.log(dmp.s);
|
|
49
|
-
yield driver.
|
|
49
|
+
yield driver.script(pool, dmp.s);
|
|
50
50
|
structure = yield driver.analyseSingleTable(pool, name);
|
|
51
51
|
}
|
|
52
52
|
if (options.truncate) {
|
|
53
|
-
yield driver.
|
|
53
|
+
yield driver.script(pool, `TRUNCATE TABLE ${fullNameQuoted}`);
|
|
54
54
|
}
|
|
55
55
|
writable.columnNames = (0, intersection_1.default)(structure.columns.map(x => x.columnName), writable.structure.columns.map(x => x.columnName));
|
|
56
56
|
});
|
package/lib/structureTools.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { DatabaseInfo, TableInfo } from 'dbgate-types';
|
|
1
|
+
import { DatabaseInfo, TableInfo, ApplicationDefinition } from 'dbgate-types';
|
|
2
2
|
export declare function addTableDependencies(db: DatabaseInfo): DatabaseInfo;
|
|
3
3
|
export declare function extendTableInfo(table: TableInfo): TableInfo;
|
|
4
4
|
export declare function extendDatabaseInfo(db: DatabaseInfo): DatabaseInfo;
|
|
5
|
+
export declare function extendDatabaseInfoFromApps(db: DatabaseInfo, apps: ApplicationDefinition[]): DatabaseInfo;
|
|
6
|
+
export declare function isTableColumnUnique(table: TableInfo, column: string): boolean;
|
package/lib/structureTools.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extendDatabaseInfo = exports.extendTableInfo = exports.addTableDependencies = void 0;
|
|
6
|
+
exports.isTableColumnUnique = exports.extendDatabaseInfoFromApps = exports.extendDatabaseInfo = exports.extendTableInfo = exports.addTableDependencies = void 0;
|
|
7
7
|
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
8
8
|
function addTableDependencies(db) {
|
|
9
9
|
const allForeignKeys = (0, flatten_1.default)(db.tables.map(x => x.foreignKeys || []));
|
|
@@ -22,3 +22,26 @@ function extendDatabaseInfo(db) {
|
|
|
22
22
|
return fillDatabaseExtendedInfo(addTableDependencies(db));
|
|
23
23
|
}
|
|
24
24
|
exports.extendDatabaseInfo = extendDatabaseInfo;
|
|
25
|
+
function extendDatabaseInfoFromApps(db, apps) {
|
|
26
|
+
if (!db || !apps)
|
|
27
|
+
return db;
|
|
28
|
+
const dbExt = Object.assign(Object.assign({}, db), { tables: db.tables.map(table => (Object.assign(Object.assign({}, table), { foreignKeys: [
|
|
29
|
+
...(table.foreignKeys || []),
|
|
30
|
+
...(0, flatten_1.default)(apps.map(app => app.virtualReferences || []))
|
|
31
|
+
.filter(fk => fk.pureName == table.pureName && fk.schemaName == table.schemaName)
|
|
32
|
+
.map(fk => (Object.assign(Object.assign({}, fk), { constraintType: 'foreignKey', isVirtual: true }))),
|
|
33
|
+
] }))) });
|
|
34
|
+
return addTableDependencies(dbExt);
|
|
35
|
+
}
|
|
36
|
+
exports.extendDatabaseInfoFromApps = extendDatabaseInfoFromApps;
|
|
37
|
+
function isTableColumnUnique(table, column) {
|
|
38
|
+
if (table.primaryKey && table.primaryKey.columns.length == 1 && table.primaryKey.columns[0].columnName == column) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
const uqs = [...(table.uniques || []), ...(table.indexes || []).filter(x => x.isUnique)];
|
|
42
|
+
if (uqs.find(uq => uq.columns.length == 1 && uq.columns[0].columnName == column)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
exports.isTableColumnUnique = isTableColumnUnique;
|
package/lib/tableTransforms.js
CHANGED
|
@@ -8,6 +8,9 @@ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
|
8
8
|
function prepareTableForImport(table) {
|
|
9
9
|
const res = (0, cloneDeep_1.default)(table);
|
|
10
10
|
res.foreignKeys = [];
|
|
11
|
+
res.indexes = [];
|
|
12
|
+
res.uniques = [];
|
|
13
|
+
res.checks = [];
|
|
11
14
|
if (res.primaryKey)
|
|
12
15
|
res.primaryKey.constraintName = null;
|
|
13
16
|
return res;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.
|
|
2
|
+
"version": "4.6.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.6.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.6.1",
|
|
36
36
|
"uuid": "^3.4.0"
|
|
37
37
|
}
|
|
38
38
|
}
|