diff --git a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js index 8b153ea..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, @@ -36,6 +43,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 +303,40 @@ 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 wrapValue = value => wrapComment(value); + + const annotationsItems = tableAnnotations + .filter(annotation => annotation?.tableAnnotationName?.trim()) + .map(annotation => { + const name = prepareName(annotation.tableAnnotationName.trim()); + + let finalValue = ''; + const annotationValue = annotation?.tableAnnotationValue; + + if (annotationValue !== undefined && String(annotationValue).trim() !== '') { + finalValue = ' ' + wrapValue(String(annotationValue).trim()); + } + + return `${name}${finalValue}`; + }); + + 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..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')({ @@ -375,6 +376,7 @@ module.exports = (baseProvider, options, app) => { 'description', 'ifNotExist', 'tableProperties', + 'tableAnnotations', ), synonyms: tableData?.schemaData?.synonyms?.filter(synonym => synonym.synonymEntityId === jsonSchema.GUID) || @@ -407,6 +409,7 @@ module.exports = (baseProvider, options, app) => { tableProperties, synonyms, notNullConstraints, + tableAnnotations, }, isActivated, ) { @@ -471,6 +474,7 @@ module.exports = (baseProvider, options, app) => { partitioning, selectStatement, tableProperties, + tableAnnotations, }), }); if (usingTryCatchWrapper) {