Skip to content

Commit

Permalink
HCK-7929: DB2 deactivated view fields are not commented out in FE (#29)
Browse files Browse the repository at this point in the history
<!--do not remove this marker, its needed to replace info when ticket
title is updated -->
<!--jira-description-action-hidden-marker-start-->

<table>
<td>
<a href="https://hackolade.atlassian.net/browse/HCK-7929"
title="HCK-7929" target="_blank"><img alt="Sub-bug"
src="https://hackolade.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
/>HCK-7929</a> DB2 deactivated view fields are not commented out in FE
  </td></table>
  <br />
 

<!--jira-description-action-hidden-marker-end-->
  • Loading branch information
Nightlngale authored Sep 10, 2024
1 parent e9a0af7 commit ac52a48
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ac52a48

Please sign in to comment.