Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCK-8971: include schema name in index name of DDL #35

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading