Skip to content

Commit ddd2e2a

Browse files
committed
HCK-14284: Clean up the code
1 parent b340981 commit ddd2e2a

4 files changed

Lines changed: 16 additions & 56 deletions

File tree

forward_engineering/alterScript/alterScriptFromDeltaHelper.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { isObjectInDeltaModelActivated } = require('../utils/general');
21
const { getContainersScripts } = require('./alterScriptHelpers/alterContainerHelper');
32
const {
43
getModifyCollectionScriptDtos,

forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@ const {
88
const { wrapInQuotes, getIsChangeProperties, getUpdatedProperties } = require('../../utils/general');
99
const { getModifiedCommentOnSchemaScriptDtos } = require('./containerHelpers/commentsHelper');
1010

11-
const getSchemaName = containerData => containerData.role.name;
11+
const extractSchemaName = containerData => containerData.role.name;
1212

1313
const getAddContainerScriptDto = ddlProvider => containerData => {
1414
const schemaData = {
1515
...containerData.role,
16-
schemaName: getSchemaName(containerData),
16+
schemaName: extractSchemaName(containerData),
1717
};
1818
const script = ddlProvider.createSchema(schemaData);
1919

2020
return AlterScriptDto.getInstance([script], true, false);
2121
};
2222

2323
const getDeleteContainerScriptDto = ddlProvider => containerData => {
24-
const script = ddlProvider.dropSchema({ name: getSchemaName(containerData) });
24+
const script = ddlProvider.dropSchema({ name: extractSchemaName(containerData) });
2525

2626
return AlterScriptDto.getInstance([script], true, true);
2727
};
2828

2929
const getModifyContainerScriptDto = ddlProvider => containerData => {
3030
const scripts = [];
3131
const compMod = containerData.role?.compMod || {};
32-
const schemaName = getSchemaName(containerData);
32+
const schemaName = extractSchemaName(containerData);
33+
const wrappedSchemaName = wrapInQuotes(schemaName);
3334
const isActivated = containerData.isActivated !== false;
3435
const updatedProperties = getUpdatedProperties(compMod, ['dataCapture']);
3536

@@ -38,13 +39,17 @@ const getModifyContainerScriptDto = ddlProvider => containerData => {
3839
scripts.push(AlterScriptDto.getInstance([alterDataCaptureScript], isActivated, false));
3940
}
4041

41-
const commentScripts = getModifiedCommentOnSchemaScriptDtos({
42-
schemaName,
42+
const commentScript = getModifiedCommentOnSchemaScriptDtos({
43+
schemaName: wrappedSchemaName,
4344
compMod,
4445
isActivated,
4546
});
4647

47-
return [...scripts, ...commentScripts].filter(Boolean);
48+
if (commentScript) {
49+
scripts.push(commentScript);
50+
}
51+
52+
return scripts;
4853
};
4954

5055
const getContainersScripts = app => {

forward_engineering/alterScript/alterScriptHelpers/containerHelpers/commentsHelper.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ const {
66
const { wrapInQuotes } = require('../../../utils/general');
77

88
const getModifiedCommentOnSchemaScriptDtos = ({ schemaName, compMod, isActivated }) => {
9-
const scripts = [];
109
const description = compMod.description || {};
1110

1211
if (description.new && description.new !== description.old) {
1312
const script = getSchemaCommentStatement({ schemaName, description: description.new });
14-
scripts.push(AlterScriptDto.getInstance([script], isActivated, false));
13+
return AlterScriptDto.getInstance([script], isActivated, false);
1514
}
1615

1716
if (description.old && !description.new) {
1817
const script = dropSchemaCommentStatement({ schemaName });
19-
scripts.push(AlterScriptDto.getInstance([script], isActivated, true));
18+
return AlterScriptDto.getInstance([script], isActivated, true);
2019
}
2120

22-
return scripts;
21+
return undefined;
2322
};
2423

2524
module.exports = {

forward_engineering/ddlProvider/ddlHelpers/comment/commentHelper.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@ const getCommentStatement = ({ objectName, objectType, description, mode = COMME
3636
return '';
3737
}
3838

39-
const commentValue =
40-
mode === COMMENT_MODE.remove ? 'NULL' : wrapInSingleQuotes({ name: escapeSpecialCharacters(description) });
41-
4239
return assignTemplates({
4340
template: templates.comment,
4441
templateData: {
4542
objectType,
4643
objectName: trim(objectName),
47-
comment: commentValue,
44+
comment: wrapInSingleQuotes({ name: escapeSpecialCharacters(description || '') }),
4845
},
4946
});
5047
};
@@ -121,43 +118,6 @@ const getColumnComments = ({ tableName, columnDefinitions = [] }) => {
121118
.join('\n');
122119
};
123120

124-
/**
125-
* @param {{ tableName: string, columnName: string }}
126-
* @returns {string}
127-
*/
128-
const dropColumnCommentStatement = ({ tableName, columnName }) => {
129-
const objectName = tableName + '.' + wrapInQuotes(columnName);
130-
return getCommentStatement({
131-
objectName,
132-
objectType: OBJECT_TYPE.column,
133-
mode: COMMENT_MODE.remove,
134-
});
135-
};
136-
137-
/**
138-
* @param {{ tableName: string }}
139-
* @returns {string}
140-
*/
141-
const dropTableCommentStatement = ({ tableName }) => {
142-
return getCommentStatement({
143-
objectName: tableName,
144-
objectType: OBJECT_TYPE.table,
145-
mode: COMMENT_MODE.remove,
146-
});
147-
};
148-
149-
/**
150-
* @param {{ indexName: string }}
151-
* @returns {string}
152-
*/
153-
const dropIndexCommentStatement = ({ indexName }) => {
154-
return getCommentStatement({
155-
objectName: indexName,
156-
objectType: OBJECT_TYPE.index,
157-
mode: COMMENT_MODE.remove,
158-
});
159-
};
160-
161121
/**
162122
* @param {{ schemaName: string }}
163123
* @returns {string}
@@ -178,7 +138,4 @@ module.exports = {
178138
getIndexCommentStatement,
179139

180140
dropSchemaCommentStatement,
181-
dropColumnCommentStatement,
182-
dropTableCommentStatement,
183-
dropIndexCommentStatement,
184141
};

0 commit comments

Comments
 (0)