Skip to content

Commit

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

* HCK-8971: fix comments

* HCK-8971: fix comments
  • Loading branch information
Nightlngale authored Dec 4, 2024
1 parent ef1f848 commit 5096a56
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
7 changes: 5 additions & 2 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')({
Expand Down Expand Up @@ -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 = [];
Expand Down
33 changes: 29 additions & 4 deletions forward_engineering/helpers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -323,6 +347,7 @@ module.exports = (_, wrap) => {

return {
getTableName,
getIndexName,
getTableOptions,
getPartitions,
getViewData,
Expand Down

0 comments on commit 5096a56

Please sign in to comment.