From ac52a48e2c70b6055cec46ce3fce6ba319ed0152 Mon Sep 17 00:00:00 2001 From: Yevhenii Moroziuk Date: Tue, 10 Sep 2024 20:00:04 +0300 Subject: [PATCH] HCK-7929: DB2 deactivated view fields are not commented out in FE (#29)
Sub-bugHCK-7929 DB2 deactivated view fields are not commented out in FE

--- .../ddlProvider/ddlProvider.js | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index 9390bc2..1b7b778 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -31,6 +31,33 @@ const { getTableType } = require('./ddlHelpers/table/getTableType.js'); const { getName } = require('./ddlHelpers/jsonSchema/jsonSchemaHelper.js'); const { hydrateAuxiliaryTableData } = require('./ddlHelpers/table/hydrateAuxiliaryTableData.js'); +/** + * @param {{ columns: object[] }} + * @returns {string} + */ +const getViewColumnsAsString = ({ columns }) => { + const statements = columns.map(({ statement, isActivated }) => + commentIfDeactivated(statement, { isActivated, isPartOfLine: false }), + ); + const lastNonCommentIndex = statements.findLastIndex(statement => !statement.startsWith('--')); + + if (lastNonCommentIndex === -1) { + return statements.join('\n'); + } + + return statements + .map((st, index) => { + const isNotLast = index !== statements.length - 1; + + if (lastNonCommentIndex === index && isNotLast) { + return `${st} -- ,`; + } + + return `${st}${isNotLast ? ',' : ''}`; + }) + .join('\n\t\t'); +}; + module.exports = (baseProvider, options, app) => { return { getDefaultType(type) { @@ -418,7 +445,7 @@ module.exports = (baseProvider, options, app) => { const orReplace = viewData.orReplace ? ' OR REPLACE' : ''; const { columns, tables } = getViewData({ keys: viewData.keys }); - const columnsAsString = columns.map(column => column.statement).join(',\n\t\t'); + const columnsAsString = getViewColumnsAsString({ columns }); const commentStatement = getTableCommentStatement({ tableName: viewName, description: viewData.description,