Skip to content
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
44 changes: 43 additions & 1 deletion forward_engineering/ddlProvider/ddlHelpers/tableHelper.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = (baseProvider, options, app) => {
commentIfDeactivated,
prepareName,
assignTemplates,
wrapComment,
});

const { getUserDefinedType, isNotPlainType } = require('./ddlHelpers/udtHelper')({
Expand Down Expand Up @@ -375,6 +376,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 +409,7 @@ module.exports = (baseProvider, options, app) => {
tableProperties,
synonyms,
notNullConstraints,
tableAnnotations,
},
isActivated,
) {
Expand Down Expand Up @@ -471,6 +474,7 @@ module.exports = (baseProvider, options, app) => {
partitioning,
selectStatement,
tableProperties,
tableAnnotations,
}),
});
if (usingTryCatchWrapper) {
Expand Down