Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 41 additions & 0 deletions forward_engineering/ddlProvider/ddlHelpers/tableHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = ({ getColumnsList, checkAllKeysDeactivated, commentIfDeactivate
{ key: 'partitioning', getValue: getPartitioning },
{ key: 'selectStatement', getValue: getBasicValue('AS') },
{ key: 'tableProperties', getValue: value => _.trim(value) },
{ key: 'tableAnnotations', getValue: getAnnotationsString },
]
.map(config => (tableData[config.key] ? wrap(config.getValue(tableData[config.key], tableData)) : ''))
.filter(Boolean)
Expand Down Expand Up @@ -295,6 +296,46 @@ module.exports = ({ getColumnsList, checkAllKeysDeactivated, commentIfDeactivate
return { foreignOnDelete };
};

/**
* Generates annotations string.
* @param {Array} tableAnnotations - tableAnnotations array.
* @returns {string} - Annotation string (e.g: "\nANNOTATIONS (...)") or ''.
*/
const getAnnotationsString = tableAnnotations => {
if (!Array.isArray(tableAnnotations) || tableAnnotations.length === 0) {
return '';
}

const annotationsItems = tableAnnotations
.filter(ann => ann?.tableAnnotationName?.trim())
.map(ann => {
let name = ann.tableAnnotationName.trim();

// Oracle identifiers (including annotation names) must be enclosed in double quotes
// if they contain spaces, special characters, or start with a number.
if (!/^\w+$/.test(name) && !name.startsWith('"')) {
Comment thread
chulanovskyi-bs marked this conversation as resolved.
Outdated
name = `"${name}"`;
}

// Oracle string values must be enclosed in single quotes.
// If the user's value contains a single quote (e.g., "Manager's table"),
// we must escape it by doubling it (e.g., "Manager''s table") to prevent SQL syntax errors.
let valueStr = '';
if (ann?.tableAnnotationValue !== undefined && String(ann?.tableAnnotationValue).trim() !== '') {
const escapedVal = String(ann?.tableAnnotationValue).replaceAll("'", "''");
valueStr = ` '${escapedVal}'`;
}

return `${name}${valueStr}`;
});

if (annotationsItems.length > 0) {
return `ANNOTATIONS (${annotationsItems.join(', ')})`;
}

return '';
};

return {
getTableOptions,
getTableType,
Expand Down
3 changes: 3 additions & 0 deletions forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ module.exports = (baseProvider, options, app) => {
'description',
'ifNotExist',
'tableProperties',
'tableAnnotations',
),
synonyms:
tableData?.schemaData?.synonyms?.filter(synonym => synonym.synonymEntityId === jsonSchema.GUID) ||
Expand Down Expand Up @@ -407,6 +408,7 @@ module.exports = (baseProvider, options, app) => {
tableProperties,
synonyms,
notNullConstraints,
tableAnnotations,
},
isActivated,
) {
Expand Down Expand Up @@ -471,6 +473,7 @@ module.exports = (baseProvider, options, app) => {
partitioning,
selectStatement,
tableProperties,
tableAnnotations,
}),
});
if (usingTryCatchWrapper) {
Expand Down