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; };