diff --git a/forward_engineering/alterScript/alterScriptFromDeltaHelper.js b/forward_engineering/alterScript/alterScriptFromDeltaHelper.js index 031242a..0b1f348 100644 --- a/forward_engineering/alterScript/alterScriptFromDeltaHelper.js +++ b/forward_engineering/alterScript/alterScriptFromDeltaHelper.js @@ -38,6 +38,7 @@ const { getDeleteContainerSequencesScriptDtos, getAddContainerSequencesScriptDtos, } = require('./alterScriptHelpers/containerHelpers/sequencesHelper'); +const { isObjectInDeltaModelActivated } = require('../utils/general'); /** * @param dto {{ @@ -53,12 +54,20 @@ const getAlterContainersScriptDtos = ({ collection }) => { const addContainersScriptDtos = [] .concat(addedContainers) .filter(Boolean) - .map(container => getAddContainerScriptDto(Object.keys(container.properties)[0])); + .map(container => { + const [containerName, containerData] = Object.entries(container.properties)[0]; + const isActivated = isObjectInDeltaModelActivated(containerData); + return getAddContainerScriptDto(containerName, isActivated); + }); const deleteContainersScriptDtos = [] .concat(deletedContainers) .filter(Boolean) - .map(container => getDeleteContainerScriptDto(Object.keys(container.properties)[0])); + .map(container => { + const [containerName, containerData] = Object.entries(container.properties)[0]; + const isActivated = isObjectInDeltaModelActivated(containerData); + return getDeleteContainerScriptDto(containerName, isActivated); + }); const modifyContainersScriptDtos = [] .concat(modifiedContainers) diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js index 77c58e0..22bc589 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js @@ -29,20 +29,22 @@ const dropSchema = schemaName => { /** * @param {string} containerName + * @param {boolean} isActivated * @return {AlterScriptDto | undefined} * */ -const getAddContainerScriptDto = containerName => { +const getAddContainerScriptDto = (containerName, isActivated = true) => { const script = createSchemaOnly(wrapInQuotes(containerName)); - return AlterScriptDto.getInstance([script], true, false); + return AlterScriptDto.getInstance([script], isActivated, false); }; /** * @param {string} containerName + * @param {boolean} isActivated * @return {AlterScriptDto | undefined} * */ -const getDeleteContainerScriptDto = containerName => { +const getDeleteContainerScriptDto = (containerName, isActivated = true) => { const script = dropSchema(wrapInQuotes(containerName)); - return AlterScriptDto.getInstance([script], true, true); + return AlterScriptDto.getInstance([script], isActivated, true); }; /** diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index adcaa9b..899767d 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js @@ -15,7 +15,14 @@ const { getAdditionalDataForDdlProvider, } = require('./entityHelpers/indexesHelper'); const { getModifiedDefaultColumnValueScriptDtos } = require('./columnHelpers/defaultValueHelper'); -const { getEntityName, getFullTableName, getNamePrefixedWithSchemaName, wrapInQuotes } = require('../../utils/general'); +const { + getEntityName, + getFullTableName, + getNamePrefixedWithSchemaName, + wrapInQuotes, + isParentContainerActivated, + isObjectInDeltaModelActivated, +} = require('../../utils/general'); /** * @return {(collection: AlterCollectionDto) => AlterScriptDto | undefined} @@ -124,6 +131,9 @@ const getAddColumnsByConditionScriptDtos = const fullName = getNamePrefixedWithSchemaName(tableName, schemaName); const schemaData = { schemaName, dbVersion }; + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); + const scripts = _.toPairs(collection.properties) .filter(([name, jsonSchema]) => predicate([name, jsonSchema])) .map(([name, jsonSchema]) => { @@ -134,7 +144,7 @@ const getAddColumnsByConditionScriptDtos = externalDefinitions, }); - return createColumnDefinitionBySchema({ + const columnDefinition = createColumnDefinitionBySchema({ name, jsonSchema, parentJsonSchema: collectionSchema, @@ -142,10 +152,14 @@ const getAddColumnsByConditionScriptDtos = schemaData, definitionJsonSchema, }); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { columnDefinition, isActivated }; }) - .map(ddlProvider.convertColumnDefinition) - .map(columnDefinition => ddlProvider.addColumn(fullName, columnDefinition)) - .map(addColumnScript => AlterScriptDto.getInstance([addColumnScript], true, false)); + .map(({ columnDefinition, isActivated }) => ({ + script: ddlProvider.addColumn(fullName, ddlProvider.convertColumnDefinition(columnDefinition)), + isActivated, + })) + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false)); return scripts.filter(Boolean); }; @@ -204,13 +218,17 @@ const getDeleteColumnsByConditionScriptDtos = app => (collection, predicate) => const schemaName = collectionSchema.compMod?.keyspaceName; const fullTableName = getNamePrefixedWithSchemaName(tableName, schemaName); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); + return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => predicate([name, jsonSchema])) - .map(([name]) => { + .map(([name, jsonSchema]) => { const columnNameForDDL = wrapInQuotes(name); - return ddlProvider.dropColumn(fullTableName, columnNameForDDL); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: ddlProvider.dropColumn(fullTableName, columnNameForDDL), isActivated }; }) - .map(dropColumnScript => AlterScriptDto.getInstance([dropColumnScript], true, true)) + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, true)) .filter(Boolean); }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js index af43cd8..815149e 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js @@ -1,6 +1,11 @@ const _ = require('lodash'); const { AlterScriptDto } = require('../types/AlterScriptDto'); -const { getUdtName, wrapInQuotes, checkFieldPropertiesChanged } = require('../../utils/general'); +const { + getUdtName, + wrapInQuotes, + checkFieldPropertiesChanged, + isObjectInDeltaModelActivated, +} = require('../../utils/general'); /** * @return {(jsonSchema: Object) => AlterScriptDto | undefined} @@ -44,7 +49,7 @@ const getCreateUdtScriptDto = const udt = { ...updatedUdt, properties: columnDefinitions }; const script = ddlProvider.createUdt(udt); - return AlterScriptDto.getInstance([script], true, false); + return AlterScriptDto.getInstance([script], jsonSchema.isActivated, false); }; /** @@ -56,10 +61,10 @@ const getDeleteUdtScriptDto = app => udt => { const ddlUdtName = wrapInQuotes(getUdtName(udt)); if (udt.type === 'domain') { const script = ddlProvider.dropDomain(ddlUdtName); - return AlterScriptDto.getInstance([script], true, true); + return AlterScriptDto.getInstance([script], udt.isActivated, true); } else { const script = ddlProvider.dropType(ddlUdtName); - return AlterScriptDto.getInstance([script], true, true); + return AlterScriptDto.getInstance([script], udt.isActivated, true); } }; @@ -97,7 +102,7 @@ const getAddColumnToTypeScriptDtos = }) .map(ddlProvider.convertColumnDefinition) .map(columnDefinition => ddlProvider.alterTypeAddAttribute(fullName, columnDefinition)) - .map(script => AlterScriptDto.getInstance([script], true, false)) + .map(script => AlterScriptDto.getInstance([script], udt.isActivated, false)) .filter(Boolean); }; @@ -108,11 +113,12 @@ const getDeleteColumnFromTypeScriptDtos = app => udt => { const ddlProvider = require('../../ddlProvider/ddlProvider')(null, null, app); const fullName = wrapInQuotes(udt.code || udt.name); + const isActivated = isObjectInDeltaModelActivated(udt); return _.toPairs(udt.properties) .filter(([name, jsonSchema]) => !jsonSchema.compMod) .map(([name]) => ddlProvider.alterTypeDropAttribute(fullName, wrapInQuotes(name))) - .map(script => AlterScriptDto.getInstance([script], true, true)) + .map(script => AlterScriptDto.getInstance([script], isActivated, true)) .filter(Boolean); }; @@ -123,6 +129,7 @@ const getModifyColumnOfTypeScriptDtos = app => udt => { const ddlProvider = require('../../ddlProvider/ddlProvider')(null, null, app); const fullName = wrapInQuotes(udt.code || udt.name); + const isActivated = isObjectInDeltaModelActivated(udt); const renameColumnScripts = _.values(udt.properties) .filter(jsonSchema => checkFieldPropertiesChanged(jsonSchema.compMod, ['name'])) @@ -131,7 +138,7 @@ const getModifyColumnOfTypeScriptDtos = app => udt => { const newAttributeDDLName = wrapInQuotes(jsonSchema.compMod.newField.name); return ddlProvider.alterTypeRenameAttribute(fullName, oldAttributeDDLName, newAttributeDDLName); }) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(script => AlterScriptDto.getInstance([script], isActivated, false)); const changeTypeScripts = _.toPairs(udt.properties) .filter(([name, jsonSchema]) => checkFieldPropertiesChanged(jsonSchema.compMod, ['type', 'mode'])) @@ -140,7 +147,7 @@ const getModifyColumnOfTypeScriptDtos = app => udt => { const newDataType = jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type; return ddlProvider.alterTypeChangeAttributeType(fullName, attributeDDLName, newDataType); }) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(script => AlterScriptDto.getInstance([script], isActivated, false)); return [...renameColumnScripts, ...changeTypeScripts].filter(Boolean); }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js index ead25ee..767e71c 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js @@ -1,6 +1,12 @@ const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { checkFieldPropertiesChanged, getFullTableName, wrapInQuotes } = require('../../../utils/general'); +const { + checkFieldPropertiesChanged, + getFullTableName, + wrapInQuotes, + isObjectInDeltaModelActivated, + isParentContainerActivated, +} = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -63,6 +69,8 @@ const hasPrecisionOrScaleChanged = (collection, oldFieldName, currentJsonSchema) * */ const getUpdateTypesScriptDtos = collection => { const fullTableName = getFullTableName(collection); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { @@ -79,9 +87,10 @@ const getUpdateTypesScriptDtos = collection => { const typeName = jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type; const columnName = wrapInQuotes(name); const typeConfig = _.pick(jsonSchema, ['length', 'precision', 'scale']); - return alterColumnType(fullTableName, columnName, typeName, typeConfig); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: alterColumnType(fullTableName, columnName, typeName, typeConfig), isActivated }; }) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false)); }; module.exports = { diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js index 952402d..68b756e 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js @@ -1,6 +1,11 @@ const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { getFullColumnName, wrapComment } = require('../../../utils/general'); +const { + getFullColumnName, + wrapComment, + isObjectInDeltaModelActivated, + isParentContainerActivated, +} = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -22,6 +27,8 @@ const updateColumnComment = (columnName, comment) => { * @return {AlterScriptDto[]} * */ const getUpdatedCommentOnColumnScriptDtos = collection => { + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { const newComment = jsonSchema.description; @@ -33,9 +40,10 @@ const getUpdatedCommentOnColumnScriptDtos = collection => { const newComment = jsonSchema.description; const ddlComment = wrapComment(newComment); const columnName = getFullColumnName(collection, name); - return updateColumnComment(columnName, ddlComment); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: updateColumnComment(columnName, ddlComment), isActivated }; }) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false)); }; /** @@ -55,6 +63,8 @@ const dropColumnComment = columnName => { * @return {AlterScriptDto[]} * */ const getDeletedCommentOnColumnScriptDtos = collection => { + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { const newComment = jsonSchema.description; @@ -64,9 +74,10 @@ const getDeletedCommentOnColumnScriptDtos = collection => { }) .map(([name, jsonSchema]) => { const columnName = getFullColumnName(collection, name); - return dropColumnComment(columnName); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: dropColumnComment(columnName), isActivated }; }) - .map(script => AlterScriptDto.getInstance([script], true, true)); + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, true)); }; /** diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js index 51c73c2..bcf04d4 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js @@ -1,6 +1,11 @@ const { toPairs } = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { getFullTableName, wrapInQuotes } = require('../../../utils/general'); +const { + getFullTableName, + wrapInQuotes, + isObjectInDeltaModelActivated, + isParentContainerActivated, +} = require('../../../utils/general'); const { decorateDefault } = require('../../../ddlProvider/ddlHelpers/columnDefinitionHelper'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -26,8 +31,11 @@ const updateColumnDefaultValue = ({ tableName, columnName, defaultValue }) => { * @param {Object} props.collection * @returns { Array } * */ -const getUpdatedDefaultColumnValueScriptDtos = ({ collection }) => - toPairs(collection.properties) +const getUpdatedDefaultColumnValueScriptDtos = ({ collection }) => { + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); + + return toPairs(collection.properties) .filter(([_name, jsonSchema]) => { const newDefault = jsonSchema.default; const oldName = jsonSchema.compMod.oldField.name; @@ -43,10 +51,12 @@ const getUpdatedDefaultColumnValueScriptDtos = ({ collection }) => columnName: wrapInQuotes(columnName), defaultValue: decorateDefault(type, newDefaultValue, isArrayType), }; - return updateColumnDefaultValue(scriptGenerationConfig); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: updateColumnDefaultValue(scriptGenerationConfig), isActivated }; }) - .map(script => AlterScriptDto.getInstance([script], true, false)) + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false)) .filter(Boolean); +}; /** * @param {Object} props @@ -67,8 +77,11 @@ const dropColumnDefaultValue = ({ tableName, columnName }) => { * @param {Object} props.collection * @returns { Array } * */ -const getDeletedDefaultColumnValueScriptDtos = ({ collection }) => - toPairs(collection.properties) +const getDeletedDefaultColumnValueScriptDtos = ({ collection }) => { + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); + + return toPairs(collection.properties) .filter(([_name, jsonSchema]) => { const newDefault = jsonSchema.default; const oldName = jsonSchema.compMod.oldField.name; @@ -77,15 +90,17 @@ const getDeletedDefaultColumnValueScriptDtos = ({ collection }) => const hasNewValue = newDefault !== undefined; return hasPrevValue && !hasNewValue; }) - .map(([columnName]) => { + .map(([columnName, jsonSchema]) => { const scriptGenerationConfig = { tableName: getFullTableName(collection), columnName: wrapInQuotes(columnName), }; - return dropColumnDefaultValue(scriptGenerationConfig); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: dropColumnDefaultValue(scriptGenerationConfig), isActivated }; }) - .map(script => AlterScriptDto.getInstance([script], true, true)) + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, true)) .filter(Boolean); +}; /** * @param {Object} props diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js index e6f2153..d2d39d1 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/nonNullConstraintHelper.js @@ -1,6 +1,11 @@ const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { getFullTableName, wrapInQuotes } = require('../../../utils/general'); +const { + getFullTableName, + wrapInQuotes, + isObjectInDeltaModelActivated, + isParentContainerActivated, +} = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -35,6 +40,9 @@ const dropNotNullConstraint = (tableName, columnName) => { const getModifyNonNullColumnsScriptDtos = collection => { const fullTableName = getFullTableName(collection); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); + const currentRequiredColumnNames = collection.required || []; const previousRequiredColumnNames = collection.role.required || []; @@ -48,8 +56,11 @@ const getModifyNonNullColumnsScriptDtos = collection => { const shouldAddForNewName = columnNamesToAddNotNullConstraint.includes(name); return shouldAddForNewName && !shouldRemoveForOldName; }) - .map(([columnName]) => setNotNullConstraint(fullTableName, wrapInQuotes(columnName))) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(([columnName, jsonSchema]) => { + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: setNotNullConstraint(fullTableName, wrapInQuotes(columnName)), isActivated }; + }) + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false)); const removeNotNullConstraint = _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { @@ -58,8 +69,11 @@ const getModifyNonNullColumnsScriptDtos = collection => { const shouldAddForNewName = columnNamesToAddNotNullConstraint.includes(name); return shouldRemoveForOldName && !shouldAddForNewName; }) - .map(([name]) => dropNotNullConstraint(fullTableName, wrapInQuotes(name))) - .map(script => AlterScriptDto.getInstance([script], true, true)); + .map(([name, jsonSchema]) => { + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: dropNotNullConstraint(fullTableName, wrapInQuotes(name)), isActivated }; + }) + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, true)); return [...addNotNullConstraintsScript, ...removeNotNullConstraint]; }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js index c58be4e..22feffb 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js @@ -1,6 +1,12 @@ const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { checkFieldPropertiesChanged, getFullTableName, wrapInQuotes } = require('../../../utils/general'); +const { + checkFieldPropertiesChanged, + getFullTableName, + wrapInQuotes, + isParentContainerActivated, + isObjectInDeltaModelActivated, +} = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -25,14 +31,18 @@ const renameColumn = (tableName, oldColumnName, newColumnName) => { const getRenameColumnScriptDtos = collection => { const fullTableName = getFullTableName(collection); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); + return _.values(collection.properties) .filter(jsonSchema => checkFieldPropertiesChanged(jsonSchema.compMod, ['name'])) .map(jsonSchema => { const oldColumnName = wrapInQuotes(jsonSchema.compMod.oldField.name); const newColumnName = wrapInQuotes(jsonSchema.compMod.newField.name); - return renameColumn(fullTableName, oldColumnName, newColumnName); + const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated; + return { script: renameColumn(fullTableName, oldColumnName, newColumnName), isActivated }; }) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false)); }; module.exports = { diff --git a/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/commentsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/commentsHelper.js index 3ca35d5..3a71b2e 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/commentsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/commentsHelper.js @@ -1,5 +1,5 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { wrapComment, wrapInQuotes } = require('../../../utils/general'); +const { wrapComment, wrapInQuotes, isObjectInDeltaModelActivated } = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -30,7 +30,8 @@ const getUpsertCommentsScriptDto = container => { const wrappedComment = wrapComment(description.new); const wrappedSchemaName = wrapInQuotes(container.role.name); const script = updateSchemaComment(wrappedSchemaName, wrappedComment); - return AlterScriptDto.getInstance([script], true, false); + const isContainerActivated = isObjectInDeltaModelActivated(container); + return AlterScriptDto.getInstance([script], isContainerActivated, false); } return undefined; }; @@ -56,7 +57,8 @@ const getDropCommentsScriptDto = container => { if (description.old && !description.new) { const wrappedSchemaName = wrapInQuotes(container.role.name); const script = dropSchemaComment(wrappedSchemaName); - return AlterScriptDto.getInstance([script], true, true); + const isContainerActivated = isObjectInDeltaModelActivated(container); + return AlterScriptDto.getInstance([script], isContainerActivated, true); } return undefined; }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/sequencesHelper.js b/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/sequencesHelper.js index 4a04337..1c8c774 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/sequencesHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/containerHelpers/sequencesHelper.js @@ -1,7 +1,7 @@ const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); const { App } = require('../../../types/coreApplicationTypes'); -const { getDbName, getGroupItemsByCompMode } = require('../../../utils/general'); +const { getDbName, getGroupItemsByCompMode, isObjectInDeltaModelActivated } = require('../../../utils/general'); const { createSequenceScript, dropSequenceScript, @@ -17,10 +17,11 @@ const sequencesCompModKey = 'sequences'; * */ const getAddContainerSequencesScriptDtos = ({ container }) => { const schemaName = getDbName([container.role]); + const isContainerActivated = isObjectInDeltaModelActivated(container); return (container.role?.sequences || []) .map(sequence => createSequenceScript({ schemaName, sequence })) - .map(script => AlterScriptDto.getInstance([script], true, false)) + .map(script => AlterScriptDto.getInstance([script], isContainerActivated, false)) .filter(Boolean); }; @@ -31,6 +32,7 @@ const getAddContainerSequencesScriptDtos = ({ container }) => { * */ const getModifyContainerSequencesScriptDtos = ({ container }) => { const schemaName = getDbName([container.role]); + const isContainerActivated = isObjectInDeltaModelActivated(container); const sequencesCompMod = container.role?.compMod?.[sequencesCompModKey] || {}; const { new: newItems = [], old: oldItems = [] } = sequencesCompMod; @@ -41,10 +43,10 @@ const getModifyContainerSequencesScriptDtos = ({ container }) => { const removedScriptDtos = removed .map(sequence => dropSequenceScript({ schemaName, sequence })) - .map(script => AlterScriptDto.getInstance([script], true, true)); + .map(script => AlterScriptDto.getInstance([script], isContainerActivated, true)); const addedScriptDtos = added .map(sequence => createSequenceScript({ schemaName, sequence })) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(script => AlterScriptDto.getInstance([script], isContainerActivated, false)); const modifiedScriptDtos = modified .map(sequence => { @@ -55,7 +57,7 @@ const getModifyContainerSequencesScriptDtos = ({ container }) => { oldSequence, }); }) - .map(script => AlterScriptDto.getInstance([script], true, false)); + .map(script => AlterScriptDto.getInstance([script], isContainerActivated, false)); return [...modifiedScriptDtos, ...removedScriptDtos, ...addedScriptDtos].filter(Boolean); }; @@ -67,10 +69,11 @@ const getModifyContainerSequencesScriptDtos = ({ container }) => { * */ const getDeleteContainerSequencesScriptDtos = ({ container }) => { const schemaName = getDbName([container.role]); + const isContainerActivated = isObjectInDeltaModelActivated(container); return (container.role?.sequences || []) .map(sequence => dropSequenceScript({ schemaName, sequence })) - .map(script => AlterScriptDto.getInstance([script], true, true)) + .map(script => AlterScriptDto.getInstance([script], isContainerActivated, true)) .filter(Boolean); }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js index ef568eb..134f73b 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js @@ -1,7 +1,12 @@ const _ = require('lodash'); const { AlterCollectionDto } = require('../../types/AlterCollectionDto'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { getFullTableName, wrapInQuotes } = require('../../../utils/general'); +const { + getFullTableName, + wrapInQuotes, + isParentContainerActivated, + isObjectInDeltaModelActivated, +} = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -142,11 +147,17 @@ const getModifyCheckConstraintScriptDtos = collection => { const fullTableName = getFullTableName(collection); const constraintHistory = mapCheckConstraintNamesToChangeHistory(collection); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isObjectInDeltaModelActivated(collection); + const addCheckConstraintScripts = getAddCheckConstraintScriptDtos(constraintHistory, fullTableName); const dropCheckConstraintScripts = getDropCheckConstraintScriptDtos(constraintHistory, fullTableName); const updateCheckConstraintScripts = getUpdateCheckConstraintScriptDtos(constraintHistory, fullTableName); - return [...addCheckConstraintScripts, ...dropCheckConstraintScripts, ...updateCheckConstraintScripts]; + return [...addCheckConstraintScripts, ...dropCheckConstraintScripts, ...updateCheckConstraintScripts].map(dto => ({ + ...dto, + isActivated: isContainerActivated && isCollectionActivated, + })); }; module.exports = { diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/commentsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/commentsHelper.js index a982875..ebef834 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/commentsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/commentsHelper.js @@ -1,7 +1,12 @@ const _ = require('lodash'); const { AlterScriptDto } = require('../../types/AlterScriptDto'); const { AlterCollectionDto } = require('../../types/AlterCollectionDto'); -const { getFullTableName, wrapComment } = require('../../../utils/general'); +const { + getFullTableName, + wrapComment, + isObjectInDeltaModelActivated, + isParentContainerActivated, +} = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -36,8 +41,11 @@ const getUpdatedCommentOnCollectionScriptDto = collection => { const tableName = getFullTableName(collection); const comment = wrapComment(newComment); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + const script = updateTableComment(tableName, comment); - return AlterScriptDto.getInstance([script], true, false); + return AlterScriptDto.getInstance([script], isCollectionActivated, false); }; /** @@ -69,8 +77,11 @@ const getDeletedCommentOnCollectionScriptDto = collection => { const tableName = getFullTableName(collection); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + const script = dropTableComment(tableName); - return AlterScriptDto.getInstance([script], true, true); + return AlterScriptDto.getInstance([script], isCollectionActivated, true); }; /** diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index b81787d..757b484 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -13,6 +13,8 @@ const { getSchemaOfAlterCollection, getEntityName, wrapInQuotes, + isParentContainerActivated, + isObjectInDeltaModelActivated, } = require('../../../utils/general'); const { alterKeyConstraint, dropKeyConstraint } = require('../../../ddlProvider/ddlHelpers/constraintsHelper'); const { areConstraintOptionsEqual } = require('./areConstraintOptionsEqual'); @@ -251,10 +253,13 @@ const getAddCompositePkScriptDtos = collection => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return newPrimaryKeys .map(newPk => { const ddlConfig = getCreateCompositePKDDLProviderConfig(newPk, entityName, collection); - const statementDto = alterKeyConstraint(fullTableName, collection.isActivated, ddlConfig); + const statementDto = alterKeyConstraint(fullTableName, isCollectionActivated, ddlConfig); return new KeyScriptModificationDto(statementDto.statement, fullTableName, false, statementDto.isActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); @@ -286,6 +291,9 @@ const getDropCompositePkScriptDtos = collection => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return oldPrimaryKeys .map(oldPk => { let constraintName = getDefaultConstraintName(entityName); @@ -294,7 +302,7 @@ const getDropCompositePkScriptDtos = collection => { } const ddlConstraintName = wrapInQuotes(constraintName); const script = dropKeyConstraint(fullTableName, ddlConstraintName); - return new KeyScriptModificationDto(script, fullTableName, true, collection.isActivated); + return new KeyScriptModificationDto(script, fullTableName, true, isCollectionActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); }; @@ -563,6 +571,9 @@ const getAddPkScriptDtos = collection => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { if (wasFieldChangedToBeARegularPk(jsonSchema, collection)) { @@ -579,7 +590,7 @@ const getAddPkScriptDtos = collection => { }) .map(([name, jsonSchema]) => { const ddlConfig = getCreateRegularPKDDLProviderConfig(name, jsonSchema, entityName, collection); - const statementDto = alterKeyConstraint(fullTableName, collection.isActivated, ddlConfig); + const statementDto = alterKeyConstraint(fullTableName, isCollectionActivated, ddlConfig); return new KeyScriptModificationDto(statementDto.statement, fullTableName, false, statementDto.isActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); @@ -594,6 +605,9 @@ const getDropPkScriptDto = collection => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { if (isFieldNoLongerARegularPk(jsonSchema, collection)) { @@ -614,7 +628,7 @@ const getDropPkScriptDto = collection => { const ddlConstraintName = wrapInQuotes(getConstraintNameForRegularPk(oldJsonSchema, entityName)); const script = dropKeyConstraint(fullTableName, ddlConstraintName); - return new KeyScriptModificationDto(script, fullTableName, true, collection.isActivated); + return new KeyScriptModificationDto(script, fullTableName, true, isCollectionActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/uniqueKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/uniqueKeyHelper.js index 6ebb82d..5bc5e23 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/uniqueKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/uniqueKeyHelper.js @@ -16,6 +16,8 @@ const { getEntityName, getDbVersion, wrapInQuotes, + isParentContainerActivated, + isObjectInDeltaModelActivated, } = require('../../../utils/general'); const { areConstraintOptionsEqual } = require('./areConstraintOptionsEqual'); @@ -264,6 +266,9 @@ const getAddCompositeUniqueKeyScriptDtos = (collection, dbVersion) => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return newUniqueKeys .map(newUniqueKey => { const ddlConfig = getCreateCompositeUniqueKeyDDLProviderConfig( @@ -272,7 +277,7 @@ const getAddCompositeUniqueKeyScriptDtos = (collection, dbVersion) => { collection, dbVersion, ); - const statementDto = alterKeyConstraint(fullTableName, collection.isActivated, ddlConfig); + const statementDto = alterKeyConstraint(fullTableName, isCollectionActivated, ddlConfig); return new KeyScriptModificationDto(statementDto.statement, fullTableName, false, statementDto.isActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); @@ -304,6 +309,9 @@ const getDropCompositeUniqueKeyScriptDtos = collection => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return oldUniqueKeys .map(oldUniqueKey => { let constraintName = getDefaultConstraintName(entityName); @@ -312,7 +320,7 @@ const getDropCompositeUniqueKeyScriptDtos = collection => { } const ddlConstraintName = wrapInQuotes(constraintName); const script = dropKeyConstraint(fullTableName, ddlConstraintName); - return new KeyScriptModificationDto(script, fullTableName, true, collection.isActivated); + return new KeyScriptModificationDto(script, fullTableName, true, isCollectionActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); }; @@ -601,6 +609,9 @@ const getAddUniqueKeyScriptDtos = (collection, dbVersion) => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { if (wasFieldChangedToBeARegularUniqueKey(jsonSchema, collection)) { @@ -623,7 +634,7 @@ const getAddUniqueKeyScriptDtos = (collection, dbVersion) => { collection, dbVersion, ); - const statementDto = alterKeyConstraint(fullTableName, collection.isActivated, ddlConfig); + const statementDto = alterKeyConstraint(fullTableName, isCollectionActivated, ddlConfig); return new KeyScriptModificationDto(statementDto.statement, fullTableName, false, statementDto.isActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); @@ -638,6 +649,9 @@ const getDropUniqueKeyScriptDto = collection => { const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); + const isContainerActivated = isParentContainerActivated(collection); + const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection); + return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { if (isFieldNoLongerARegularUniqueKey(jsonSchema, collection)) { @@ -658,7 +672,7 @@ const getDropUniqueKeyScriptDto = collection => { const ddlConstraintName = wrapInQuotes(getConstraintNameForRegularUniqueKey(oldJsonSchema, entityName)); const script = dropKeyConstraint(fullTableName, ddlConstraintName); - return new KeyScriptModificationDto(script, fullTableName, true, collection.isActivated); + return new KeyScriptModificationDto(script, fullTableName, true, isCollectionActivated); }) .filter(scriptDto => Boolean(scriptDto.script)); }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/viewHelpers/commentsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/viewHelpers/commentsHelper.js index 2a01f09..645ac3d 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/viewHelpers/commentsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/viewHelpers/commentsHelper.js @@ -1,5 +1,10 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto'); -const { getFullViewName, wrapComment } = require('../../../utils/general'); +const { + getFullViewName, + wrapComment, + isObjectInDeltaModelActivated, + isParentContainerActivated, +} = require('../../../utils/general'); const assignTemplates = require('../../../utils/assignTemplates'); const templates = require('../../../ddlProvider/templates'); @@ -41,8 +46,12 @@ const getUpsertCommentsScriptDto = view => { if (description.new && description.new !== description.old) { const wrappedComment = wrapComment(description.new); const viewName = getFullViewName(view); + + const isContainerActivated = isParentContainerActivated(view); + const isViewActivated = isContainerActivated && isObjectInDeltaModelActivated(view); + const script = updateViewComment(viewName, wrappedComment); - return AlterScriptDto.getInstance([script], true, false); + return AlterScriptDto.getInstance([script], isViewActivated, false); } return undefined; }; @@ -56,8 +65,12 @@ const getDropCommentsScriptDto = view => { if (description.old && !description.new) { const viewName = getFullViewName(view); + + const isContainerActivated = isParentContainerActivated(view); + const isViewActivated = isContainerActivated && isObjectInDeltaModelActivated(view); + const script = dropViewComment(viewName); - return AlterScriptDto.getInstance([script], true, true); + return AlterScriptDto.getInstance([script], isViewActivated, true); } return undefined; }; diff --git a/forward_engineering/ddlProvider/ddlHelpers/constraintsHelper.js b/forward_engineering/ddlProvider/ddlHelpers/constraintsHelper.js index 7f62c37..edcfcce 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/constraintsHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/constraintsHelper.js @@ -96,7 +96,7 @@ const createKeyConstraint = (templates, isParentActivated) => keyData => { deferrable, deferrableConstraintCheckTime, }), - isActivated: !isAllColumnsDeactivated, + isActivated: !isAllColumnsDeactivated && isParentActivated, }; }; diff --git a/forward_engineering/utils/general.js b/forward_engineering/utils/general.js index ae71471..d3ad15d 100644 --- a/forward_engineering/utils/general.js +++ b/forward_engineering/utils/general.js @@ -269,6 +269,16 @@ const getGroupItemsByCompMode = ({ newItems = [], oldItems = [] }) => { }; }; +const isObjectInDeltaModelActivated = modelObject => { + return modelObject.compMod?.isActivated?.new ?? modelObject.role?.isActivated; +}; + +const isParentContainerActivated = collection => { + return ( + collection?.compMod?.bucketProperties?.isActivated ?? collection?.role?.compMod?.bucketProperties?.isActivated + ); +}; + module.exports = { getDbName, getDbData, @@ -301,4 +311,6 @@ module.exports = { getGroupItemsByCompMode, wrapInSingleQuotes, addCommaPrefix, + isObjectInDeltaModelActivated, + isParentContainerActivated, };