From c913f76534985cadaa165174a20737e470746786 Mon Sep 17 00:00:00 2001 From: Alik Rakhmonov Date: Thu, 18 Dec 2025 16:11:01 +0100 Subject: [PATCH 1/3] HCK-14046: invalid constraint name --- .../hiveHelpers/helpers/alterScriptHelpers/generalHelper.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js index 3032705..e307094 100644 --- a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js +++ b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js @@ -48,9 +48,9 @@ const hydrateProperty = (entity, compMod, nameProperty) => { const getDefaultConstraintName = ({ collection, column = {}, postfix }) => { const entityData = collection?.role || {}; - const entityName = prepareName(getName(entityData)); - const columnName = prepareName(getName(column)); - return [entityName, columnName, postfix].filter(Boolean).join('_'); + const entityName = getName(entityData); + const columnName = getName(column); + return prepareName([entityName, columnName, postfix].filter(Boolean).join('_')); }; module.exports = { From 6cbd27ecd1f47e96da9e45f4a2586727f23d0196 Mon Sep 17 00:00:00 2001 From: chulanovskyi Date: Thu, 18 Dec 2025 17:40:38 +0200 Subject: [PATCH 2/3] fix: normalized name escaping --- .../helpers/alterScriptHelpers/generalHelper.js | 2 +- .../hiveHelpers/helpers/columnHelper.js | 11 ++++++++--- .../hiveHelpers/helpers/tableHelper.js | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js index e307094..c96a7ed 100644 --- a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js +++ b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/generalHelper.js @@ -47,7 +47,7 @@ const hydrateProperty = (entity, compMod, nameProperty) => { }; const getDefaultConstraintName = ({ collection, column = {}, postfix }) => { - const entityData = collection?.role || {}; + const entityData = collection?.role || collection || {}; const entityName = getName(entityData); const columnName = getName(column); return prepareName([entityName, columnName, postfix].filter(Boolean).join('_')); diff --git a/forward_engineering/hiveHelpers/helpers/columnHelper.js b/forward_engineering/hiveHelpers/helpers/columnHelper.js index 13ea2f9..837f2bd 100644 --- a/forward_engineering/hiveHelpers/helpers/columnHelper.js +++ b/forward_engineering/hiveHelpers/helpers/columnHelper.js @@ -297,8 +297,8 @@ const getTypeByProperty = } }; -const getColumn = (name, type, comment, constraints, isActivated) => ({ - [name]: { type, comment, constraints, isActivated }, +const getColumn = (name, type, comment, constraints, isActivated, originalName) => ({ + [name]: { type, comment, constraints, isActivated, originalName }, }); const getColumns = (jsonSchema, areColumnConstraintsAvailable, definitions) => { @@ -333,6 +333,7 @@ const getColumns = (jsonSchema, areColumnConstraintsAvailable, definitions) => { } : {}, property.isActivated, + name, ), }; }, {}); @@ -408,7 +409,11 @@ const getColumnConstraintsStatement = ({ collection, column, isAlterScript }) => getConstraintOpts({ rely, enableSpecification, noValidateSpecification }); const getConstraint = ({ statement, postfix, noValidate, skipName = false }) => { - const constraintName = getDefaultConstraintName({ collection, column, postfix }); + const constraintName = getDefaultConstraintName({ + collection, + column: { ...column, name: column.originalName }, + postfix, + }); const columnName = skipName ? '' : ` (${column.name})`; return `CONSTRAINT ${constraintName} ${statement}${columnName} ${noValidate}`; }; diff --git a/forward_engineering/hiveHelpers/helpers/tableHelper.js b/forward_engineering/hiveHelpers/helpers/tableHelper.js index 57d9670..2b4fd76 100644 --- a/forward_engineering/hiveHelpers/helpers/tableHelper.js +++ b/forward_engineering/hiveHelpers/helpers/tableHelper.js @@ -80,7 +80,7 @@ const getPrimaryKeyStatement = (jsonSchema, keysNames, deactivatedColumnNames, i rely, enableSpecification: 'DISABLE', }); - const constraintNameStatement = constraintName ? `CONSTRAINT ${constraintName} ` : ''; + const constraintNameStatement = constraintName ? `CONSTRAINT ${prepareName(constraintName)} ` : ''; const getStatement = keys => `${constraintNameStatement}PRIMARY KEY (${keys})${constraintOptsStatement}`; From 74445c5e6378fb372db97fa04879fdf3154e76e9 Mon Sep 17 00:00:00 2001 From: chulanovskyi Date: Thu, 18 Dec 2025 18:06:47 +0200 Subject: [PATCH 3/3] fix: normalized name escaping (part 2) --- .../helpers/alterScriptHelpers/uniqueKeyHelper.js | 8 ++++---- .../hiveHelpers/helpers/constraintHelper.js | 9 +++++---- .../hiveHelpers/helpers/foreignKeyHelper.js | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/uniqueKeyHelper.js b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/uniqueKeyHelper.js index ad08a60..3237d72 100644 --- a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/uniqueKeyHelper.js +++ b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/uniqueKeyHelper.js @@ -39,9 +39,9 @@ const getDropCompositeUkScripts = ({ collection, provider }) => { const oldUniqueKeys = pkDto.old || []; return oldUniqueKeys.map(oldUk => { - const pkConstraintName = + const ukConstraintName = oldUk.constraintName || getDefaultConstraintName({ collection, postfix: CONSTRAINT_POSTFIX.uniqueKey }); - const constraintName = prepareName(pkConstraintName); + const constraintName = prepareName(ukConstraintName); return provider.assignTemplates(templates.dropConstraint, { tableName, @@ -65,9 +65,9 @@ const getAddCompositeUkScripts = ({ collection, provider }) => { const compositeUniqueKey = newUk.compositeUniqueKey || []; const guidsOfColumnsInUk = compositeUniqueKey.map(compositeUkEntry => compositeUkEntry.keyId); const columnNames = getPropertiesNamesByGUIDs(collection, guidsOfColumnsInUk); - const pkConstraintName = + const ukConstraintName = newUk.constraintName || getDefaultConstraintName({ collection, postfix: CONSTRAINT_POSTFIX.uniqueKey }); - const constraintName = prepareName(pkConstraintName); + const constraintName = prepareName(ukConstraintName); const noValidate = newUk.noValidateSpecification ? ` ${newUk.noValidateSpecification}` : ''; const rely = newUk.rely ? ` ${newUk.rely}` : ''; diff --git a/forward_engineering/hiveHelpers/helpers/constraintHelper.js b/forward_engineering/hiveHelpers/helpers/constraintHelper.js index 6a77ef9..bc3d303 100644 --- a/forward_engineering/hiveHelpers/helpers/constraintHelper.js +++ b/forward_engineering/hiveHelpers/helpers/constraintHelper.js @@ -3,6 +3,7 @@ * @typedef {import('../types').ConstraintDto} ConstraintDto * @typedef {import('../types').JsonSchema} JsonSchema */ +const { prepareName } = require('./generalHelper'); const findName = (keyId, properties) => { return Object.keys(properties).find(name => properties[name].GUID === keyId); @@ -48,7 +49,7 @@ const getConstraintOpts = ({ noValidateSpecification, enableSpecification, rely const getUniqueKeyStatement = (jsonSchema, isParentItemActivated) => { const getStatement = ({ keys, name, constraintOptsStatement }) => - `CONSTRAINT ${name} UNIQUE (${keys})${constraintOptsStatement}`; + `CONSTRAINT ${prepareName(name)} UNIQUE (${keys})${constraintOptsStatement}`; const getColumnsName = columns => columns.map(column => column.name).join(', '); const hydratedUniqueKeys = hydrateUniqueKeys(jsonSchema); @@ -84,7 +85,7 @@ const getUniqueKeyStatement = (jsonSchema, isParentItemActivated) => { const getCheckConstraint = jsonSchema => { const checks = jsonSchema.chkConstr || []; const createCheckStatement = ({ constraintName, checkExpression, constraintOptsStatement }) => - `CONSTRAINT ${constraintName} CHECK (${checkExpression})${constraintOptsStatement}`; + `CONSTRAINT ${prepareName(constraintName)} CHECK (${checkExpression})${constraintOptsStatement}`; const checkConstraint = checks.map(check => { const { constraintName, rely, noValidateSpecification, enableSpecification, checkExpression } = check || {}; @@ -111,7 +112,7 @@ const getCompositePrimaryKeys = ({ jsonSchema }) => { .filter(primaryKey => primaryKey.compositePrimaryKey?.length) .map(primaryKey => ({ keyType: 'PRIMARY KEY', - name: primaryKey.constraintName, + name: prepareName(primaryKey.constraintName), columns: getKeys(primaryKey.compositePrimaryKey, jsonSchema), })); }; @@ -129,7 +130,7 @@ const getCompositeUniqueKeys = ({ jsonSchema }) => { .filter(uniqueKey => uniqueKey.compositeUniqueKey?.length) .map(uniqueKey => ({ keyType: 'UNIQUE', - name: uniqueKey.constraintName, + name: prepareName(uniqueKey.constraintName), columns: getKeys(uniqueKey.compositeUniqueKey, jsonSchema), })); }; diff --git a/forward_engineering/hiveHelpers/helpers/foreignKeyHelper.js b/forward_engineering/hiveHelpers/helpers/foreignKeyHelper.js index 4142516..ccca33b 100644 --- a/forward_engineering/hiveHelpers/helpers/foreignKeyHelper.js +++ b/forward_engineering/hiveHelpers/helpers/foreignKeyHelper.js @@ -116,7 +116,7 @@ const getForeignKeyConstraint = ({ parentColumns, disableNoValidate, }) => { - const constraintNameStatement = constraintName ? `CONSTRAINT ${constraintName} ` : ''; + const constraintNameStatement = constraintName ? `CONSTRAINT ${prepareName(constraintName)} ` : ''; const statement = `,${constraintNameStatement}FOREIGN KEY (${childColumns}) REFERENCES ${parentTableName}(${parentColumns}) ${disableNoValidate ? 'DISABLE NOVALIDATE' : ''}`; return statement; };