From f0610e2e87657fd4353905c098709fb102eb7989 Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus Date: Thu, 28 Oct 2021 14:42:54 +0300 Subject: [PATCH 1/6] Added lost function argument mode --- properties_pane/container_level/containerLevelConfig.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/properties_pane/container_level/containerLevelConfig.json b/properties_pane/container_level/containerLevelConfig.json index 978983c..af9bd66 100644 --- a/properties_pane/container_level/containerLevelConfig.json +++ b/properties_pane/container_level/containerLevelConfig.json @@ -175,6 +175,7 @@ making sure that you maintain a proper JSON format. "defaultValue": "IN", "options": [ "IN", + "OUT", "INOUT", "VARIADIC" ] @@ -400,6 +401,7 @@ making sure that you maintain a proper JSON format. "defaultValue": "IN", "options": [ "IN", + "OUT", "INOUT", "VARIADIC" ] From d6783d418f2d24f68100d10753f75cc95127b53c Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus Date: Thu, 28 Oct 2021 16:40:38 +0300 Subject: [PATCH 2/6] consfigs: fixed fieldKeyword for function definition --- forward_engineering/helpers/functionHelper.js | 2 +- properties_pane/container_level/containerLevelConfig.json | 2 +- reverse_engineering/helpers/postgresHelpers/functionHelper.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/forward_engineering/helpers/functionHelper.js b/forward_engineering/helpers/functionHelper.js index b44ad9e..8c01029 100644 --- a/forward_engineering/helpers/functionHelper.js +++ b/forward_engineering/helpers/functionHelper.js @@ -10,7 +10,7 @@ module.exports = ({ _, templates, assignTemplates, getFunctionArguments, getName returnType: udf.functionReturnsSetOf ? `SETOF ${udf.functionReturnType}` : udf.functionReturnType, language: udf.functionLanguage, properties: getProperties(udf), - definition: udf.functionDefinition, + definition: udf.functionBody, }); }).join('\n'); }; diff --git a/properties_pane/container_level/containerLevelConfig.json b/properties_pane/container_level/containerLevelConfig.json index af9bd66..f8f8604 100644 --- a/properties_pane/container_level/containerLevelConfig.json +++ b/properties_pane/container_level/containerLevelConfig.json @@ -227,7 +227,7 @@ making sure that you maintain a proper JSON format. }, { "propertyName": "Definition", - "propertyKeyword": "functionDefinition", + "propertyKeyword": "functionBody", "propertyTooltip": "A string constant defining the function; the meaning depends on the language. It can be an internal function name, the path to an object file, an SQL command, or text in a procedural language.", "propertyType": "details", "template": "textarea", diff --git a/reverse_engineering/helpers/postgresHelpers/functionHelper.js b/reverse_engineering/helpers/postgresHelpers/functionHelper.js index 32357a0..ed4adf2 100644 --- a/reverse_engineering/helpers/postgresHelpers/functionHelper.js +++ b/reverse_engineering/helpers/postgresHelpers/functionHelper.js @@ -66,7 +66,7 @@ const mapFunctionData = (functionData, functionArgs, additionalData) => { functionReturnsSetOf: additionalData?.returns_set, functionReturnType: functionData.return_data_type, functionLanguage: _.toLower(functionData.external_language), - functionDefinition: functionData.routine_definition, + functionBody: functionData.routine_definition, functionWindow: additionalData.kind === 'w', functionVolatility: getVolatility(additionalData?.volatility), functionLeakProof: additionalData?.leak_proof, From 20afa58454845586b3770c5865f3945758596d77 Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus Date: Fri, 29 Oct 2021 10:11:02 +0300 Subject: [PATCH 3/6] RE: fixed NULL in model properties --- reverse_engineering/helpers/postgresService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reverse_engineering/helpers/postgresService.js b/reverse_engineering/helpers/postgresService.js index 22190cb..0caed56 100644 --- a/reverse_engineering/helpers/postgresService.js +++ b/reverse_engineering/helpers/postgresService.js @@ -130,12 +130,12 @@ module.exports = { const encoding = (await db.queryTolerant(queryConstants.GET_DB_ENCODING, [], true))?.server_encoding; const LC_COLLATE = (await db.queryTolerant(queryConstants.GET_DB_COLLATE_NAME, [], true))?.default_collate_name; - return { + return clearEmptyPropertiesInObject({ database_name, encoding, LC_COLLATE, LC_CTYPE: LC_COLLATE, - }; + }); }, async retrieveEntitiesData(schemaName, entitiesNames, recordSamplingSettings) { From 70ea1ea1f7789a7b12f4f6c441816c6c6f6c7e6b Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus Date: Fri, 29 Oct 2021 11:51:56 +0300 Subject: [PATCH 4/6] Added adapter to fix rename functionDefinition property to functionBody --- adapter/0.1.1.json | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 adapter/0.1.1.json diff --git a/adapter/0.1.1.json b/adapter/0.1.1.json new file mode 100644 index 0000000..3064cec --- /dev/null +++ b/adapter/0.1.1.json @@ -0,0 +1,54 @@ +/** + * Copyright © 2016-2018 by IntegrIT S.A. dba Hackolade. All rights reserved. + * + * The copyright to the computer software herein is the property of IntegrIT S.A. + * The software may be used and/or copied only with the written permission of + * IntegrIT S.A. or in accordance with the terms and conditions stipulated in + * the agreement/contract under which the software has been supplied. + * + * { + * "add": { + * "entity": [], + * "container": [], + * "model": [], + * "view": [], + * "field": { + * "": [] + * } + * }, + * "remove": { + * "entity": [], + * "container": [], + * "model": [], + * "view": [], + * "field": { + * "": [] + * } + * }, + * "modify": { + * "entity": [ + * { + * "from": { }, + * "to": { } + * } + * ], + * "container": [], + * "model": [], + * "view": [], + * "field": [] + * }, + * } + */ +{ + "modify": { + "container": [ + [ + "renamePropertiesInArrayElements", + "UDFs", + { + "functionDefinition": "functionBody" + } + ] + ] + } +} \ No newline at end of file From 13339358d6a2e4beddfff01dec915fb70a1603a3 Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus Date: Fri, 29 Oct 2021 13:29:56 +0300 Subject: [PATCH 5/6] FE: changed string quoting --- forward_engineering/config.json | 1 + forward_engineering/configs/templates.js | 14 +++++++------- forward_engineering/ddlProvider.js | 2 +- .../helpers/columnDefinitionHelper.js | 8 +++----- forward_engineering/helpers/general.js | 8 +------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/forward_engineering/config.json b/forward_engineering/config.json index ccbba7f..e21b647 100644 --- a/forward_engineering/config.json +++ b/forward_engineering/config.json @@ -2,6 +2,7 @@ "type": "ddl", "ddlType": "plugin", "namePrefix": "PostgreSQL", + "mode": "pgsql", "level": { "container": true, "entity": true, diff --git a/forward_engineering/configs/templates.js b/forward_engineering/configs/templates.js index 6646bc5..0c123c8 100644 --- a/forward_engineering/configs/templates.js +++ b/forward_engineering/configs/templates.js @@ -1,14 +1,14 @@ module.exports = { createDatabase: 'CREATE DATABASE ${name}${template}${encoding}${locale}${collate}${characterClassification}${tablespace};\n', - createSchema: 'CREATE SCHEMA${ifNotExist} ${name};\nSET search_path TO ${name};\n${comment}\n', + createSchema: 'CREATE SCHEMA${ifNotExist} ${name};\nSET search_path TO ${name};\n\n${comment}\n', comment: 'COMMENT ON ${object} ${objectName} IS ${comment};\n', createTable: 'CREATE${temporary} TABLE${ifNotExist} ${name} (\n' + '${columnDefinitions}${keyConstraints}${checkConstraints}${foreignKeyConstraints}\n' + - ')${options};\n${comment}${columnDescriptions}', + ')${options};\n\n${comment}${columnDescriptions}', columnDefinition: '${name} ${type}${collation}${primaryKey}${uniqueKey}${defaultValue}${notNull}', @@ -26,7 +26,7 @@ module.exports = { ' ON${only} ${tableName}${using}${keys}${options};\n\n', createView: - 'CREATE${orReplace}${temporary} VIEW ${name}${withOptions}\nAS ${selectStatement}${checkOption};\n${comment}\n', + 'CREATE${orReplace}${temporary} VIEW ${name}${withOptions}\nAS ${selectStatement}${checkOption};\n\n${comment}\n', viewSelectStatement: 'SELECT ${keys}\n\tFROM ${tableName}', @@ -43,8 +43,8 @@ module.exports = { '\tLANGUAGE ${language}\n' + 'AS $BODY$\n${body}\n$BODY$;\n', - createCompositeType: 'CREATE TYPE ${name} AS (\n\t${columnDefinitions}\n);\n${comment}', - createEnumType: 'CREATE TYPE ${name} AS ENUM (${values});\n${comment}', - createRangeType: 'CREATE TYPE ${name} AS RANGE (\n\tSUBTYPE=${subtype}${options}\n);\n${comment}', - createDomainType: 'CREATE DOMAIN ${name} AS ${underlyingType}${notNull}${collate}${default}${constraints};\n${comment}' + createCompositeType: 'CREATE TYPE ${name} AS (\n\t${columnDefinitions}\n);\n\n${comment}', + createEnumType: 'CREATE TYPE ${name} AS ENUM (${values});\n\n${comment}', + createRangeType: 'CREATE TYPE ${name} AS RANGE (\n\tSUBTYPE=${subtype}${options}\n);\n\n${comment}', + createDomainType: 'CREATE DOMAIN ${name} AS ${underlyingType}${notNull}${collate}${default}${constraints};\n\n${comment}' }; diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index 631ed28..35c215e 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -82,7 +82,7 @@ module.exports = (baseProvider, options, app) => { assignTemplates, templates, commentIfDeactivated, - getNamePrefixedWithSchemaName, + wrapInQuotes, wrapComment, }); diff --git a/forward_engineering/helpers/columnDefinitionHelper.js b/forward_engineering/helpers/columnDefinitionHelper.js index 3df43e1..9460317 100644 --- a/forward_engineering/helpers/columnDefinitionHelper.js +++ b/forward_engineering/helpers/columnDefinitionHelper.js @@ -4,8 +4,8 @@ module.exports = ({ assignTemplates, templates, commentIfDeactivated, - getNamePrefixedWithSchemaName, wrapComment, + wrapInQuotes }) => { const addLength = (type, length) => { return `${type}(${length})`; @@ -60,12 +60,10 @@ module.exports = ({ const isString = type => ['char', 'varchar', 'text', 'bit', 'varbit'].includes(type); const isDateTime = type => ['date', 'time', 'timestamp', 'interval'].includes(type); - const escapeQuotes = str => _.trim(str).replace(/(\')+/g, "'$1"); - const decorateDefault = (type, defaultValue) => { const constantsValues = ['current_timestamp', 'null']; if ((isString(type) || isDateTime(type)) && !constantsValues.includes(_.toLower(defaultValue))) { - return wrap(escapeQuotes(defaultValue), "'", "'"); + return wrap(defaultValue, "$$", "$$"); } else { return defaultValue; } @@ -77,7 +75,7 @@ module.exports = ({ .map(columnData => { const comment = assignTemplates(templates.comment, { object: 'COLUMN', - objectName: getNamePrefixedWithSchemaName(columnData.name, tableName), + objectName: `${tableName}.${wrapInQuotes(columnData.name)}`, comment: wrapComment(columnData.comment), }); diff --git a/forward_engineering/helpers/general.js b/forward_engineering/helpers/general.js index 438fd78..7da7f7e 100644 --- a/forward_engineering/helpers/general.js +++ b/forward_engineering/helpers/general.js @@ -177,13 +177,7 @@ module.exports = ({ _, divideIntoActivatedAndDeactivated, commentIfDeactivated } ); }; - const wrapComment = comment => { - if (_.includes(comment, "'")) { - return `'${comment.replace("'", "''")}'`; - } - - return `'${comment}'`; - }; + const wrapComment = comment => `$$${comment}$$`; return { getFunctionArguments, From 744c259f91cb8e2479dfb7b407c1811d42953a25 Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus Date: Fri, 29 Oct 2021 13:47:25 +0300 Subject: [PATCH 6/6] Added log about system information --- forward_engineering/api.js | 3 +- reverse_engineering/api.js | 17 +++++--- reverse_engineering/helpers/loggerHelper.js | 47 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/forward_engineering/api.js b/forward_engineering/api.js index e1d867d..4586e80 100644 --- a/forward_engineering/api.js +++ b/forward_engineering/api.js @@ -1,5 +1,5 @@ const reApi = require('../reverse_engineering/api'); -const { createLogger } = require('../reverse_engineering/helpers/loggerHelper'); +const { createLogger, getSystemInfo } = require('../reverse_engineering/helpers/loggerHelper'); const applyToInstanceHelper = require('./applyToInstanceHelper'); module.exports = { @@ -10,6 +10,7 @@ module.exports = { }, applyToInstance(connectionInfo, logger, callback, app) { logger.clear(); + logger.log('info', getSystemInfo(connectionInfo.appVersion), 'Apply to instance'); logger.log( 'info', app.require('lodash').omit(connectionInfo, 'script', 'containerData'), diff --git a/reverse_engineering/api.js b/reverse_engineering/api.js index f78dab2..8b16258 100644 --- a/reverse_engineering/api.js +++ b/reverse_engineering/api.js @@ -1,6 +1,6 @@ 'use strict'; -const { createLogger } = require('./helpers/loggerHelper'); +const { createLogger, getSystemInfo } = require('./helpers/loggerHelper'); const postgresService = require('./helpers/postgresService'); module.exports = { @@ -12,8 +12,7 @@ module.exports = { async testConnection(connectionInfo, logger, callback, app) { try { - logger.clear(); - logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys); + logInfo('Test connection', connectionInfo, logger); const postgresLogger = createLogger({ title: 'Test connection instance log', @@ -35,8 +34,7 @@ module.exports = { async getDatabases(connectionInfo, logger, cb, app) { try { - logger.clear(); - logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys); + logInfo('Get databases', connectionInfo, logger); const postgresLogger = createLogger({ title: 'Get DB names', @@ -63,8 +61,7 @@ module.exports = { async getDbCollectionsNames(connectionInfo, logger, callback, app) { try { - logger.clear(); - logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys); + logInfo('Get DB table names', connectionInfo, logger); const postgresLogger = createLogger({ title: 'Get DB collections names', @@ -204,3 +201,9 @@ const prepareError = error => { error = JSON.parse(error); return error; }; + +const logInfo = (step, connectionInfo, logger) => { + logger.clear(); + logger.log('info', getSystemInfo(connectionInfo.appVersion), step); + logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys); +}; diff --git a/reverse_engineering/helpers/loggerHelper.js b/reverse_engineering/helpers/loggerHelper.js index 6a425f5..09f9327 100644 --- a/reverse_engineering/helpers/loggerHelper.js +++ b/reverse_engineering/helpers/loggerHelper.js @@ -1,3 +1,7 @@ +const os = require('os'); +const net = require('net'); +const packageFile = require('../../package.json'); + const createLogger = ({ title, logger, hiddenKeys }) => { return { info(message, additionalData = {}) { @@ -20,6 +24,49 @@ const prepareError = error => { return error; }; +const getPluginVersion = () => packageFile.version; + +const getSystemInfo = appVersion => { + return ( + '' + + `Date: ${new Date()}` + + '\n' + + `Application version: ${appVersion}` + + '\n' + + `Plugin version: ${getPluginVersion()}` + + '\n\n' + + `System information:` + + '\n' + + ` Hostname: ${os.hostname()}` + + '\n' + + ` Platform: ${os.platform()} ${os.arch()}` + + '\n' + + ` Release: ${os.release()}` + + '\n' + + ` Uptime: ${toTime(os.uptime())}` + + '\n' + + ` Total RAM: ${(os.totalmem() / 1073741824).toFixed(2)} GB` + + '\n' + + ` CPU Model: ${os.cpus()[0].model}` + + '\n' + + ` CPU Clock: ${maxClock(os.cpus())} MHZ` + + '\n' + + ` CPU Cores: ${os.cpus().length} cores` + + '\n\n' + ); +}; + +const maxClock = cpus => { + return cpus.reduce((highestClock, cpu) => Math.max(highestClock, cpu.speed), 0); +}; + +const prefixZero = number => (number < 10 ? '0' + number : number); + +const toTime = number => { + return Math.floor(number / 3600) + ':' + prefixZero(parseInt((number / 3600 - Math.floor(number / 3600)) * 60)); +}; + module.exports = { createLogger, + getSystemInfo, };