Skip to content

Commit

Permalink
HCK-8515: driver upgrade (#50)
Browse files Browse the repository at this point in the history
* feat: upgraded the driver, added extra logs on querying the labels step, cleaned up the redundant dependencies

* feat: catch possible errors and return the labels list only for successful DBs

* chore: original patch contents

* revert: downgrade to 4.4.11

* feat: added log about db version
  • Loading branch information
chulanovskyi-bs authored Oct 21, 2024
1 parent 936f081 commit c5501ab
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 120 deletions.
25 changes: 6 additions & 19 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const { dependencies, setDependencies } = require('./helpers/appDependencies');
const _ = require('lodash');
const applyToInstanceHelper = require('./helpers/applyToInstance');
let _;
const setAppDependencies = ({ lodash }) => (_ = lodash);

module.exports = {
generateContainerScript(data, logger, cb, app) {
setDependencies(app);
setAppDependencies(dependencies);
generateContainerScript(data, logger, cb) {
let { collections, relationships, jsonData } = data;
const dbVersion = data.modelData[0]?.dbVersion;
logger.clear();
Expand All @@ -24,7 +20,6 @@ module.exports = {
setTimeout(() => {
cb({ message: e.message, stack: e.stack });
}, 150);
return;
}
},

Expand Down Expand Up @@ -133,13 +128,12 @@ module.exports = {
},

applyToInstance(connectionInfo, logger, callback, app) {
setDependencies(app);
logger.clear();
logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys);
const sshService = app.require('@hackolade/ssh-service');

applyToInstanceHelper
.applyToInstance(connectionInfo, dependencies, logger, sshService)
.applyToInstance(connectionInfo, logger, sshService)
.then(result => {
callback(null, result);
})
Expand All @@ -149,11 +143,10 @@ module.exports = {
},

testConnection(connectionInfo, logger, callback, app) {
setDependencies(app);
logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys);
const sshService = app.require('@hackolade/ssh-service');

applyToInstanceHelper.testConnection(connectionInfo, dependencies, sshService).then(callback, err => {
applyToInstanceHelper.testConnection(connectionInfo, sshService).then(callback, err => {
logger.log('error', err, 'Neo4j test connection error');
callback({ ...err, type: 'simpleError' });
});
Expand Down Expand Up @@ -246,9 +239,7 @@ module.exports = {
parent,
relationship,
child,
bidirectional:
relationship?.customProperties?.biDirectional &&
child.GUID !== parent.GUID,
bidirectional: relationship?.customProperties?.biDirectional && child.GUID !== parent.GUID,
});
});
} else if (!hasRelationship[parent.GUID]) {
Expand Down Expand Up @@ -488,10 +479,7 @@ module.exports = {
if (entity.index) {
entity.index.forEach(index => {
if (index.key) {
const fields = this.findFields(
entity,
index.key.map(getId),
);
const fields = this.findFields(entity, index.key.map(getId));
if (fields.length) {
const indexScript = getIndex({
entity,
Expand Down Expand Up @@ -630,7 +618,6 @@ module.exports = {
const screen = s => `\`${s}\``;

const getProperty = (schema, field) => {
setAppDependencies(dependencies);
if (_.has(schema, `properties.${field}`)) {
return schema.properties[field];
} else if (_.has(schema, `allOf.${field}`)) {
Expand Down
10 changes: 0 additions & 10 deletions forward_engineering/helpers/appDependencies.js

This file was deleted.

6 changes: 2 additions & 4 deletions forward_engineering/helpers/applyToInstance.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const neo4jHelper = require('../../reverse_engineering/neo4jHelper');

const applyToInstanceHelper = {
async applyToInstance(connectionInfo, dependencies, logger, sshService) {
async applyToInstance(connectionInfo, logger, sshService) {
try {
logger.log(
'info',
Expand All @@ -11,7 +11,6 @@ const applyToInstanceHelper = {
'Neo4j script',
);

neo4jHelper.setDependencies(dependencies);
await neo4jHelper.connect(connectionInfo, () => Promise.resolve(), sshService);
const instanceSupportMultiDb = await neo4jHelper.supportsMultiDb();
const dbData = connectionInfo.containerData?.[0];
Expand Down Expand Up @@ -66,8 +65,7 @@ const applyToInstanceHelper = {
}
},

async testConnection(connectionInfo, dependencies, sshService) {
neo4jHelper.setDependencies(dependencies);
async testConnection(connectionInfo, sshService) {
await neo4jHelper.connect(connectionInfo, () => Promise.resolve(), sshService);
await neo4jHelper.close(sshService);
},
Expand Down
46 changes: 26 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
"description": "Hackolade plugin for Neo4j",
"disabled": false,
"dependencies": {
"async": "3.2.6",
"lodash": "4.17.21",
"neo4j-driver": "4.4.10"
"neo4j-driver": "4.4.11"
},
"lint-staged": {
"*.{js,json}": "prettier --write"
Expand Down Expand Up @@ -80,4 +81,4 @@
"prettier": "3.2.5",
"simple-git-hooks": "2.11.1"
}
}
}
61 changes: 30 additions & 31 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const { dependencies, setDependencies } = require('./appDependencies');
const async = require('async');
const _ = require('lodash');
const neo4j = require('./neo4jHelper');
const snippetsPath = '../snippets/';
const logHelper = require('./logHelper');
let _;
let async;

const snippets = {
'Cartesian 3D': require(snippetsPath + 'cartesian-3d.json'),
Expand All @@ -18,12 +17,14 @@ module.exports = {
connect: function (connectionInfo, logger, cb, app) {
const sshService = app.require('@hackolade/ssh-service');

initDependencies(app);

neo4j.connect(connectionInfo, checkConnection(logger), sshService).then(
() => {
logger.log('info', 'Successfully connected to the database instance', 'Connection');

neo4j.getRawDbVersion().then(dbVersion => {
logger.log('info', `Database version ${dbVersion}`);
});

cb();
},
error => {
Expand All @@ -45,7 +46,6 @@ module.exports = {
testConnection: function (connectionInfo, logger, cb, app) {
logInfo('Test connection', connectionInfo, logger);

initDependencies(app);
this.connect(
connectionInfo,
logger,
Expand All @@ -66,38 +66,43 @@ module.exports = {
},

getDbCollectionsNames: async function (connectionInfo, logger, cb, app) {
logInfo('Retrieving labels information', connectionInfo, logger);
const step = 'Retrieving labels information';

logInfo(step, connectionInfo, logger);
try {
const sshService = app.require('@hackolade/ssh-service');
initDependencies(app);
neo4j.setTimeOut(connectionInfo);

await neo4j.connect(connectionInfo, checkConnection(logger), sshService);
logger.log('info', 'Successfully connected to the database instance', 'Connection');

const dbVersion = await neo4j.getRawDbVersion();
logger.log('info', `Successfully connected to the database instance: ${dbVersion}`, 'Connection');

const isMultiDb = await neo4j.supportsMultiDb();
logger.log('info', `Multi database support: ${isMultiDb}`, step);

const databaseNames = await neo4j.getDatabaseName('graph.db', isMultiDb);
logger.log('info', 'Name of database successfully retrieved', 'Retrieving labels information');
const result = await Promise.all(
databaseNames.map(async name => {
return {
dbName: name,
dbCollections: await neo4j.getLabels(name, isMultiDb),
};
}),
);
logger.log('info', 'Labels successfully retrieved', 'Retrieving labels information');
logger.log('info', 'Information about labels successfully retrieved', 'Retrieving labels information');
cb(null, result);
logger.log('info', 'Database names are successfully retrieved', step);

const results = [];
for (let databaseName of databaseNames) {
logger.log('info', `Fetching the labels from ${databaseName}`, step);
results.push({
dbName: databaseName,
dbCollections: await neo4j.getLabels({ databaseName, isMultiDb, logger }),
});
}

logger.log('info', 'Labels are successfully retrieved', step);
cb(null, results);
} catch (error) {
logger.log(
'error',
{
message: error.step || 'Process of retrieving labels was interrupted by error',
error: prepareError(error),
},
'Retrieving labels information',
step,
);

const mappedError = {
Expand All @@ -122,7 +127,6 @@ module.exports = {
},

getDbCollectionsDataWrapped: async function (data, logger, cb, app) {
initDependencies(app);
neo4j.setTimeOut(data);
logger.log('info', data, 'Retrieving schema for chosen labels', data.hiddenKeys);

Expand All @@ -141,8 +145,10 @@ module.exports = {
logger.log('info', '', 'Start Reverse Engineering Neo4j');

const isMultiDb = await neo4j.supportsMultiDb();
const dbVersion = await neo4j.getDbVersion();
logger.log('info', `Database version: ${dbVersion}`);
const modelProps = {
dbVersion: await neo4j.getDbVersion(),
dbVersion,
};

async.map(
Expand Down Expand Up @@ -277,13 +283,6 @@ module.exports = {
},
};

const initDependencies = app => {
setDependencies(app);
_ = dependencies.lodash;
async = dependencies.async;
neo4j.setDependencies(dependencies);
};

const getSampleDocSize = (count, recordSamplingSettings) => {
if (recordSamplingSettings.active === 'absolute') {
return Number(recordSamplingSettings.absolute.value);
Expand Down
11 changes: 0 additions & 11 deletions reverse_engineering/appDependencies.js

This file was deleted.

Loading

0 comments on commit c5501ab

Please sign in to comment.