Skip to content

Commit

Permalink
Merge branch 'main' into feature/HCK-4585
Browse files Browse the repository at this point in the history
  • Loading branch information
chulanovskyi-bs authored Mar 5, 2024
2 parents 91371cc + ce2cdac commit 90c6c42
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ const getModifyContainerScriptDtos = (provider, _, isUnityCatalogSupports, dbVer
const alterCommentsScriptDtos = getAlterCommentsScriptDtos(provider)(container);
const alterDatabaseScript = getDatabaseAlterStatement([containerData], dbVersion);
const alterDatabaseScriptDto = AlterScriptDto.getInstance([alterDatabaseScript], true, false)
const alterUnityCatalogTagsScript = getModifyUnityCatalogTagsScriptDtos(provider)(container, catalogName);
const alterUnitySchemaTagsScript = getModifyUnitySchemaTagsScriptDtos({ ddlProvider: provider })({
entityData: container,
name: fullDatabaseName,
});
const alterUnityCatalogTagsScript = getModifyUnityCatalogTagsScriptDtos({ ddlProvider: provider })({ entityData: container, name: catalogName });
const alterUnitySchemaTagsScript = getModifyUnitySchemaTagsScriptDtos({ ddlProvider: provider })({
entityData: container,
name: fullDatabaseName,
});

if (!alterDatabaseScript?.length) {
return [...alterCommentsScriptDtos, ...alterUnityCatalogTagsScript, ...alterUnitySchemaTagsScript];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const {getColumns, getColumnsStatement} = require("../../../helpers/columnHelper");
const {getEntityProperties, generateFullEntityName, prepareName} = require("../../../utils/general");
const {getEntityProperties, generateFullEntityName, prepareName, getDBVersionNumber} = require("../../../utils/general");
const {getIndexes} = require("../../../helpers/indexHelper");
const {AlterScriptDto} = require("../../types/AlterScriptDto");
const {hydrateIndex} = require("./indexHelper");
const {generateModifyCollectionScript} = require("./modifyCollectionScript");
const { Runtime } = require("../../../enums/runtime");
const { getColumnTagsStatement } = require("../../../helpers/unityTagsHelper");

/**
* @typedef {{
Expand Down Expand Up @@ -69,27 +71,29 @@ const getAddColumnsScriptsForModifyModifyCollectionScript = (_, provider) => (en
const addIndexScript = getIndexes(_)(...hydratedAddIndex);
const addColumnScript = provider.addTableColumns({name: fullCollectionName, columns: columnStatement});

const isUnityTagsSupported = getDBVersionNumber(dbVersion) >= Runtime.MINIMUM_UNITY_TAGS_SUPPORT_VERSION
const columnsUnityTagsScript = isUnityTagsSupported ? getColumnTagsStatement(_, properties, fullCollectionName) : [];
const addColumnScriptWithUnityTags = isUnityTagsSupported ? [addColumnScript, ...columnsUnityTagsScript].join('\n') : addColumnScript;

const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true);
const addIndexScriptDto = AlterScriptDto.getInstance([addIndexScript], true, false);
const addColumnScriptDto = AlterScriptDto.getInstance([addColumnScript], true, false);
const addColumnScriptDto = AlterScriptDto.getInstance([addColumnScriptWithUnityTags], true, false);
const notNullConstraintScriptDtos = getAddNotNullConstraintScriptDtos(_, provider)({ collection: entity, columns, dbVersion });

return [
dropIndexScriptDto,
addColumnScriptDto,
...notNullConstraintScriptDtos,
...(modifyScript.script || []),
addIndexScriptDto
]
.filter(Boolean);
dropIndexScriptDto,
addColumnScriptDto,
...notNullConstraintScriptDtos,
...(modifyScript.script || []),
addIndexScriptDto,
].filter(Boolean);
}

const getAddColumnsScriptsForNewModifyCollectionScript = (_, provider) => (entity, definitions, modifyScript, dbVersion) => {
const properties = getEntityProperties(entity);
const {hydratedAddIndex, hydratedDropIndex} = hydrateIndex(_)({ entity, properties, definitions, dbVersion });
const dropIndexScript = provider.dropTableIndex(hydratedDropIndex);
const addIndexScript = getIndexes(_)(...hydratedAddIndex);

const dropIndexScriptDto = AlterScriptDto.getInstance([dropIndexScript], true, true);
const addIndexScriptDto = AlterScriptDto.getInstance([addIndexScript], true, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto');
* @param ddlProvider {Object}
* @returns {GetAlterScriptDtoFunction}
*/
const getSetUnityEntityTagsDtos = ({ ddlProvider }) => ({ entityData, entityName }) => {
const getSetUnityEntityTagsDtos = ({ ddlProvider }) => ({ entityData, name }) => {
const unityTags = entityData?.role?.compMod?.unityEntityTags || {};
const newUnityTags = unityTags.new || [];
const oldUnityTags = unityTags.old || [];
Expand All @@ -29,7 +29,7 @@ const getSetUnityEntityTagsDtos = ({ ddlProvider }) => ({ entityData, entityName
return [];
}

const script = ddlProvider.setEntityTags({name: entityName, tags: buildTagPairs(setTags) });
const script = ddlProvider.setEntityTags({name, tags: buildTagPairs(setTags) });

return [AlterScriptDto.getInstance([script], true, false)];
};
Expand All @@ -38,7 +38,7 @@ const getSetUnityEntityTagsDtos = ({ ddlProvider }) => ({ entityData, entityName
* @param ddlProvider {Object}
* @returns {GetAlterScriptDtoFunction}
*/
const getUnsetUnityEntityTagsScriptsDtosFrom = ({ ddlProvider }) => ({ entityData, entityName }) => {
const getUnsetUnityEntityTagsScriptsDtosFrom = ({ ddlProvider }) => ({ entityData, name }) => {
const unityTags = entityData?.role?.compMod?.unityEntityTags || {};
const newUnityTags = unityTags.new || [];
const oldUnityTags = unityTags.old || [];
Expand All @@ -49,7 +49,7 @@ const getUnsetUnityEntityTagsScriptsDtosFrom = ({ ddlProvider }) => ({ entityDat
return [];
}

const script = ddlProvider.unsetEntityTags({ name: entityName, tags: getUnsetTagsNamesParamString({ unsetTags }) });
const script = ddlProvider.unsetEntityTags({ name, tags: getUnsetTagsNamesParamString({ unsetTags }) });

return [AlterScriptDto.getInstance([script], true, true)];
};
Expand All @@ -58,12 +58,12 @@ const getUnsetUnityEntityTagsScriptsDtosFrom = ({ ddlProvider }) => ({ entityDat
* @param ddlProvider {Object}
* @returns {GetAlterScriptDtoFunction}
*/
const getModifyUnityEntityTagsScriptDtos = ({ ddlProvider }) => ({ entityData, entityName }) => {
const getModifyUnityEntityTagsScriptDtos = ({ ddlProvider }) => ({ entityData, name }) => {
const unsetUnityTagsScriptDtosFromTable = getUnsetUnityEntityTagsScriptsDtosFrom({ ddlProvider })({
entityData,
entityName,
name,
});
const setUnityTagsScriptDtosFromTable = getSetUnityEntityTagsDtos({ ddlProvider })({ entityData, entityName });
const setUnityTagsScriptDtosFromTable = getSetUnityEntityTagsDtos({ ddlProvider })({ entityData, name });

return [...unsetUnityTagsScriptDtosFromTable, ...setUnityTagsScriptDtosFromTable].filter(Boolean);
};
Expand Down
5 changes: 2 additions & 3 deletions forward_engineering/helpers/unityTagsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ const getViewTagsStatement = (viewSchema, viewName) => {
};

/**
* @param {UnityTag[]} unsetTags
* @param {{unsetTags: UnityTag[]}} param
* @returns {string}
*/
const getUnsetTagsNamesParamString = ({ unsetTags }) => {
return unsetTags.map(({ unityTagKey }) => wrapInSingleQuotes(unityTagKey)).join(', ');
};

/**
* @param {UnityTag[]} tagsToFilter
* @param {UnityTag[]} filterBy
* @param {{tagsToFilter: UnityTag[], filterBy: UnityTag[]}} param
* @returns {UnityTag[]}
*/
const getUnityTagsFromCompMod = ({ tagsToFilter, filterBy }) => {
Expand Down

0 comments on commit 90c6c42

Please sign in to comment.