From 3a71e2f6bc89cfe1bcea22b91147122e4fb316d1 Mon Sep 17 00:00:00 2001 From: Serhii Filonenko Date: Tue, 17 Sep 2024 09:46:25 +0300 Subject: [PATCH 1/4] HCK-8004: remove trailing comma before last deactivated column --- forward_engineering/ddlProvider.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index 40e4d6c..e46233e 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -17,6 +17,7 @@ module.exports = (baseProvider, options, app) => { getDifferentProperties, } = app.require('@hackolade/ddl-fe-utils').general; const { assignTemplates, compareGroupItems } = app.require('@hackolade/ddl-fe-utils'); + const { joinActivatedAndDeactivatedStatements } = app.require('@hackolade/ddl-fe-utils'); const { decorateDefault, decorateType, canBeNational, getSign, createGeneratedColumn, canHaveAutoIncrement } = require('./helpers/columnDefinitionHelper')(_, wrap); const { getTableName, getTableOptions, getPartitions, getViewData, getCharacteristics, escapeQuotes } = @@ -272,10 +273,21 @@ module.exports = (baseProvider, options, app) => { const dividedForeignKeys = divideIntoActivatedAndDeactivated(foreignKeyConstraints, key => key.statement); const foreignKeyConstraintsString = generateConstraintsString(dividedForeignKeys, isActivated); const ignoreReplace = selectStatement ? (selectIgnore ? ' IGNORE' : selectReplace ? ' REPLACE' : '') : ''; + const columnStatementDtos = columns.map(column => { + return { + statement: column, + isActivated: !column.startsWith('--'), + }; + }); + const columnDefinitions = joinActivatedAndDeactivatedStatements({ + statementDtos: columnStatementDtos, + delimiter: ',', + indent: '\n\t', + }); const tableStatement = assignTemplates(templates.createTable, { name: tableName, - column_definitions: columns.join(',\n\t'), + column_definitions: columnDefinitions, selectStatement: selectStatement ? ` AS ${selectStatement}` : '', temporary: temporaryTable, ifNotExist: ifNotExistTable, From 3025089b99c2d29a198fc0377265a37c342bb655 Mon Sep 17 00:00:00 2001 From: Serhii Filonenko Date: Tue, 17 Sep 2024 14:57:53 +0300 Subject: [PATCH 2/4] Revert "HCK-8004: remove trailing comma before last deactivated column" This reverts commit 3a71e2f6bc89cfe1bcea22b91147122e4fb316d1. --- forward_engineering/ddlProvider.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index e46233e..40e4d6c 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -17,7 +17,6 @@ module.exports = (baseProvider, options, app) => { getDifferentProperties, } = app.require('@hackolade/ddl-fe-utils').general; const { assignTemplates, compareGroupItems } = app.require('@hackolade/ddl-fe-utils'); - const { joinActivatedAndDeactivatedStatements } = app.require('@hackolade/ddl-fe-utils'); const { decorateDefault, decorateType, canBeNational, getSign, createGeneratedColumn, canHaveAutoIncrement } = require('./helpers/columnDefinitionHelper')(_, wrap); const { getTableName, getTableOptions, getPartitions, getViewData, getCharacteristics, escapeQuotes } = @@ -273,21 +272,10 @@ module.exports = (baseProvider, options, app) => { const dividedForeignKeys = divideIntoActivatedAndDeactivated(foreignKeyConstraints, key => key.statement); const foreignKeyConstraintsString = generateConstraintsString(dividedForeignKeys, isActivated); const ignoreReplace = selectStatement ? (selectIgnore ? ' IGNORE' : selectReplace ? ' REPLACE' : '') : ''; - const columnStatementDtos = columns.map(column => { - return { - statement: column, - isActivated: !column.startsWith('--'), - }; - }); - const columnDefinitions = joinActivatedAndDeactivatedStatements({ - statementDtos: columnStatementDtos, - delimiter: ',', - indent: '\n\t', - }); const tableStatement = assignTemplates(templates.createTable, { name: tableName, - column_definitions: columnDefinitions, + column_definitions: columns.join(',\n\t'), selectStatement: selectStatement ? ` AS ${selectStatement}` : '', temporary: temporaryTable, ifNotExist: ifNotExistTable, From b2368f088b363a041f709e54e5b7f7a73ee2b47d Mon Sep 17 00:00:00 2001 From: Serhii Filonenko Date: Tue, 17 Sep 2024 15:05:27 +0300 Subject: [PATCH 3/4] HCK-8004: remove trailing comma before last deactivated column --- forward_engineering/ddlProvider.js | 4 +- .../joinActivatedAndDeactivatedStatements.js | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 forward_engineering/utils/joinActivatedAndDeactivatedStatements.js diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index 40e4d6c..6d2919d 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -3,6 +3,7 @@ const types = require('./configs/types'); const templates = require('./configs/templates'); const getAdditionalOptions = require('./helpers/getAdditionalOptions'); const dropStatementProxy = require('./helpers/dropStatementProxy'); +const { joinActivatedAndDeactivatedStatements } = require('./utils/joinActivatedAndDeactivatedStatements'); module.exports = (baseProvider, options, app) => { const _ = app.require('lodash'); @@ -272,10 +273,11 @@ module.exports = (baseProvider, options, app) => { const dividedForeignKeys = divideIntoActivatedAndDeactivated(foreignKeyConstraints, key => key.statement); const foreignKeyConstraintsString = generateConstraintsString(dividedForeignKeys, isActivated); const ignoreReplace = selectStatement ? (selectIgnore ? ' IGNORE' : selectReplace ? ' REPLACE' : '') : ''; + const columnStatements = joinActivatedAndDeactivatedStatements({ statements: columns, indent: '\n\t' }); const tableStatement = assignTemplates(templates.createTable, { name: tableName, - column_definitions: columns.join(',\n\t'), + column_definitions: columnStatements, selectStatement: selectStatement ? ` AS ${selectStatement}` : '', temporary: temporaryTable, ifNotExist: ifNotExistTable, diff --git a/forward_engineering/utils/joinActivatedAndDeactivatedStatements.js b/forward_engineering/utils/joinActivatedAndDeactivatedStatements.js new file mode 100644 index 0000000..36e0a11 --- /dev/null +++ b/forward_engineering/utils/joinActivatedAndDeactivatedStatements.js @@ -0,0 +1,49 @@ +/** + * @param {{ +* index: number; +* numberOfStatements: number; +* lastIndexOfActivatedStatement: number; +* delimiter: string; +* }} +* @return {string} +* */ +const getDelimiter = ({ index, numberOfStatements, lastIndexOfActivatedStatement, delimiter }) => { + const isLastStatement = index === numberOfStatements - 1; + const isLastActivatedStatement = index === lastIndexOfActivatedStatement; + + if (isLastStatement || isLastActivatedStatement) { + return ''; + } + + return delimiter; +}; + +/** +* @param {{ +* statements?: string[]; +* delimiter?: string; +* indent?: string; +* }} +* @return {string} +* */ +const joinActivatedAndDeactivatedStatements = ({ statements = [], delimiter = ',', indent = '\n' }) => { + const lastIndexOfActivatedStatement = statements.findLastIndex(statement => !statement.startsWith('--')); + const numberOfStatements = statements.length; + + return statements + .map((statement, index) => { + const currentDelimiter = getDelimiter({ + index, + numberOfStatements, + lastIndexOfActivatedStatement, + delimiter, + }); + + return statement + currentDelimiter; + }) + .join(indent); +}; + +module.exports = { + joinActivatedAndDeactivatedStatements, +}; From b86c02d261f981540b3f776eb2df1935aae61c2e Mon Sep 17 00:00:00 2001 From: Serhii Filonenko Date: Tue, 17 Sep 2024 16:24:32 +0300 Subject: [PATCH 4/4] HCK-8004: add comma commenting for last activated column statement --- .../utils/joinActivatedAndDeactivatedStatements.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/forward_engineering/utils/joinActivatedAndDeactivatedStatements.js b/forward_engineering/utils/joinActivatedAndDeactivatedStatements.js index 36e0a11..02f0470 100644 --- a/forward_engineering/utils/joinActivatedAndDeactivatedStatements.js +++ b/forward_engineering/utils/joinActivatedAndDeactivatedStatements.js @@ -11,10 +11,14 @@ const getDelimiter = ({ index, numberOfStatements, lastIndexOfActivatedStatement const isLastStatement = index === numberOfStatements - 1; const isLastActivatedStatement = index === lastIndexOfActivatedStatement; - if (isLastStatement || isLastActivatedStatement) { + if (isLastStatement) { return ''; } + if (isLastActivatedStatement) { + return ' --' + delimiter; + } + return delimiter; };