Skip to content

Commit

Permalink
HCK-7861, HCK-7862, HCK-7866: fix generating tags clause if tag has e…
Browse files Browse the repository at this point in the history
…mpty name (#142)

* HCK-7861: fix generating tag clause if tag has no name

* HCK-7862: fix tag name quoting in unset clause

---------

Co-authored-by: Vitalii Yarmus <[email protected]>
  • Loading branch information
serhii-filonenko and Vitalii4as authored Sep 6, 2024
1 parent 8b1cfd4 commit 895e245
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = (baseProvider, options, app) => {
tab,
});

const { getTagStatement, getTagAllowedValues, getTagKeyValues, prepareObjectTagsData } =
const { getTagStatement, getTagAllowedValues, getTagKeyValues, prepareObjectTagsData, isEmptyTags } =
require('./helpers/tagHelper')({
getName,
toString,
Expand Down Expand Up @@ -233,7 +233,7 @@ module.exports = (baseProvider, options, app) => {
this.createTag({ tag, schemaName: currentSchemaName, isCaseSensitive }),
);

if (!_.isEmpty(schemaTags)) {
if (!isEmptyTags({ tags: schemaTags })) {
const schemaTagStatement = assignTemplates(templates.alterSchema, {
name: fullName,
operation: 'SET TAG',
Expand Down
26 changes: 17 additions & 9 deletions forward_engineering/helpers/tagHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = ({ getName, toString }) => {
* @returns {string}
*/
const getTagStatement = ({ tags, isCaseSensitive, indent = ' ' }) => {
if (isEmpty(tags)) {
if (isEmptyTags({ tags })) {
return '';
}

Expand All @@ -23,14 +23,13 @@ module.exports = ({ getName, toString }) => {
* @param {{ allowedValues: string[] }}
* @returns {string}
*/
const getTagAllowedValues = ({ allowedValues }) => {
if (isEmpty(allowedValues)) {
return '';
}

const values = allowedValues.map(({ value }) => toString(value)).join(', ');
const getTagAllowedValues = ({ allowedValues = [] }) => {
const values = allowedValues
.filter(({ value }) => value)
.map(({ value }) => toString(value))
.join(', ');

return ` ALLOWED_VALUES ${values}`;
return isEmpty(values) ? '' : ` ALLOWED_VALUES ${values}`;
};

/**
Expand Down Expand Up @@ -83,7 +82,7 @@ module.exports = ({ getName, toString }) => {
return '';
}

const tagNames = droppedTags.map(({ tagName }) => tagName).join(', ');
const tagNames = droppedTags.map(({ tagName }) => getTagName({ tagName, isCaseSensitive })).join(', ');

return `TAG ${tagNames}`;
};
Expand Down Expand Up @@ -114,12 +113,21 @@ module.exports = ({ getName, toString }) => {
};
};

/**
* @param {{ tags: ObjectTag[] }}
* @returns {boolean}
*/
const isEmptyTags = ({ tags }) => {
return isEmpty(tags) || tags.every(tag => !tag.tagName);
};

return {
getTagStatement,
getTagAllowedValues,
getTagKeyValues,
prepareObjectTagsData,
getSetTagValue,
getUnsetTagValue,
isEmptyTags,
};
};

0 comments on commit 895e245

Please sign in to comment.