From de1cdd886cd1036e1270b98599040134cf2db137 Mon Sep 17 00:00:00 2001 From: yevhenii-moroziuk Date: Tue, 3 Dec 2024 18:28:01 +0200 Subject: [PATCH 1/3] HCK-8971: include schema name in index name of DDL --- forward_engineering/ddlProvider.js | 7 ++++-- forward_engineering/helpers/general.js | 33 ++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index 6d2919d..562cfc8 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -20,7 +20,7 @@ module.exports = (baseProvider, options, app) => { const { assignTemplates, compareGroupItems } = app.require('@hackolade/ddl-fe-utils'); const { decorateDefault, decorateType, canBeNational, getSign, createGeneratedColumn, canHaveAutoIncrement } = require('./helpers/columnDefinitionHelper')(_, wrap); - const { getTableName, getTableOptions, getPartitions, getViewData, getCharacteristics, escapeQuotes } = + const { getTableName, getIndexName, getTableOptions, getPartitions, getViewData, getCharacteristics, escapeQuotes } = require('./helpers/general')(_, wrap); const { generateConstraintsString, foreignKeysToString, foreignActiveKeysToString, createKeyConstraint } = require('./helpers/constraintsHelper')({ @@ -430,7 +430,10 @@ module.exports = (baseProvider, options, app) => { const wholeStatementCommented = index.isActivated === false || !isParentActivated || allDeactivated; const indexType = index.indexType && _.toUpper(index.indexType) !== 'KEY' ? `${_.toUpper(index.indexType)} ` : ''; - const name = wrap(index.indxName || '', '`', '`'); + const name = getIndexName({ + name: index.indxName, + schemaName: dbData.databaseName, + }) const table = getTableName(tableName, dbData.databaseName); const indexCategory = index.indexCategory ? ` USING ${index.indexCategory}` : ''; let indexOptions = []; diff --git a/forward_engineering/helpers/general.js b/forward_engineering/helpers/general.js index 057c5f2..0c4ef70 100644 --- a/forward_engineering/helpers/general.js +++ b/forward_engineering/helpers/general.js @@ -67,14 +67,38 @@ module.exports = (_, wrap) => { NDB: ['KEY_BLOCK_SIZE'], }; - const getTableName = (tableName, schemaName) => { + /** + * @param {Object} params + * @param {string} params.name + * @param {string} params.schemaName + * @returns {string} + * */ + const getNamePrefixedWithSchemaName = ({name, schemaName}) => { if (schemaName) { - return `\`${schemaName}\`.\`${tableName}\``; - } else { - return `\`${tableName}\``; + return `\`${schemaName}\`.\`${name}\``; } + return `\`${name}\``; + }; + + /** + * @param schemaName {string} + * @param tableName {string} + * @return {string} + * */ + const getTableName = (tableName, schemaName) => { + return getNamePrefixedWithSchemaName({name: tableName, schemaName}); }; + /** + * @param {Object} params + * @param {string} params.name + * @param {string} params.schemaName + * @returns {string} + */ + const getIndexName = ({ name, schemaName }) => { + return getNamePrefixedWithSchemaName({name, schemaName}); + } + const getOptionValue = (keyword, value) => { if (['ROW_FORMAT', 'INSERT_METHOD'].includes(keyword)) { if (value) { @@ -323,6 +347,7 @@ module.exports = (_, wrap) => { return { getTableName, + getIndexName, getTableOptions, getPartitions, getViewData, From a6fe7b0e170aed0c34f11a616620a0203caaf497 Mon Sep 17 00:00:00 2001 From: yevhenii-moroziuk Date: Wed, 4 Dec 2024 13:35:53 +0200 Subject: [PATCH 2/3] HCK-8971: fix comments --- forward_engineering/helpers/general.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forward_engineering/helpers/general.js b/forward_engineering/helpers/general.js index 0c4ef70..4aca0fc 100644 --- a/forward_engineering/helpers/general.js +++ b/forward_engineering/helpers/general.js @@ -73,7 +73,7 @@ module.exports = (_, wrap) => { * @param {string} params.schemaName * @returns {string} * */ - const getNamePrefixedWithSchemaName = ({name, schemaName}) => { + const getNamePrefixedWithSchemaName = ({ name, schemaName }) => { if (schemaName) { return `\`${schemaName}\`.\`${name}\``; } @@ -86,7 +86,7 @@ module.exports = (_, wrap) => { * @return {string} * */ const getTableName = (tableName, schemaName) => { - return getNamePrefixedWithSchemaName({name: tableName, schemaName}); + return getNamePrefixedWithSchemaName({ name: tableName, schemaName }); }; /** From aa2d9051fa56d826bddc83e83df86eaad2413e83 Mon Sep 17 00:00:00 2001 From: yevhenii-moroziuk Date: Wed, 4 Dec 2024 14:00:26 +0200 Subject: [PATCH 3/3] HCK-8971: fix comments --- forward_engineering/helpers/general.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forward_engineering/helpers/general.js b/forward_engineering/helpers/general.js index 4aca0fc..fee0c7e 100644 --- a/forward_engineering/helpers/general.js +++ b/forward_engineering/helpers/general.js @@ -96,7 +96,7 @@ module.exports = (_, wrap) => { * @returns {string} */ const getIndexName = ({ name, schemaName }) => { - return getNamePrefixedWithSchemaName({name, schemaName}); + return getNamePrefixedWithSchemaName({ name, schemaName }); } const getOptionValue = (keyword, value) => {