diff --git a/forward_engineering/helpers/general.js b/forward_engineering/helpers/general.js index c56913d..4abf5be 100644 --- a/forward_engineering/helpers/general.js +++ b/forward_engineering/helpers/general.js @@ -7,13 +7,18 @@ module.exports = app => { const { decorateDefault } = require('./columnDefinitionHelper')(app); const { checkAllKeysDeactivated } = app.require('@hackolade/ddl-fe-utils').general; + const withBrackets = (name, brackets) => (brackets ? `[${name}]` : name); + const getTableName = (tableName, schemaName, brackets = true) => { - const withBrackets = name => (brackets ? `[${name}]` : name); - if (schemaName) { - return `${withBrackets(schemaName)}.${withBrackets(tableName)}`; - } else { - return withBrackets(tableName); - } + const name = withBrackets(tableName, brackets); + + return schemaName ? `${withBrackets(schemaName, brackets)}.${name}` : name; + }; + + const getIndexName = ({ name, schemaName, brackets = true }) => { + const indexName = withBrackets(name, brackets); + + return schemaName ? `${withBrackets(schemaName, brackets)}.${indexName}` : indexName; }; const getDefaultValue = (defaultValue, defaultConstraintName, type) => { @@ -262,6 +267,7 @@ module.exports = app => { filterColumnStoreProperties, getKeyWithAlias, getTableName, + getIndexName, getTableOptions, hasType, getViewData, diff --git a/forward_engineering/helpers/indexHelper.js b/forward_engineering/helpers/indexHelper.js index 382ad1e..8913414 100644 --- a/forward_engineering/helpers/indexHelper.js +++ b/forward_engineering/helpers/indexHelper.js @@ -4,7 +4,7 @@ const BOUNDING_BOX_LABEL = ['XMIN', 'YMIN', 'XMAX', 'YMAX']; module.exports = app => { const _ = app.require('lodash'); - const { filterColumnStoreProperties, getTableName } = require('./general')(app); + const { filterColumnStoreProperties, getTableName, getIndexName } = require('./general')(app); const { assignTemplates } = app.require('@hackolade/ddl-fe-utils'); const { divideIntoActivatedAndDeactivated, checkAllKeysDeactivated } = app.require('@hackolade/ddl-fe-utils').general; @@ -82,7 +82,7 @@ module.exports = app => { : ''; return assignTemplates(templates.index, { - name: index.name, + name: getIndexName({ name: index.name, schemaName: index.schemaName }), unique: index.unique ? ' UNIQUE' : '', clustered: index.clustered ? ' CLUSTERED' : '', table: getTableName(tableName, index.schemaName), @@ -159,7 +159,7 @@ module.exports = app => { return isParentActivated ? commentIfDeactivated(column, key) : column; }) .join(',\n\t'), - indexName: index.keyIndex, + indexName: getIndexName({ name: index.keyIndex, schemaName: index.schemaName }), catalog: catalog ? `ON ${catalog}\n` : '', options: options ? `WITH (\n\t${options}\n)` : '', terminator, @@ -212,7 +212,7 @@ module.exports = app => { const options = getSpatialOptions(index); return assignTemplates(templates.spatialIndex, { - name: index.name, + name: getIndexName({ name: index.name, schemaName: index.schemaName }), table: getTableName(tableName, index.schemaName), column: `[${index.column.name}]`, using: index.using ? `\nUSING ${index.using}` : '',