Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
eaaa66c
RE preparations
Vitalii4as Sep 20, 2021
9fcc4ce
RE: added logic to show schemas with tables
Vitalii4as Sep 21, 2021
8b98b19
Fixed configs for json types
Vitalii4as Sep 22, 2021
b7dd3f1
RE: added retrieving of table properties
Vitalii4as Sep 24, 2021
1da7f8a
RE: removed partition data from query
Vitalii4as Sep 24, 2021
725f8d4
RE: added handling table properties and columns
Vitalii4as Sep 28, 2021
b400a2c
RE: fixed table partitioning
Vitalii4as Sep 29, 2021
ec54c98
RE: added handling of inherits property
Vitalii4as Sep 29, 2021
b4fb4e2
RE: added constraints support
Vitalii4as Sep 29, 2021
a506d8d
Changed configuration for indexes storage parameters
Vitalii4as Sep 30, 2021
4cc575d
RE: added query tolerancy for not important data, added RE of table i…
Vitalii4as Sep 30, 2021
b084d4d
RE: addeed reversion of relationships
Vitalii4as Sep 30, 2021
c8b0826
Added logging of Postgres version
Vitalii4as Oct 1, 2021
ead4724
RE: added RE of views
Vitalii4as Oct 1, 2021
987947d
RE: added RE of functions and procedures
Vitalii4as Oct 1, 2021
4fc8c32
Removed not used file
Vitalii4as Oct 1, 2021
0d7457f
Added configs for user-defined types, fixed issues with json type
Vitalii4as Oct 4, 2021
3d0061a
RE: fixed Re of json types
Vitalii4as Oct 4, 2021
ac1ef38
RE: added RE of user-defined types
Vitalii4as Oct 4, 2021
3de90e0
RE: fixed issue with redundant table
Vitalii4as Oct 4, 2021
190044c
Added tooltips
Vitalii4as Oct 4, 2021
0f61cc2
Fixed localization
Vitalii4as Oct 4, 2021
36076e8
RE: fixed query tolerance to fails
Vitalii4as Oct 4, 2021
9f14d87
RE: added schema name to inherits
Vitalii4as Oct 5, 2021
b287e6f
RE: added progress logs
Vitalii4as Oct 5, 2021
1ec4b83
RE: added Re of database properties
Vitalii4as Oct 5, 2021
761af41
Fixed configs
Vitalii4as Oct 8, 2021
87fd743
Added support for multirange type, renamed range_type to range_udt
Vitalii4as Oct 8, 2021
36dc68b
RE: added support for RE of comments of columns
Vitalii4as Oct 8, 2021
2907c58
Configs: removed not needed synonyms, disabled enum value on entities
Vitalii4as Oct 11, 2021
e30a181
Fixed config issues
Vitalii4as Oct 11, 2021
c41506a
FE: Added FE of Tables, UDT, Functions and procedures
Vitalii4as Oct 11, 2021
45bd890
FE: added FE of table indexes
Vitalii4as Oct 11, 2021
ee1d853
Configs: fixed view options
Vitalii4as Oct 11, 2021
a53a077
RE: fixes view re fixes
Vitalii4as Oct 11, 2021
f3bf653
FE: added views fe
Vitalii4as Oct 11, 2021
32c6c93
FE: added FE of comments on table columns
Vitalii4as Oct 11, 2021
b4cb187
FE: fixed include property of indexes
Vitalii4as Oct 12, 2021
c8a0d18
Added apply to instance
Vitalii4as Oct 12, 2021
241b860
Added support for tsvector and tsquery. Fixed RE of these properties
Vitalii4as Oct 12, 2021
35e9166
FE: fixed fe of functions and procedures, fixed fe of precision value…
Vitalii4as Oct 12, 2021
ff6d95f
Remove trailing comma
Vitalii4as Oct 12, 2021
8993782
FIxed indexes to properly work with different index_method, fixed fe …
Vitalii4as Oct 12, 2021
8593dda
Fixed re and fe of functions
Vitalii4as Oct 12, 2021
75a4fb4
Fixed ifNotExists for table, fixed ndents
Vitalii4as Oct 12, 2021
79401b0
RE: fixed RE of functions
Vitalii4as Oct 12, 2021
cf1223a
FE: fixed issue with not valid comments, added support for FE on mode…
Vitalii4as Oct 12, 2021
1631be6
Indexes: fixed columns in indexes
Vitalii4as Oct 13, 2021
caa40ff
Fixed re and fe of storage options
Vitalii4as Oct 13, 2021
8f1b5f2
storage parameters default values and dependencies
Vitalii4as Oct 13, 2021
5585a98
Fixed partition key. Fixed columns fe of default value
Vitalii4as Oct 13, 2021
b1e4223
FE: reverted old logic of creating functions and udfs
Vitalii4as Oct 13, 2021
46cc1b6
RE: fixed re of <include> and <where> properties of indexes
Vitalii4as Oct 13, 2021
227ff3a
Bump Hackolade version
Vitalii4as Oct 13, 2021
a970e07
Fixed issue with multirange types, fixed names in configs
Vitalii4as Oct 15, 2021
e21e73d
Added support to inherit multiple tables
Vitalii4as Oct 15, 2021
acbe469
RE: fixed issue issue with re of <required> and <default> properties
Vitalii4as Oct 18, 2021
4fbda3d
Added support of domain types including FE and RE
Vitalii4as Oct 19, 2021
cd8c67d
Fixed RE of timestamp precision, fixed issue with not handled <withou…
Vitalii4as Oct 19, 2021
95ca93b
RE: added support to select database after connection to PostgreSQL s…
Vitalii4as Oct 19, 2021
91fd64a
Apply to instance: added scenario to show database selector before ap…
Vitalii4as Oct 19, 2021
f491da0
RE: fixed log message
Vitalii4as Oct 19, 2021
151e015
Fixed configs accroding to documentation
Vitalii4as Oct 20, 2021
139316f
FE: fixed Fe of constrants defined on field level
Vitalii4as Oct 20, 2021
5dae493
FE: added generation of database script, adjusted ddlProvider to work…
Vitalii4as Oct 21, 2021
a8e025a
RE: fixed not handled error
Vitalii4as Oct 22, 2021
ec300da
Apply to instance: removed createDb script before applying process
Vitalii4as Oct 22, 2021
1cfb209
RE: fixed long test connection
Vitalii4as Oct 25, 2021
45abcf2
Fixed small issue in config
Vitalii4as Oct 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
50 changes: 26 additions & 24 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
const reApi = require('../reverse_engineering/api');
const { createLogger } = require('../reverse_engineering/helpers/loggerHelper');
const applyToInstanceHelper = require('./applyToInstanceHelper');

