Skip to content

Commit 4c040ca

Browse files
HCK-15041: add annotations filtering for versions 12c and 18c (#241)
Co-authored-by: chulanovskyi-bs <56116665+chulanovskyi-bs@users.noreply.github.com>
1 parent 8bd9d39 commit 4c040ca

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/abstractDualityViewDdlCreator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,14 @@ class AbstractDualityViewFeDdlCreator {
183183
getCreateJsonRelationalDualityViewHeadingDdl(createViewDto, prepareName) {
184184
const { jsonSchema, view } = createViewDto;
185185
const template = this._ddlTemplates?.dualityView?.createJsonRelationalDualityViewHeading || '';
186+
const dbVersion = view?.modelInfo?.dbVersion || '';
186187

187188
const orReplaceStatement = this._getOrReplaceStatement(view);
188189
const forceStatement = this._getForceStatement(jsonSchema);
189190
const editionableStatement = this._getEditionableStatement(jsonSchema);
190191
const viewName = getViewName(view);
191192
const ddlViewName = this._getNamePrefixedWithSchemaName(viewName, view.schemaName);
192-
const annotations = getAnnotationsString(prepareName)(view.viewAnnotations);
193+
const annotations = getAnnotationsString(prepareName, dbVersion)(view.viewAnnotations);
193194

194195
const params = {
195196
orReplaceStatement,

forward_engineering/ddlProvider/ddlHelpers/tableHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = ({ getColumnsList, checkAllKeysDeactivated, commentIfDeactivate
2929
{ key: 'partitioning', getValue: getPartitioning },
3030
{ key: 'selectStatement', getValue: getBasicValue('AS') },
3131
{ key: 'tableProperties', getValue: value => _.trim(value) },
32-
{ key: 'tableAnnotations', getValue: getAnnotationsString(prepareName) },
32+
{ key: 'tableAnnotations', getValue: getAnnotationsString(prepareName, tableData?.dbVersion) },
3333
]
3434
.map(config => (tableData[config.key] ? wrap(config.getValue(tableData[config.key], tableData)) : ''))
3535
.filter(Boolean)

forward_engineering/ddlProvider/ddlProvider.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module.exports = (baseProvider, options, app) => {
143143
const emptyLineSeparator = '\n\n';
144144
const statementTerminator = ';';
145145

146-
const annotations = getAnnotationsString(prepareName)(schemaAnnotations);
146+
const annotations = getAnnotationsString(prepareName, dbVersion)(schemaAnnotations);
147147
const finalAnnotationsClause = annotations ? ' ' + annotations : '';
148148
const preparedSchemaName = prepareName(schemaName);
149149
const usingTryCatchWrapper = shouldUseTryCatchIfNotExistsWrapper(dbVersion);
@@ -226,8 +226,9 @@ module.exports = (baseProvider, options, app) => {
226226
},
227227

228228
convertColumnDefinition(columnDefinition, template = templates.columnDefinition) {
229-
const type = replaceTypeByVersion(columnDefinition.type, columnDefinition.dbVersion);
230-
const annotations = getAnnotationsString(prepareName)(columnDefinition.columnAnnotations);
229+
const dbVersion = columnDefinition?.dbVersion;
230+
const type = replaceTypeByVersion(columnDefinition.type, dbVersion);
231+
const annotations = getAnnotationsString(prepareName, dbVersion)(columnDefinition.columnAnnotations);
231232
const finalAnnotationsClause = annotations ? ' ' + annotations : '';
232233

233234
return commentIfDeactivated(
@@ -484,6 +485,7 @@ module.exports = (baseProvider, options, app) => {
484485
selectStatement,
485486
tableProperties,
486487
tableAnnotations,
488+
dbVersion,
487489
}),
488490
});
489491
if (usingTryCatchWrapper) {
@@ -514,7 +516,7 @@ module.exports = (baseProvider, options, app) => {
514516
const dbVersion = options.dbVersion || '';
515517
const usingTryCatchWrapper = shouldUseTryCatchIfNotExistsWrapper(dbVersion);
516518

517-
const annotations = getAnnotationsString(prepareName)(index.indexAnnotations);
519+
const annotations = getAnnotationsString(prepareName, dbVersion)(index.indexAnnotations);
518520
const finalAnnotationsClause = annotations ? ' ' + annotations : '';
519521

520522
const shouldInsertIfNotExistsStatement = index.ifNotExist && !usingTryCatchWrapper;
@@ -668,7 +670,7 @@ module.exports = (baseProvider, options, app) => {
668670
const dbVersion = _.get(viewData, 'modelInfo.dbVersion', '');
669671
const usingTryCatchWrapper = shouldUseTryCatchIfNotExistsWrapper(dbVersion);
670672

671-
const annotations = getAnnotationsString(prepareName)(viewData.viewAnnotations);
673+
const annotations = getAnnotationsString(prepareName, dbVersion)(viewData.viewAnnotations);
672674

673675
let createViewDdl = assignTemplates(templates.createView, {
674676
name: viewName,

forward_engineering/utils/getAnnotationsString.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ const { wrapComment } = require('./general');
77
* }} Annotation
88
*/
99

10+
const UNSUPPORTED_DB_VERSIONS = new Set(['12c', '18c']);
11+
1012
/**
1113
* Generates annotations string.
12-
* @param {function} prepareName
14+
* @param {function} prepareName - Function to format/escape identifiers
15+
* @param {string} [dbVersion] - Database version
1316
* @returns {(annotations: Annotation[]) => string} - returns Annotations string (e.g: "\nANNOTATIONS (...)") or ''.
1417
*/
15-
const getAnnotationsString = prepareName => annotations => {
18+
const getAnnotationsString = (prepareName, dbVersion) => annotations => {
19+
if (!dbVersion || UNSUPPORTED_DB_VERSIONS.has(dbVersion)) {
20+
return '';
21+
}
22+
1623
if (!Array.isArray(annotations) || annotations.length === 0) {
1724
return '';
1825
}

0 commit comments

Comments
 (0)