Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions adapter/0.1.1.json
Original file line number Diff line number Diff line change
@@ -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": [<names of new property>],
* "container": [<names of new property>],
* "model": [<names of new property>],
* "view": [<names of new property>],
* "field": {
* "<type>": [<names of new property>]
* }
* },
* "remove": {
* "entity": [<names of new property>],
* "container": [<names of new property>],
* "model": [<names of new property>],
* "view": [<names of new property>],
* "field": {
* "<type>": [<names of new property>]
* }
* },
* "modify": {
* "entity": [
* {
* "from": { <properties that identify record> },
* "to": { <properties that need to be changed> }
* }
* ],
* "container": [],
* "model": [],
* "view": [],
* "field": []
* },
* }
*/
{
"modify": {
"container": [
[
"renamePropertiesInArrayElements",
"UDFs",
{
"functionDefinition": "functionBody"
}
]
]
}
}
3 changes: 2 additions & 1 deletion forward_engineering/api.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions forward_engineering/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"type": "ddl",
"ddlType": "plugin",
"namePrefix": "PostgreSQL",
"mode": "pgsql",
"level": {
"container": true,
"entity": true,
Expand Down
14 changes: 7 additions & 7 deletions forward_engineering/configs/templates.js
Original file line number Diff line number Diff line change
@@ -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}',

Expand All @@ -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}',

Expand All @@ -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}'
};
2 changes: 1 addition & 1 deletion forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = (baseProvider, options, app) => {
assignTemplates,
templates,
commentIfDeactivated,
getNamePrefixedWithSchemaName,
wrapInQuotes,
wrapComment,
});

Expand Down
8 changes: 3 additions & 5 deletions forward_engineering/helpers/columnDefinitionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module.exports = ({
assignTemplates,
templates,
commentIfDeactivated,
getNamePrefixedWithSchemaName,
wrapComment,
wrapInQuotes
}) => {
const addLength = (type, length) => {
return `${type}(${length})`;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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),
});

Expand Down
2 changes: 1 addition & 1 deletion forward_engineering/helpers/functionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down
8 changes: 1 addition & 7 deletions forward_engineering/helpers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion properties_pane/container_level/containerLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ making sure that you maintain a proper JSON format.
"defaultValue": "IN",
"options": [
"IN",
"OUT",
"INOUT",
"VARIADIC"
]
Expand Down Expand Up @@ -226,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",
Expand Down Expand Up @@ -400,6 +401,7 @@ making sure that you maintain a proper JSON format.
"defaultValue": "IN",
"options": [
"IN",
"OUT",
"INOUT",
"VARIADIC"
]
Expand Down
17 changes: 10 additions & 7 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { createLogger } = require('./helpers/loggerHelper');
const { createLogger, getSystemInfo } = require('./helpers/loggerHelper');
const postgresService = require('./helpers/postgresService');

module.exports = {
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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);
};
47 changes: 47 additions & 0 deletions reverse_engineering/helpers/loggerHelper.js
Original file line number Diff line number Diff line change
@@ -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 = {}) {
Expand All @@ -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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions reverse_engineering/helpers/postgresService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down