module.exports = {
applyToInstance(connectionInfo, logger, callback, app) {
logger.clear();
logger.log('info', connectionInfo, 'connectionInfo', connectionInfo.hiddenKeys);
getDatabases(connectionInfo, logger, callback, app) {
logger.progress({ message: 'Find all databases' });

applyToInstanceHelper.applyToInstance(connectionInfo, logger, app)
.then(result => {
callback(null, result);
})
.catch(error => {
const err = {
message: error.message,
stack: error.stack,
};
logger.log('error', err, 'Error when applying to instance');
callback(err);
});
},
testConnection(connectionInfo, logger, callback, app) {
reApi.testConnection(connectionInfo, logger, callback, app)
.then(
callback,
callback
);
}
};
reApi.getDatabases(connectionInfo, logger, callback, app);
},
applyToInstance(connectionInfo, logger, callback, app) {
logger.clear();
logger.log(
'info',
app.require('lodash').omit(connectionInfo, 'script', 'containerData'),
'connectionInfo',
connectionInfo.hiddenKeys
);

const postgresLogger = createLogger({
title: 'Apply to instance',
hiddenKeys: connectionInfo.hiddenKeys,
logger,
});

applyToInstanceHelper.applyToInstance(connectionInfo, postgresLogger, app).then(callback, callback);
},
testConnection(connectionInfo, logger, callback, app) {
reApi.testConnection(connectionInfo, logger, callback, app).then(callback, callback);
},
};
54 changes: 19 additions & 35 deletions forward_engineering/applyToInstanceHelper.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
const connectionHelper = require('../reverse_engineering/helpers/connectionHelper');

const removeDelimiter = (statement) => {
const regExp = /delimiter (.*)/i;

if (!regExp.test(statement)) {
return statement;
}

const delimiter = statement.match(regExp)[1];
const statementWithoutDelimiter = statement.replace(new RegExp(regExp, 'gi'), '');

return statementWithoutDelimiter.trim().replace(new RegExp(delimiter.split('').map(n => '\\' + n).join('') + '$'), '');
};
const postgresService = require('../reverse_engineering/helpers/postgresService');

const applyToInstance = async (connectionInfo, logger, app) => {
const _ = app.require('lodash');
const async = app.require('async');
const connection = connectionHelper.createInstance(
await connectionHelper.connect(connectionInfo),
logger,
);

try {
const queries = connectionInfo.script.split('\n\n').map((query) => {
return removeDelimiter(_.trim(query));
}).filter(Boolean);
let i = 0;
try {
postgresService.setDependencies(app);
await postgresService.connect(connectionInfo, logger);
await postgresService.logVersion();
await postgresService.applyScript(removeCreateDbScript(connectionInfo.script));
} catch (error) {
logger.error(error);
throw prepareError(error);
}
};

await async.mapSeries(queries, async query => {
const message = 'Query: ' + query.split('\n').shift().substr(0, 150);
logger.progress({ message });
await connection.query(query);
});
const removeCreateDbScript = script => {
const createDbScriptRegexp = /CREATE DATABASE[^;]*;/gi;

} catch (e) {
connectionHelper.close();
throw e;
}
return script.replace(createDbScriptRegexp, '');
};

const prepareError = error => {
error = JSON.stringify(error, Object.getOwnPropertyNames(error));
error = JSON.parse(error);
return error;
};

