From 4ad77a352fa97cb18526bbec022458a980984d87 Mon Sep 17 00:00:00 2001 From: Linsted Date: Thu, 26 Feb 2026 10:06:13 +0100 Subject: [PATCH 1/3] HCK-14981: add annotations to Table level --- .../ddlProvider/ddlHelpers/tableHelper.js | 41 +++++++++++++++++++ .../ddlProvider/ddlProvider.js | 3 ++ 2 files changed, 44 insertions(+) diff --git a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js index 8b153ea..1e23581 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js @@ -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) @@ -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('"')) { + 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, diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index 40422eb..fb673c7 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -375,6 +375,7 @@ module.exports = (baseProvider, options, app) => { 'description', 'ifNotExist', 'tableProperties', + 'tableAnnotations', ), synonyms: tableData?.schemaData?.synonyms?.filter(synonym => synonym.synonymEntityId === jsonSchema.GUID) || @@ -407,6 +408,7 @@ module.exports = (baseProvider, options, app) => { tableProperties, synonyms, notNullConstraints, + tableAnnotations, }, isActivated, ) { @@ -471,6 +473,7 @@ module.exports = (baseProvider, options, app) => { partitioning, selectStatement, tableProperties, + tableAnnotations, }), }); if (usingTryCatchWrapper) { From 4b536f02800e1dc1c7f685f5a2e9ab944f79aff7 Mon Sep 17 00:00:00 2001 From: ivan-m-dev Date: Thu, 26 Feb 2026 11:29:12 +0100 Subject: [PATCH 2/3] HCK-14981: update annotation name creation logic --- .../ddlProvider/ddlHelpers/tableHelper.js | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js index 1e23581..a3be528 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js @@ -307,26 +307,22 @@ module.exports = ({ getColumnsList, checkAllKeysDeactivated, commentIfDeactivate } 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('"')) { - name = `"${name}"`; - } + .filter(annotation => annotation?.tableAnnotationName?.trim()) + .map(annotation => { + const name = prepareName(annotation.tableAnnotationName.trim()); // 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}'`; + let finalValue = ''; + const annotationValue = annotation?.tableAnnotationValue; + + if (annotationValue !== undefined && String(annotationValue).trim() !== '') { + const escapedValue = String(annotationValue).replaceAll("'", "''"); + finalValue = ` '${escapedValue}'`; } - return `${name}${valueStr}`; + return `${name}${finalValue}`; }); if (annotationsItems.length > 0) { From 1e03af7f8b4afafffb519c1f256eb81fd2b9a719 Mon Sep 17 00:00:00 2001 From: ivan-m-dev Date: Thu, 26 Feb 2026 11:44:25 +0100 Subject: [PATCH 3/3] HCK-14981: update annotation value creation logic --- .../ddlProvider/ddlHelpers/tableHelper.js | 17 +++++++++++------ forward_engineering/ddlProvider/ddlProvider.js | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js index a3be528..aa1beba 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js @@ -1,6 +1,13 @@ const _ = require('lodash'); -module.exports = ({ getColumnsList, checkAllKeysDeactivated, commentIfDeactivated, prepareName, assignTemplates }) => { +module.exports = ({ + getColumnsList, + checkAllKeysDeactivated, + commentIfDeactivated, + prepareName, + assignTemplates, + wrapComment, +}) => { const getTableType = ({ duplicated, external, @@ -306,20 +313,18 @@ module.exports = ({ getColumnsList, checkAllKeysDeactivated, commentIfDeactivate return ''; } + const wrapValue = value => wrapComment(value); + const annotationsItems = tableAnnotations .filter(annotation => annotation?.tableAnnotationName?.trim()) .map(annotation => { const name = prepareName(annotation.tableAnnotationName.trim()); - // 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 finalValue = ''; const annotationValue = annotation?.tableAnnotationValue; if (annotationValue !== undefined && String(annotationValue).trim() !== '') { - const escapedValue = String(annotationValue).replaceAll("'", "''"); - finalValue = ` '${escapedValue}'`; + finalValue = ' ' + wrapValue(String(annotationValue).trim()); } return `${name}${finalValue}`; diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index fb673c7..54bf6b8 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -65,6 +65,7 @@ module.exports = (baseProvider, options, app) => { commentIfDeactivated, prepareName, assignTemplates, + wrapComment, }); const { getUserDefinedType, isNotPlainType } = require('./ddlHelpers/udtHelper')({