Skip to content

Commit

Permalink
HCK-9310: do not FE table property if the property value is not defin…
Browse files Browse the repository at this point in the history
…ed (#248)

* HCK-9310: do not FE table property if the property value is not defined

* HCK-9310: fix TBLPROPERTIES in alter script

---------

Co-authored-by: Serhii Filonenko <[email protected]>
  • Loading branch information
Vitalii4as and serhii-filonenko authored Jan 2, 2025
1 parent 1fb3a72 commit 1824b8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash');
const { DiffMap } = require('../../types/DiffMap');
const { getTablePropertiesClause } = require('../../../helpers/tableHelper');
const { getTablePropertiesClause, getDeleteTablePropertiesClause } = require('../../../helpers/tableHelper');
const { AlterScriptDto } = require('../../types/AlterScriptDto');
const { generateFullEntityName } = require('../../../utils/general');

Expand Down Expand Up @@ -54,7 +54,7 @@ const getDeleteTablePropertyScriptDto = ddlProvider => (properties, fullCollecti
...prop,
propertyValue: undefined,
}));
const dropPropertiesDdlString = getTablePropertiesClause(propertiesWithNoValues);
const dropPropertiesDdlString = getDeleteTablePropertiesClause(propertiesWithNoValues);
const ddlConfig = {
name: fullCollectionName,
properties: dropPropertiesDdlString,
Expand Down
21 changes: 15 additions & 6 deletions forward_engineering/helpers/tableHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,9 @@ const getCorrectUsing = using => {
const getTablePropertiesClause = tableProperties => {
const isText = _.overEvery([value => _.isNaN(_.toNumber(value)), value => value !== 'true' && value !== 'false']);
const tablePropertyStatements = (tableProperties || [])
.filter(({ propertyKey }) => Boolean(adjustPropertyKey(propertyKey)))
.map(({ propertyKey, propertyValue = undefined }) => {
.filter(({ propertyKey, propertyValue }) => propertyKey?.trim?.() && propertyValue?.trim?.())
.map(({ propertyKey, propertyValue }) => {
let value = propertyValue;
if (value === undefined) {
return propertyKey;
}
if (isText(value)) {
value = `'${adjustPropertyValue(value)}'`;
}
Expand All @@ -552,8 +549,19 @@ const getTablePropertiesClause = tableProperties => {
return tablePropertyStatements.join(', ');
};

const getDeleteTablePropertiesClause = tableProperties => {
const tablePropertyStatements = (tableProperties || [])
.filter(({ propertyKey }) => propertyKey?.trim?.())
.map(({ propertyKey }) => adjustPropertyKey(propertyKey));

return tablePropertyStatements.join(', ');
};

const checkTablePropertiesDefined = tableProperties => {
return Boolean(tableProperties?.length && tableProperties?.some(property => property.propertyKey));
return Boolean(
tableProperties?.length &&
tableProperties?.some(property => property.propertyKey?.trim?.() && property.propertyValue?.trim?.()),
);
};

const hydrateTableProperties = ({ new: newItems, old: oldItems }, name) => {
Expand Down Expand Up @@ -587,4 +595,5 @@ module.exports = {
getTablePropertiesClause,
hydrateTableProperties,
checkTablePropertiesDefined,
getDeleteTablePropertiesClause,
};

0 comments on commit 1824b8b

Please sign in to comment.