From 895e245d278145e5e9d2da85babc7e7df2b64b8e Mon Sep 17 00:00:00 2001 From: Serhii Filonenko <91055067+serhii-filonenko@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:14:10 +0300 Subject: [PATCH] HCK-7861, HCK-7862, HCK-7866: fix generating tags clause if tag has empty 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 <71256742+Vitalii4as@users.noreply.github.com> --- forward_engineering/ddlProvider.js | 4 ++-- forward_engineering/helpers/tagHelper.js | 26 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index c796071d..b39d1061 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -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, @@ -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', diff --git a/forward_engineering/helpers/tagHelper.js b/forward_engineering/helpers/tagHelper.js index 64e48b1d..fadf68ef 100644 --- a/forward_engineering/helpers/tagHelper.js +++ b/forward_engineering/helpers/tagHelper.js @@ -10,7 +10,7 @@ module.exports = ({ getName, toString }) => { * @returns {string} */ const getTagStatement = ({ tags, isCaseSensitive, indent = ' ' }) => { - if (isEmpty(tags)) { + if (isEmptyTags({ tags })) { return ''; } @@ -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}`; }; /** @@ -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}`; }; @@ -114,6 +113,14 @@ module.exports = ({ getName, toString }) => { }; }; + /** + * @param {{ tags: ObjectTag[] }} + * @returns {boolean} + */ + const isEmptyTags = ({ tags }) => { + return isEmpty(tags) || tags.every(tag => !tag.tagName); + }; + return { getTagStatement, getTagAllowedValues, @@ -121,5 +128,6 @@ module.exports = ({ getName, toString }) => { prepareObjectTagsData, getSetTagValue, getUnsetTagValue, + isEmptyTags, }; };