diff --git a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/common.js b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/common.js index df2825d..21ec99b 100644 --- a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/common.js +++ b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/common.js @@ -1,5 +1,7 @@ const _ = require('lodash'); +const commentPropKey = 'comment'; + const getDifferentItems = (newItems = [], oldItems = []) => { const intersection = _.intersectionWith(newItems, oldItems, _.isEqual); return { @@ -9,25 +11,30 @@ const getDifferentItems = (newItems = [], oldItems = []) => { }; const hydrateTableProperties = ({ new: newItems, old: oldItems }, name, commentState) => { - const hydrateProperties = properties => (properties || '').split(',').map(prop => prop.trim()); const prepareProperties = properties => properties .filter(Boolean) - .map(property => property.replace(/(\S+)=([\s\S]+)/, `'$1'='$2'`)) + .map(property => `'${property.tablePropKey}'='${property.tablePropValue}'`) .join(',\n'); const isCommentChanged = !_.isEqual(commentState?.new, commentState?.old); - const addCommentProp = isCommentChanged && commentState?.new ? `comment=${commentState?.new}` : ''; - const dropCommentProp = isCommentChanged && !commentState?.new ? `comment` : ''; + + const addCommentProp = + isCommentChanged && commentState?.new + ? { tablePropKey: commentPropKey, tablePropValue: commentState?.new } + : null; + + const dropCommentProp = isCommentChanged && !commentState?.new ? { tablePropKey: commentPropKey } : null; const preparePropertiesName = properties => properties .filter(Boolean) - .map(prop => `'${prop.replace(/(=\S+)/, '')}'`) + .map(prop => `'${prop.tablePropKey}'`) .join(', '); - const newHydrateItems = hydrateProperties(newItems); - const oldHydrateItems = hydrateProperties(oldItems); + // Ensure newItems and oldItems are arrays + const newHydrateItems = Array.isArray(newItems) ? newItems : []; + const oldHydrateItems = Array.isArray(oldItems) ? oldItems : []; const { add, drop } = getDifferentItems(newHydrateItems, oldHydrateItems);