module.exports = { applyToInstance };
13 changes: 10 additions & 3 deletions forward_engineering/config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"type": "ddl",
"ddlType": "plugin",
"namePrefix": "MariaDB",
"namePrefix": "PostgreSQL",
"level": {
"container": true,
"entity": true,
"view": true
},
"resolvedDefinitions": true,
"applyScriptToInstance": true
"applyScriptToInstance": true,
"applyToInstanceSettings": {
"scenario": "getDatabases"
},
"combinedContainers": true,
"feLevelSelector": {
"container": true,
"model": true
}
}
20 changes: 10 additions & 10 deletions forward_engineering/configs/defaultTypes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
number: 'NUMBER',
string: 'TEXT',
date: 'DATE',
timestamp: 'TIMESTAMP',
binary: 'BINARY',
boolean: 'BIT',
document: 'LONGTEXT',
array: 'LONGTEXT',
objectId: 'VARCHAR(24)',
default: 'CHAR',
number: 'numeric',
string: 'text',
date: 'date',
timestamp: 'timestamp',
binary: 'bytea',
boolean: 'boolean',
document: 'jsonb',
array: 'jsonb',
objectId: 'uuid',
default: 'char',
};
64 changes: 36 additions & 28 deletions forward_engineering/configs/templates.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
module.exports = {
createDatabase: 'CREATE${orReplace} DATABASE${ifNotExist} `${name}`${dbOptions};\n\nUSE `${name}`;\n',
createDatabase: 'CREATE DATABASE ${name}${template}${encoding}${locale}${collate}${characterClassification}${tablespace};\n',

createTable:
'CREATE ${orReplace}${temporary}TABLE ${ifNotExist}${name} (\n' +
'\t${column_definitions}${keyConstraints}${checkConstraints}${foreignKeyConstraints}\n' +
')${options}${partitions}${selectStatement};\n',
createSchema: 'CREATE SCHEMA${ifNotExist} ${name};\nSET search_path TO ${name};\n${comment}\n',

createLikeTable: 'CREATE ${orReplace}${temporary}TABLE ${ifNotExist}${name} LIKE ${likeTableName};\n',
comment: 'COMMENT ON ${object} ${objectName} IS ${comment};\n',

columnDefinition:
'`${name}` ${national}${type}${signed}${primary_key}${unique_key}${default}${autoIncrement}${zeroFill}${not_null}${invisible}${compressed}${charset}${collate}${comment}',
createTable:
'CREATE${temporary} TABLE${ifNotExist} ${name} (\n' +
'${columnDefinitions}${keyConstraints}${checkConstraints}${foreignKeyConstraints}\n' +
')${options};\n${comment}${columnDescriptions}',

checkConstraint: 'CONSTRAINT ${name}CHECK (${expression})',
columnDefinition: '${name} ${type}${collation}${primaryKey}${uniqueKey}${defaultValue}${notNull}',

createForeignKeyConstraint:
'CONSTRAINT `${name}` FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable}(${primaryKey})',
checkConstraint: '${name} CHECK (${expression})${noInherit}',

createKeyConstraint: '${constraintName}${keyType}${columns}${using}${blockSize}${comment}${ignore}',
createForeignKeyConstraint: '${name} FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable} (${primaryKey})',

createForeignKey:
'ALTER TABLE ${foreignTable} ADD CONSTRAINT `${name}` FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable}(${primaryKey});',
createKeyConstraint: '${constraintName}${keyType}${columns}${includeNonKey}${storageParameters}${tablespace}',

index:
'CREATE ${indexType}INDEX ${ifNotExist}${name}${indexCategory}\n' +
'\tON ${table} ( ${keys} )${indexOptions};\n',
createForeignKey:
'ALTER TABLE IF EXISTS ${foreignTable} ADD CONSTRAINT ${name} FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable}(${primaryKey});',

createView:
'CREATE ${orReplace}${algorithm}${sqlSecurity}VIEW ${ifNotExist}${name} AS ${selectStatement}${checkOption};\n',
index:
'CREATE${unique} INDEX${concurrently}${ifNotExist} ${name}\n' +
' ON${only} ${tableName}${using}${keys}${options};\n\n',

viewSelectStatement: 'SELECT ${keys}\n\tFROM ${tableName}',
createView:
'CREATE${orReplace}${temporary} VIEW ${name}${withOptions}\nAS ${selectStatement}${checkOption};\n${comment}\n',

createFunction:
'CREATE ${orReplace}${aggregate}FUNCTION ${ifNotExist}${name}\n' +
'\t(${parameters})\n' +
'\tRETURNS ${type}\n' +
'\t${characteristics}\n' +
'${body}${delimiter}\n',
viewSelectStatement: 'SELECT ${keys}\n\tFROM ${tableName}',

createProcedure:
'CREATE ${orReplace}PROCEDURE ${name} (${parameters})\n' + '\t${characteristics}\n' + '${body}${delimiter}\n',
createFunction:
'CREATE${orReplace} FUNCTION ${name}\n' +
'\t(${parameters})\n' +
'\tRETURNS ${returnType}\n' +
'\tLANGUAGE ${language}\n' +
'${properties}' +
'AS $BODY$\n${definition}\n$BODY$;\n',

createProcedure:
'CREATE${orReplace} PROCEDURE ${name} (${parameters})\n' +
'\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}'
};
Loading