Skip to content

Commit

Permalink
HCK-8971: include schema name in index name of DDL (#122)
Browse files Browse the repository at this point in the history
* HCK-8971: include schema name in index name of DDL

* HCK-8971: include schema name in index name of DDL

* HCK-8971: fix comments
  • Loading branch information
Nightlngale authored Dec 4, 2024
1 parent 225bfdb commit e518474
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 12 additions & 6 deletions forward_engineering/helpers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -262,6 +267,7 @@ module.exports = app => {
filterColumnStoreProperties,
getKeyWithAlias,
getTableName,
getIndexName,
getTableOptions,
hasType,
getViewData,
Expand Down
8 changes: 4 additions & 4 deletions forward_engineering/helpers/indexHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}` : '',
Expand Down

0 comments on commit e518474

Please sign in to comment.