diff --git a/packages/tools/src/DatabaseAnalyser.ts b/packages/tools/src/DatabaseAnalyser.ts index d99c3198..8891777a 100644 --- a/packages/tools/src/DatabaseAnalyser.ts +++ b/packages/tools/src/DatabaseAnalyser.ts @@ -2,7 +2,7 @@ import { DatabaseInfo, DatabaseModification, EngineDriver } from 'dbgate-types'; import _sortBy from 'lodash/sortBy'; import _groupBy from 'lodash/groupBy'; import _pick from 'lodash/pick'; -import _ from 'lodash'; +import _compact from 'lodash/compact'; const fp_pick = arg => array => _pick(array, arg); export class DatabaseAnalyser { @@ -134,7 +134,7 @@ export class DatabaseAnalyser { return this.structure[objectTypeField] .filter(x => !items.find(y => x.objectId == y.objectId)) .map(x => ({ - oldName: _.pick(x, ['schemaName', 'pureName']), + oldName: _pick(x, ['schemaName', 'pureName']), objectId: x.objectId, action: 'remove', objectTypeField, @@ -175,7 +175,7 @@ export class DatabaseAnalyser { const action = obj ? { newName: { schemaName, pureName }, - oldName: _.pick(obj, ['schemaName', 'pureName']), + oldName: _pick(obj, ['schemaName', 'pureName']), action: 'change', objectTypeField: field, objectId, @@ -189,7 +189,7 @@ export class DatabaseAnalyser { res.push(action); } - return [..._.compact(res), ...this.getDeletedObjects(snapshot)]; + return [..._compact(res), ...this.getDeletedObjects(snapshot)]; } } diff --git a/packages/tools/src/SqlGenerator.ts b/packages/tools/src/SqlGenerator.ts index 7f25c6be..9d7ecfe1 100644 --- a/packages/tools/src/SqlGenerator.ts +++ b/packages/tools/src/SqlGenerator.ts @@ -7,7 +7,8 @@ import { TriggerInfo, ViewInfo, } from 'dbgate-types'; -import _ from 'lodash'; +import _flatten from 'lodash/flatten'; +import _uniqBy from 'lodash/uniqBy' import { SqlDumper } from './SqlDumper'; import { extendDatabaseInfo } from './structureTools'; @@ -122,9 +123,9 @@ export class SqlGenerator { createForeignKeys() { const fks = []; - if (this.options.createForeignKeys) fks.push(..._.flatten(this.tables.map(x => x.foreignKeys || []))); - if (this.options.createReferences) fks.push(..._.flatten(this.tables.map(x => x.dependencies || []))); - for (const fk of _.uniqBy(fks, 'constraintName')) { + if (this.options.createForeignKeys) fks.push(..._flatten(this.tables.map(x => x.foreignKeys || []))); + if (this.options.createReferences) fks.push(..._flatten(this.tables.map(x => x.dependencies || []))); + for (const fk of _uniqBy(fks, 'constraintName')) { this.dmp.createForeignKey(fk); if (this.checkDumper()) return; } @@ -152,7 +153,7 @@ export class SqlGenerator { } } if (this.options.createIndexes) { - for (const index of _.flatten(this.tables.map(x => x.indexes || []))) { + for (const index of _flatten(this.tables.map(x => x.indexes || []))) { this.dmp.createIndex(index); } } @@ -204,7 +205,7 @@ export class SqlGenerator { dropTables() { if (this.options.dropReferences) { - for (const fk of _.flatten(this.tables.map(x => x.dependencies || []))) { + for (const fk of _flatten(this.tables.map(x => x.dependencies || []))) { this.dmp.dropForeignKey(fk); } } diff --git a/packages/tools/src/settingsExtractors.ts b/packages/tools/src/settingsExtractors.ts index 843a4442..a5a9c0df 100644 --- a/packages/tools/src/settingsExtractors.ts +++ b/packages/tools/src/settingsExtractors.ts @@ -1,11 +1,12 @@ -import _ from 'lodash'; +import _isNaN from 'lodash/isNaN'; +import _isNumber from 'lodash/isNumber'; export function extractIntSettingsValue(settings, name, defaultValue, min = null, max = null) { const parsed = parseInt(settings[name]); - if (_.isNaN(parsed)) { + if (_isNaN(parsed)) { return defaultValue; } - if (_.isNumber(parsed)) { + if (_isNumber(parsed)) { if (min != null && parsed < min) return min; if (max != null && parsed > max) return max; return parsed; diff --git a/packages/tools/src/structureTools.ts b/packages/tools/src/structureTools.ts index 38d1c45e..6897090b 100644 --- a/packages/tools/src/structureTools.ts +++ b/packages/tools/src/structureTools.ts @@ -1,8 +1,8 @@ import { DatabaseInfo } from 'dbgate-types'; -import _ from 'lodash'; +import _flatten from 'lodash/flatten'; export function addTableDependencies(db: DatabaseInfo): DatabaseInfo { - const allForeignKeys = _.flatten(db.tables.map(x => x.foreignKeys || [])); + const allForeignKeys = _flatten(db.tables.map(x => x.foreignKeys || [])); return { ...db, tables: db.tables.map(table => ({