From 6616503b6cd19ab70caad496c424a34045c80883 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Jun 2023 12:22:22 +0300 Subject: [PATCH 01/14] Adjusted algorithm of updating PK constraints to properly handle transitions FROM composite PK TO regular PK --- .../entityHelpers/primaryKeyHelper.js | 23 ++++++++++++++++--- .../alterScript/types/AlterCollectionDto.js | 18 +++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index bc910b4..094bf2c 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -3,13 +3,17 @@ const { AlterCollectionDto, AlterCollectionColumnDto, AlterCollectionRoleCompModPKDto, - AlterCollectionColumnPrimaryKeyOptionDto + AlterCollectionColumnPrimaryKeyOptionDto, + AlterCollectionRoleCompModPrimaryKey } = require('../../types/AlterCollectionDto'); /** * @return {(collection: AlterCollectionDto) => boolean} * */ const didCompositePkChange = (_) => (collection) => { + /** + * @type {AlterCollectionRoleCompModPrimaryKey} + * */ const pkDto = collection?.role?.compMod?.primaryKey || {}; const newPrimaryKeys = pkDto.new || []; const oldPrimaryKeys = pkDto.old || []; @@ -291,10 +295,23 @@ const getCreateRegularPKDDLProviderConfig = (_) => ( * */ const wasFieldChangedToBeARegularPk = (_) => (columnJsonSchema, collection) => { const oldName = columnJsonSchema.compMod.oldField.name; + const oldColumnJsonSchema = collection.role.properties[oldName]; const isRegularPrimaryKey = columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; - const wasTheFieldAPrimaryKey = Boolean(collection.role.properties[oldName]?.primaryKey); - return isRegularPrimaryKey && !wasTheFieldAPrimaryKey; + const wasTheFieldAnyPrimaryKey = Boolean(oldColumnJsonSchema?.primaryKey); + + /** + * @type {AlterCollectionRoleCompModPrimaryKey} + * */ + const pkDto = collection?.role?.compMod?.primaryKey || {}; + const newPrimaryKeys = pkDto.new || []; + const oldPrimaryKeys = pkDto.old || []; + const wasTheFieldACompositePrimaryKey = oldPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === oldColumnJsonSchema.GUID)); + const isTheFieldACompositePrimaryKey = newPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === columnJsonSchema.GUID)); + + const wasCompositePkRemoved = wasTheFieldACompositePrimaryKey && !isTheFieldACompositePrimaryKey; + + return isRegularPrimaryKey && (wasCompositePkRemoved || !wasTheFieldAnyPrimaryKey); } /** diff --git a/forward_engineering/alterScript/types/AlterCollectionDto.js b/forward_engineering/alterScript/types/AlterCollectionDto.js index 095bff4..2e4d0cb 100644 --- a/forward_engineering/alterScript/types/AlterCollectionDto.js +++ b/forward_engineering/alterScript/types/AlterCollectionDto.js @@ -166,6 +166,18 @@ class AlterCollectionRoleCompModPKDto extends AlterCollectionColumnPrimaryKeyOpt } +class AlterCollectionRoleCompModPrimaryKey { + /** + * @type {AlterCollectionRoleCompModPKDto[] | undefined} + * */ + new + /** + * @type {AlterCollectionRoleCompModPKDto[] | undefined} + * */ + old + +} + class AlterCollectionRoleCompModDto { /** * @type {string} @@ -222,10 +234,7 @@ class AlterCollectionRoleCompModDto { on_commit /** - * @type {{ - * new: Array, - * old: Array, - * }} + * @type {AlterCollectionRoleCompModPrimaryKey} */ primaryKey @@ -409,5 +418,6 @@ module.exports = { AlterCollectionDto, AlterCollectionRoleDto, AlterCollectionColumnDto, + AlterCollectionRoleCompModPrimaryKey, AlterCollectionRoleCompModPKDto, } From 30e17d1a04bf61d8f3ec95833c0503b8ad7c02b7 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Jun 2023 15:58:11 +0300 Subject: [PATCH 02/14] Adjusted algorithm of updating PK constraints to properly handle transitions FROM composite PK TO regular PK --- .../entityHelpers/primaryKeyHelper.js | 91 +++++++++++++++++-- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index 094bf2c..4b4e098 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -300,18 +300,89 @@ const wasFieldChangedToBeARegularPk = (_) => (columnJsonSchema, collection) => { const isRegularPrimaryKey = columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; const wasTheFieldAnyPrimaryKey = Boolean(oldColumnJsonSchema?.primaryKey); + return isRegularPrimaryKey && !wasTheFieldAnyPrimaryKey; +} + +/** + * @param optionHolder {AlterCollectionColumnPrimaryKeyOptionDto} + * @return {} + * */ +const extractOptionsForComparison = (optionHolder) => { + return { + constraintName: optionHolder.constraintName, + indexStorageParameters: optionHolder.indexStorageParameters, + indexTablespace: optionHolder.indexTablespace, + indexInclude: optionHolder.indexInclude, + } +} + +/** + * @param columnJsonSchema {AlterCollectionColumnDto} + * @return {Array>} + * */ +const getCustomPropertiesOfRegularPkForComparison = (columnJsonSchema) => { + /** + * @type {Array} + * */ + const constraintOptions = columnJsonSchema.primaryKeyOptions || []; + return constraintOptions + .map(option => extractOptionsForComparison(option)); +} + +/** + * @param compositePk {AlterCollectionRoleCompModPKDto} + * @return {Array>} + * */ +const getCustomPropertiesOfCompositePkForComparison = (compositePk) => { + const optionsForComparison = extractOptionsForComparison(compositePk); + return [optionsForComparison] + .filter(o => Object.values(o).some(Boolean)); +} + +/** + * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => boolean} + * */ +const wasPkChangedInTransitionFromCompositeToRegular = (_) => (columnJsonSchema, collection) => { + const oldName = columnJsonSchema.compMod.oldField.name; + const oldColumnJsonSchema = collection.role.properties[oldName]; + + const isRegularPrimaryKey = columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; + const wasTheFieldAnyPrimaryKey = Boolean(oldColumnJsonSchema?.primaryKey); + + if (!(isRegularPrimaryKey && wasTheFieldAnyPrimaryKey)) { + return false; + } + /** * @type {AlterCollectionRoleCompModPrimaryKey} * */ const pkDto = collection?.role?.compMod?.primaryKey || {}; const newPrimaryKeys = pkDto.new || []; + /** + * @type {AlterCollectionRoleCompModPKDto[]} + * */ const oldPrimaryKeys = pkDto.old || []; const wasTheFieldACompositePrimaryKey = oldPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === oldColumnJsonSchema.GUID)); const isTheFieldACompositePrimaryKey = newPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === columnJsonSchema.GUID)); const wasCompositePkRemoved = wasTheFieldACompositePrimaryKey && !isTheFieldACompositePrimaryKey; - return isRegularPrimaryKey && (wasCompositePkRemoved || !wasTheFieldAnyPrimaryKey); + if (isRegularPrimaryKey && wasCompositePkRemoved) { + // return compare custom properties and amount of columns. + // If there was a transition and amount of composite PK columns is not equal + // to amount of regular pk columns, we must recreate PK + const constraintOptions = getCustomPropertiesOfRegularPkForComparison(columnJsonSchema); + return oldPrimaryKeys.some((oldCompositePk) => { + if (oldCompositePk.compositePrimaryKey.length !== 1) { + return true; + } + const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparison(oldCompositePk); + const areOptionsEqual = _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); + return !areOptionsEqual; + }); + } + + return false; } /** @@ -323,8 +394,8 @@ const isFieldNoLongerARegularPk = (_) => (columnJsonSchema, collection) => { const oldJsonSchema = collection.role.properties[oldName]; const wasTheFieldARegularPrimaryKey = oldJsonSchema?.primaryKey && !oldJsonSchema?.compositePrimaryKey; - const isNotAPrimaryKey = !columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; - return wasTheFieldARegularPrimaryKey && isNotAPrimaryKey; + const isNotAnyPrimaryKey = !columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; + return wasTheFieldARegularPrimaryKey && isNotAnyPrimaryKey; } /** @@ -332,7 +403,7 @@ const isFieldNoLongerARegularPk = (_) => (columnJsonSchema, collection) => { * */ const wasRegularPkModified = (_) => (columnJsonSchema, collection) => { const oldName = columnJsonSchema.compMod.oldField.name; - const oldJsonSchema = collection.role.properties[oldName]; + const oldJsonSchema = collection.role.properties[oldName] || {}; const isRegularPrimaryKey = columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; const wasTheFieldARegularPrimaryKey = oldJsonSchema?.primaryKey && !oldJsonSchema?.compositePrimaryKey; @@ -340,8 +411,8 @@ const wasRegularPkModified = (_) => (columnJsonSchema, collection) => { if (!(isRegularPrimaryKey && wasTheFieldARegularPrimaryKey)) { return false; } - const constraintOptions = columnJsonSchema.primaryKeyOptions; - const oldConstraintOptions = oldJsonSchema?.primaryKeyOptions; + const constraintOptions = getCustomPropertiesOfRegularPkForComparison(columnJsonSchema); + const oldConstraintOptions = getCustomPropertiesOfRegularPkForComparison(oldJsonSchema); const areOptionsEqual = _(oldConstraintOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); return !areOptionsEqual; } @@ -362,7 +433,9 @@ const getAddPkScripts = (_, ddlProvider) => (collection) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { - return wasFieldChangedToBeARegularPk(_)(jsonSchema, collection) || wasRegularPkModified(_)(jsonSchema, collection); + return wasFieldChangedToBeARegularPk(_)(jsonSchema, collection) + || wasPkChangedInTransitionFromCompositeToRegular(_)(jsonSchema, collection) + || wasRegularPkModified(_)(jsonSchema, collection); }) .map(([name, jsonSchema]) => { const ddlConfig = getCreateRegularPKDDLProviderConfig(_)(name, jsonSchema, entityName, collection); @@ -393,7 +466,9 @@ const getDropPkScript = (_, ddlProvider) => (collection) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { - return isFieldNoLongerARegularPk(_)(jsonSchema, collection) || wasRegularPkModified(_)(jsonSchema, collection); + return isFieldNoLongerARegularPk(_)(jsonSchema, collection) + || wasPkChangedInTransitionFromCompositeToRegular(_)(jsonSchema, collection) + || wasRegularPkModified(_)(jsonSchema, collection); }) .map(([name, jsonSchema]) => { const oldName = jsonSchema.compMod.oldField.name; From a647f313006e5531f89f48dca5a223227d7374bb Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jun 2023 16:51:37 +0300 Subject: [PATCH 03/14] Fixed some comparison issues --- .../entityHelpers/primaryKeyHelper.js | 305 +++++++++++++++--- .../alterScript/types/AlterCollectionDto.js | 3 +- 2 files changed, 254 insertions(+), 54 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index 4b4e098..4ca0bf5 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -7,6 +7,162 @@ const { AlterCollectionRoleCompModPrimaryKey } = require('../../types/AlterCollectionDto'); +class PkTransitionDto { + + /** + * @type {boolean} + * */ + didTransitionHappen + + /** + * @type {boolean | undefined} + * */ + wasPkChangedInTransition + +} + +/** + * @param optionHolder {AlterCollectionColumnPrimaryKeyOptionDto} + * @return {} + * */ +const extractOptionsForComparisonWithRegularPkOptions = (optionHolder) => { + return { + constraintName: optionHolder.constraintName, + indexStorageParameters: optionHolder.indexStorageParameters, + indexTablespace: optionHolder.indexTablespace, + indexInclude: optionHolder.indexInclude?.map(e => { + const indexIncludeEntry = { + keyId: e.keyId, + } + if (e.type) { + indexIncludeEntry.type = e.type; + } + return indexIncludeEntry; + }), + } +} + +/** + * @param columnJsonSchema {AlterCollectionColumnDto} + * @return {Array>} + * */ +const getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions = (columnJsonSchema) => { + /** + * @type {Array} + * */ + const constraintOptions = columnJsonSchema.primaryKeyOptions || []; + return constraintOptions + .map(option => extractOptionsForComparisonWithRegularPkOptions(option)); +} + +/** + * @param compositePk {AlterCollectionRoleCompModPKDto} + * @return {Array>} + * */ +const getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions = (compositePk) => { + const optionsForComparison = extractOptionsForComparisonWithRegularPkOptions(compositePk); + return [optionsForComparison] + .filter(o => Object.values(o).some(Boolean)); +} + +/** + * @return {(collection: AlterCollectionDto) => PkTransitionDto} + * */ +const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collection) => { + /** + * @type {AlterCollectionRoleCompModPrimaryKey} + * */ + const pkDto = collection?.role?.compMod?.primaryKey || {}; + /** + * @type {AlterCollectionRoleCompModPKDto[]} + * */ + const oldPrimaryKeys = pkDto.old || []; + const idsOfColumns = oldPrimaryKeys.flatMap(pk => pk.compositePrimaryKey.map(dto => dto.keyId)) + if (idsOfColumns.length !== 1) { + // We return false, because it wouldn't count as transition between regular PK and composite PK + // if composite PK did not constraint exactly 1 column + return { + didTransitionHappen: false, + }; + } + const idOfPkColumn = idsOfColumns[0]; + const newColumnJsonSchema = Object.values(collection.properties) + .find(columnJsonSchema => columnJsonSchema.GUID === idOfPkColumn); + if (!newColumnJsonSchema) { + return { + didTransitionHappen: false, + }; + } + const isNewColumnARegularPrimaryKey = newColumnJsonSchema?.primaryKey && !newColumnJsonSchema?.compositePrimaryKey; + if (!isNewColumnARegularPrimaryKey) { + return { + didTransitionHappen: false, + }; + } + const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(newColumnJsonSchema); + const areOptionsEqual = oldPrimaryKeys.some((compositePk) => { + if (compositePk.compositePrimaryKey.length !== 1) { + return false; + } + const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(compositePk); + return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); + }); + + return { + didTransitionHappen: true, + wasPkChangedInTransition: !areOptionsEqual, + } +} + +/** + * @return {(collection: AlterCollectionDto) => PkTransitionDto} + * */ +const wasCompositePkChangedInTransitionFromRegularToComposite = (_) => (collection) => { + /** + * @type {AlterCollectionRoleCompModPrimaryKey} + * */ + const pkDto = collection?.role?.compMod?.primaryKey || {}; + /** + * @type {AlterCollectionRoleCompModPKDto[]} + * */ + const newPrimaryKeys = pkDto.new || []; + const idsOfColumns = newPrimaryKeys.flatMap(pk => pk.compositePrimaryKey.map(dto => dto.keyId)) + if (idsOfColumns.length !== 1) { + // We return false, because it wouldn't count as transition between regular PK and composite PK + // if composite PK did not constraint exactly 1 column + return { + didTransitionHappen: false, + }; + } + const idOfPkColumn = idsOfColumns[0]; + const oldColumnJsonSchema = Object.values(collection.role.properties) + .find(columnJsonSchema => columnJsonSchema.GUID === idOfPkColumn); + if (!oldColumnJsonSchema) { + return { + didTransitionHappen: false, + }; + } + const isOldColumnARegularPrimaryKey = oldColumnJsonSchema?.primaryKey && !oldColumnJsonSchema?.compositePrimaryKey; + if (!isOldColumnARegularPrimaryKey) { + return { + didTransitionHappen: false, + }; + } + const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(oldColumnJsonSchema); + const areOptionsEqual = newPrimaryKeys.some((compositePk) => { + if (compositePk.compositePrimaryKey.length !== 1) { + return false; + } + const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(compositePk); + return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); + }); + + return { + didTransitionHappen: true, + wasPkChangedInTransition: !areOptionsEqual, + } +} + /** * @return {(collection: AlterCollectionDto) => boolean} * */ @@ -17,12 +173,20 @@ const didCompositePkChange = (_) => (collection) => { const pkDto = collection?.role?.compMod?.primaryKey || {}; const newPrimaryKeys = pkDto.new || []; const oldPrimaryKeys = pkDto.old || []; - if (newPrimaryKeys.length !== oldPrimaryKeys.length) { - return true; - } if (newPrimaryKeys.length === 0 && oldPrimaryKeys.length === 0) { return false; } + const transitionToRegularDto = wasCompositePkChangedInTransitionFromCompositeToRegular(_)(collection); + if (transitionToRegularDto.didTransitionHappen) { + return transitionToRegularDto.wasPkChangedInTransition; + } + const transitionToCompositeDto = wasCompositePkChangedInTransitionFromRegularToComposite(_)(collection); + if (transitionToCompositeDto.didTransitionHappen) { + return transitionToCompositeDto.wasPkChangedInTransition; + } + if (newPrimaryKeys.length !== oldPrimaryKeys.length) { + return true; + } const areKeyArraysEqual = _(oldPrimaryKeys).differenceWith(newPrimaryKeys, _.isEqual).isEmpty(); return !areKeyArraysEqual; } @@ -304,53 +468,72 @@ const wasFieldChangedToBeARegularPk = (_) => (columnJsonSchema, collection) => { } /** - * @param optionHolder {AlterCollectionColumnPrimaryKeyOptionDto} - * @return {} + * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => PkTransitionDto} * */ -const extractOptionsForComparison = (optionHolder) => { - return { - constraintName: optionHolder.constraintName, - indexStorageParameters: optionHolder.indexStorageParameters, - indexTablespace: optionHolder.indexTablespace, - indexInclude: optionHolder.indexInclude, +const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJsonSchema, collection) => { + const oldName = columnJsonSchema.compMod.oldField.name; + const oldColumnJsonSchema = collection.role.properties[oldName]; + + const isRegularPrimaryKey = columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; + const wasTheFieldAnyPrimaryKey = Boolean(oldColumnJsonSchema?.primaryKey); + + if (!(isRegularPrimaryKey && wasTheFieldAnyPrimaryKey)) { + return { + didTransitionHappen: false, + }; } -} -/** - * @param columnJsonSchema {AlterCollectionColumnDto} - * @return {Array>} - * */ -const getCustomPropertiesOfRegularPkForComparison = (columnJsonSchema) => { /** - * @type {Array} + * @type {AlterCollectionRoleCompModPrimaryKey} * */ - const constraintOptions = columnJsonSchema.primaryKeyOptions || []; - return constraintOptions - .map(option => extractOptionsForComparison(option)); -} + const pkDto = collection?.role?.compMod?.primaryKey || {}; + const newPrimaryKeys = pkDto.new || []; + /** + * @type {AlterCollectionRoleCompModPKDto[]} + * */ + const oldPrimaryKeys = pkDto.old || []; + const wasTheFieldACompositePrimaryKey = oldPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === oldColumnJsonSchema.GUID)); + const isTheFieldACompositePrimaryKey = newPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === columnJsonSchema.GUID)); -/** - * @param compositePk {AlterCollectionRoleCompModPKDto} - * @return {Array>} - * */ -const getCustomPropertiesOfCompositePkForComparison = (compositePk) => { - const optionsForComparison = extractOptionsForComparison(compositePk); - return [optionsForComparison] - .filter(o => Object.values(o).some(Boolean)); + const wasCompositePkRemoved = wasTheFieldACompositePrimaryKey && !isTheFieldACompositePrimaryKey; + + if (isRegularPrimaryKey && wasCompositePkRemoved) { + // return compare custom properties and amount of columns. + // If there was a transition and amount of composite PK columns is not equal + // to amount of regular pk columns, we must recreate PK + const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(columnJsonSchema); + const areOptionsEqual = oldPrimaryKeys.some((oldCompositePk) => { + if (oldCompositePk.compositePrimaryKey.length !== 1) { + return false; + } + const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(oldCompositePk); + return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); + }); + return { + didTransitionHappen: true, + wasPkChangedInTransition: !areOptionsEqual, + } + } + + return { + didTransitionHappen: false, + }; } /** - * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => boolean} + * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => PkTransitionDto} * */ -const wasPkChangedInTransitionFromCompositeToRegular = (_) => (columnJsonSchema, collection) => { +const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJsonSchema, collection) => { const oldName = columnJsonSchema.compMod.oldField.name; const oldColumnJsonSchema = collection.role.properties[oldName]; - const isRegularPrimaryKey = columnJsonSchema.primaryKey && !columnJsonSchema.compositePrimaryKey; - const wasTheFieldAnyPrimaryKey = Boolean(oldColumnJsonSchema?.primaryKey); + const wasRegularPrimaryKey = oldColumnJsonSchema.primaryKey && !oldColumnJsonSchema.compositePrimaryKey; + const isTheFieldAnyPrimaryKey = Boolean(columnJsonSchema?.primaryKey); - if (!(isRegularPrimaryKey && wasTheFieldAnyPrimaryKey)) { - return false; + if (!(wasRegularPrimaryKey && isTheFieldAnyPrimaryKey)) { + return { + didTransitionHappen: false, + }; } /** @@ -365,26 +548,32 @@ const wasPkChangedInTransitionFromCompositeToRegular = (_) => (columnJsonSchema, const wasTheFieldACompositePrimaryKey = oldPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === oldColumnJsonSchema.GUID)); const isTheFieldACompositePrimaryKey = newPrimaryKeys.some(compPk => compPk.compositePrimaryKey.some((pk) => pk.keyId === columnJsonSchema.GUID)); - const wasCompositePkRemoved = wasTheFieldACompositePrimaryKey && !isTheFieldACompositePrimaryKey; + const wasCompositePkAdded = isTheFieldACompositePrimaryKey && !wasTheFieldACompositePrimaryKey; - if (isRegularPrimaryKey && wasCompositePkRemoved) { + if (wasRegularPrimaryKey && wasCompositePkAdded) { // return compare custom properties and amount of columns. // If there was a transition and amount of composite PK columns is not equal // to amount of regular pk columns, we must recreate PK - const constraintOptions = getCustomPropertiesOfRegularPkForComparison(columnJsonSchema); - return oldPrimaryKeys.some((oldCompositePk) => { + const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(oldColumnJsonSchema); + const areOptionsEqual = newPrimaryKeys.some((oldCompositePk) => { if (oldCompositePk.compositePrimaryKey.length !== 1) { - return true; + return false; } - const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparison(oldCompositePk); - const areOptionsEqual = _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); - return !areOptionsEqual; + const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(oldCompositePk); + return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); }); + return { + didTransitionHappen: true, + wasPkChangedInTransition: !areOptionsEqual, + } } - return false; + return { + didTransitionHappen: false, + }; } + /** * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => boolean} * */ @@ -411,8 +600,8 @@ const wasRegularPkModified = (_) => (columnJsonSchema, collection) => { if (!(isRegularPrimaryKey && wasTheFieldARegularPrimaryKey)) { return false; } - const constraintOptions = getCustomPropertiesOfRegularPkForComparison(columnJsonSchema); - const oldConstraintOptions = getCustomPropertiesOfRegularPkForComparison(oldJsonSchema); + const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(columnJsonSchema); + const oldConstraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(oldJsonSchema); const areOptionsEqual = _(oldConstraintOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); return !areOptionsEqual; } @@ -433,9 +622,14 @@ const getAddPkScripts = (_, ddlProvider) => (collection) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { - return wasFieldChangedToBeARegularPk(_)(jsonSchema, collection) - || wasPkChangedInTransitionFromCompositeToRegular(_)(jsonSchema, collection) - || wasRegularPkModified(_)(jsonSchema, collection); + if (wasFieldChangedToBeARegularPk(_)(jsonSchema, collection)) { + return true; + } + const transitionToRegularDto = wasRegularPkChangedInTransitionFromCompositeToRegular(_)(jsonSchema, collection); + if (transitionToRegularDto.didTransitionHappen) { + return transitionToRegularDto.wasPkChangedInTransition; + } + return wasRegularPkModified(_)(jsonSchema, collection); }) .map(([name, jsonSchema]) => { const ddlConfig = getCreateRegularPKDDLProviderConfig(_)(name, jsonSchema, entityName, collection); @@ -466,9 +660,14 @@ const getDropPkScript = (_, ddlProvider) => (collection) => { return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => { - return isFieldNoLongerARegularPk(_)(jsonSchema, collection) - || wasPkChangedInTransitionFromCompositeToRegular(_)(jsonSchema, collection) - || wasRegularPkModified(_)(jsonSchema, collection); + if (isFieldNoLongerARegularPk(_)(jsonSchema, collection)) { + return true; + } + const transitionToRegularDto = wasRegularPkChangedInTransitionFromCompositeToRegular(_)(jsonSchema, collection); + if (transitionToRegularDto.didTransitionHappen) { + return transitionToRegularDto.wasPkChangedInTransition; + } + return wasRegularPkModified(_)(jsonSchema, collection); }) .map(([name, jsonSchema]) => { const oldName = jsonSchema.compMod.oldField.name; diff --git a/forward_engineering/alterScript/types/AlterCollectionDto.js b/forward_engineering/alterScript/types/AlterCollectionDto.js index 2e4d0cb..61c237d 100644 --- a/forward_engineering/alterScript/types/AlterCollectionDto.js +++ b/forward_engineering/alterScript/types/AlterCollectionDto.js @@ -53,7 +53,8 @@ class AlterCollectionColumnPrimaryKeyOptionDto { /** * @type {Array<{ - * keyId: string + * keyId: string, + * type?: string, * }>} * */ indexInclude From d1800c87b4d74279f092096fd31ce520fe9ee878 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jun 2023 18:16:37 +0300 Subject: [PATCH 04/14] Some refactoring --- .../entityHelpers/primaryKeyHelper.js | 168 ++++++++---------- 1 file changed, 76 insertions(+), 92 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index 4ca0bf5..a3902b7 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -7,6 +7,20 @@ const { AlterCollectionRoleCompModPrimaryKey } = require('../../types/AlterCollectionDto'); +const amountOfColumnsInRegularPk = 1; + +/** + * @return {(collection: AlterCollectionDto) => boolean} + * */ + +/** + * @param entityName {string} + * @return {string} + * */ +const getDefaultConstraintName = (entityName) => { + return `${entityName}_pk`; +} + class PkTransitionDto { /** @@ -69,6 +83,9 @@ const getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions = (compo * @return {(collection: AlterCollectionDto) => PkTransitionDto} * */ const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collection) => { + const noTransition = { + didTransitionHappen: false, + } /** * @type {AlterCollectionRoleCompModPrimaryKey} * */ @@ -78,30 +95,24 @@ const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collecti * */ const oldPrimaryKeys = pkDto.old || []; const idsOfColumns = oldPrimaryKeys.flatMap(pk => pk.compositePrimaryKey.map(dto => dto.keyId)) - if (idsOfColumns.length !== 1) { + if (idsOfColumns.length !== amountOfColumnsInRegularPk) { // We return false, because it wouldn't count as transition between regular PK and composite PK // if composite PK did not constraint exactly 1 column - return { - didTransitionHappen: false, - }; + return noTransition; } const idOfPkColumn = idsOfColumns[0]; const newColumnJsonSchema = Object.values(collection.properties) .find(columnJsonSchema => columnJsonSchema.GUID === idOfPkColumn); if (!newColumnJsonSchema) { - return { - didTransitionHappen: false, - }; + return noTransition; } const isNewColumnARegularPrimaryKey = newColumnJsonSchema?.primaryKey && !newColumnJsonSchema?.compositePrimaryKey; if (!isNewColumnARegularPrimaryKey) { - return { - didTransitionHappen: false, - }; + return noTransition; } const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(newColumnJsonSchema); const areOptionsEqual = oldPrimaryKeys.some((compositePk) => { - if (compositePk.compositePrimaryKey.length !== 1) { + if (compositePk.compositePrimaryKey.length !== amountOfColumnsInRegularPk) { return false; } const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(compositePk); @@ -118,6 +129,9 @@ const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collecti * @return {(collection: AlterCollectionDto) => PkTransitionDto} * */ const wasCompositePkChangedInTransitionFromRegularToComposite = (_) => (collection) => { + const noTransition = { + didTransitionHappen: false, + } /** * @type {AlterCollectionRoleCompModPrimaryKey} * */ @@ -127,30 +141,24 @@ const wasCompositePkChangedInTransitionFromRegularToComposite = (_) => (collecti * */ const newPrimaryKeys = pkDto.new || []; const idsOfColumns = newPrimaryKeys.flatMap(pk => pk.compositePrimaryKey.map(dto => dto.keyId)) - if (idsOfColumns.length !== 1) { + if (idsOfColumns.length !== amountOfColumnsInRegularPk) { // We return false, because it wouldn't count as transition between regular PK and composite PK - // if composite PK did not constraint exactly 1 column - return { - didTransitionHappen: false, - }; + // if composite PK does not constraint exactly 1 column + return noTransition; } const idOfPkColumn = idsOfColumns[0]; const oldColumnJsonSchema = Object.values(collection.role.properties) .find(columnJsonSchema => columnJsonSchema.GUID === idOfPkColumn); if (!oldColumnJsonSchema) { - return { - didTransitionHappen: false, - }; + return noTransition; } const isOldColumnARegularPrimaryKey = oldColumnJsonSchema?.primaryKey && !oldColumnJsonSchema?.compositePrimaryKey; if (!isOldColumnARegularPrimaryKey) { - return { - didTransitionHappen: false, - }; + return noTransition; } const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(oldColumnJsonSchema); const areOptionsEqual = newPrimaryKeys.some((compositePk) => { - if (compositePk.compositePrimaryKey.length !== 1) { + if (compositePk.compositePrimaryKey.length !== amountOfColumnsInRegularPk) { return false; } const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(compositePk); @@ -163,42 +171,6 @@ const wasCompositePkChangedInTransitionFromRegularToComposite = (_) => (collecti } } -/** - * @return {(collection: AlterCollectionDto) => boolean} - * */ -const didCompositePkChange = (_) => (collection) => { - /** - * @type {AlterCollectionRoleCompModPrimaryKey} - * */ - const pkDto = collection?.role?.compMod?.primaryKey || {}; - const newPrimaryKeys = pkDto.new || []; - const oldPrimaryKeys = pkDto.old || []; - if (newPrimaryKeys.length === 0 && oldPrimaryKeys.length === 0) { - return false; - } - const transitionToRegularDto = wasCompositePkChangedInTransitionFromCompositeToRegular(_)(collection); - if (transitionToRegularDto.didTransitionHappen) { - return transitionToRegularDto.wasPkChangedInTransition; - } - const transitionToCompositeDto = wasCompositePkChangedInTransitionFromRegularToComposite(_)(collection); - if (transitionToCompositeDto.didTransitionHappen) { - return transitionToCompositeDto.wasPkChangedInTransition; - } - if (newPrimaryKeys.length !== oldPrimaryKeys.length) { - return true; - } - const areKeyArraysEqual = _(oldPrimaryKeys).differenceWith(newPrimaryKeys, _.isEqual).isEmpty(); - return !areKeyArraysEqual; -} - -/** - * @param entityName {string} - * @return {string} - * */ -const getDefaultConstraintName = (entityName) => { - return `${entityName}_pk`; -} - /** * @param primaryKey {AlterCollectionRoleCompModPKDto} * @param entityName {string} @@ -284,21 +256,30 @@ const getAddCompositePkScripts = (_, ddlProvider) => (collection) => { getEntityName, } = require('../../../utils/general')(_); - const didPkChange = didCompositePkChange(_)(collection); - if (!didPkChange) { - return [] + /** + * @type {AlterCollectionRoleCompModPrimaryKey} + * */ + const pkDto = collection?.role?.compMod?.primaryKey || {}; + const newPrimaryKeys = pkDto.new || []; + const oldPrimaryKeys = pkDto.old || []; + if (newPrimaryKeys.length === 0 && oldPrimaryKeys.length === 0) { + return []; + } + const transitionToCompositeDto = wasCompositePkChangedInTransitionFromRegularToComposite(_)(collection); + if (transitionToCompositeDto.didTransitionHappen && !transitionToCompositeDto.wasPkChangedInTransition) { + return []; + } + if (newPrimaryKeys.length === oldPrimaryKeys.length) { + const areKeyArraysEqual = _(oldPrimaryKeys).differenceWith(newPrimaryKeys, _.isEqual).isEmpty(); + if (areKeyArraysEqual) { + return [] + } } const collectionSchema = getSchemaOfAlterCollection(collection); const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); - const pkDto = collection?.role?.compMod?.primaryKey || {}; - /** - * @type {Array} - * */ - const newPrimaryKeys = pkDto.new || []; - return newPrimaryKeys .map((newPk) => { const ddlConfig = getCreateCompositePKDDLProviderConfig(_)(newPk, entityName, collection); @@ -324,21 +305,27 @@ const getDropCompositePkScripts = (_, ddlProvider) => (collection) => { wrapInQuotes } = require('../../../utils/general')(_); - const didPkChange = didCompositePkChange(_)(collection); - if (!didPkChange) { + const pkDto = collection?.role?.compMod?.primaryKey || {}; + const newPrimaryKeys = pkDto.new || []; + const oldPrimaryKeys = pkDto.old || []; + if (newPrimaryKeys.length === 0 && oldPrimaryKeys.length === 0) { + return []; + } + const transitionToCompositeDto = wasCompositePkChangedInTransitionFromCompositeToRegular(_)(collection); + if (transitionToCompositeDto.didTransitionHappen && !transitionToCompositeDto.wasPkChangedInTransition) { return []; } + if (newPrimaryKeys.length === oldPrimaryKeys.length) { + const areKeyArraysEqual = _(oldPrimaryKeys).differenceWith(newPrimaryKeys, _.isEqual).isEmpty(); + if (areKeyArraysEqual) { + return [] + } + } const collectionSchema = getSchemaOfAlterCollection(collection); const fullTableName = getFullCollectionName(collectionSchema); const entityName = getEntityName(collectionSchema); - const pkDto = collection?.role?.compMod?.primaryKey || {}; - /** - * @type {AlterCollectionRoleCompModPKDto[]} - * */ - const oldPrimaryKeys = pkDto.old || []; - return oldPrimaryKeys .map((oldPk) => { let constraintName = wrapInQuotes(getDefaultConstraintName(entityName)); @@ -471,6 +458,9 @@ const wasFieldChangedToBeARegularPk = (_) => (columnJsonSchema, collection) => { * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => PkTransitionDto} * */ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJsonSchema, collection) => { + const noTransition = { + didTransitionHappen: false, + } const oldName = columnJsonSchema.compMod.oldField.name; const oldColumnJsonSchema = collection.role.properties[oldName]; @@ -478,9 +468,7 @@ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJson const wasTheFieldAnyPrimaryKey = Boolean(oldColumnJsonSchema?.primaryKey); if (!(isRegularPrimaryKey && wasTheFieldAnyPrimaryKey)) { - return { - didTransitionHappen: false, - }; + return noTransition; } /** @@ -503,7 +491,7 @@ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJson // to amount of regular pk columns, we must recreate PK const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(columnJsonSchema); const areOptionsEqual = oldPrimaryKeys.some((oldCompositePk) => { - if (oldCompositePk.compositePrimaryKey.length !== 1) { + if (oldCompositePk.compositePrimaryKey.length !== amountOfColumnsInRegularPk) { return false; } const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(oldCompositePk); @@ -515,15 +503,16 @@ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJson } } - return { - didTransitionHappen: false, - }; + return noTransition; } /** * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => PkTransitionDto} * */ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJsonSchema, collection) => { + const noTransition = { + didTransitionHappen: false, + } const oldName = columnJsonSchema.compMod.oldField.name; const oldColumnJsonSchema = collection.role.properties[oldName]; @@ -531,9 +520,7 @@ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJson const isTheFieldAnyPrimaryKey = Boolean(columnJsonSchema?.primaryKey); if (!(wasRegularPrimaryKey && isTheFieldAnyPrimaryKey)) { - return { - didTransitionHappen: false, - }; + return noTransition; } /** @@ -556,7 +543,7 @@ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJson // to amount of regular pk columns, we must recreate PK const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(oldColumnJsonSchema); const areOptionsEqual = newPrimaryKeys.some((oldCompositePk) => { - if (oldCompositePk.compositePrimaryKey.length !== 1) { + if (oldCompositePk.compositePrimaryKey.length !== amountOfColumnsInRegularPk) { return false; } const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(oldCompositePk); @@ -568,12 +555,9 @@ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJson } } - return { - didTransitionHappen: false, - }; + return noTransition; } - /** * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => boolean} * */ @@ -663,7 +647,7 @@ const getDropPkScript = (_, ddlProvider) => (collection) => { if (isFieldNoLongerARegularPk(_)(jsonSchema, collection)) { return true; } - const transitionToRegularDto = wasRegularPkChangedInTransitionFromCompositeToRegular(_)(jsonSchema, collection); + const transitionToRegularDto = wasRegularPkChangedInTransitionFromRegularToComposite(_)(jsonSchema, collection); if (transitionToRegularDto.didTransitionHappen) { return transitionToRegularDto.wasPkChangedInTransition; } From 5f4515484eba369dc21e3414142041313188af49 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jun 2023 18:25:03 +0300 Subject: [PATCH 05/14] Replaced hardcoded noTransition value with a factory method --- .../entityHelpers/primaryKeyHelper.js | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index a3902b7..c07d06c 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -33,6 +33,15 @@ class PkTransitionDto { * */ wasPkChangedInTransition + /** + * @return {PkTransitionDto} + * */ + static noTransition() { + return { + didTransitionHappen: false, + } + } + } /** @@ -83,9 +92,6 @@ const getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions = (compo * @return {(collection: AlterCollectionDto) => PkTransitionDto} * */ const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collection) => { - const noTransition = { - didTransitionHappen: false, - } /** * @type {AlterCollectionRoleCompModPrimaryKey} * */ @@ -98,17 +104,17 @@ const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collecti if (idsOfColumns.length !== amountOfColumnsInRegularPk) { // We return false, because it wouldn't count as transition between regular PK and composite PK // if composite PK did not constraint exactly 1 column - return noTransition; + return PkTransitionDto.noTransition(); } const idOfPkColumn = idsOfColumns[0]; const newColumnJsonSchema = Object.values(collection.properties) .find(columnJsonSchema => columnJsonSchema.GUID === idOfPkColumn); if (!newColumnJsonSchema) { - return noTransition; + return PkTransitionDto.noTransition(); } const isNewColumnARegularPrimaryKey = newColumnJsonSchema?.primaryKey && !newColumnJsonSchema?.compositePrimaryKey; if (!isNewColumnARegularPrimaryKey) { - return noTransition; + return PkTransitionDto.noTransition(); } const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(newColumnJsonSchema); const areOptionsEqual = oldPrimaryKeys.some((compositePk) => { @@ -129,9 +135,6 @@ const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collecti * @return {(collection: AlterCollectionDto) => PkTransitionDto} * */ const wasCompositePkChangedInTransitionFromRegularToComposite = (_) => (collection) => { - const noTransition = { - didTransitionHappen: false, - } /** * @type {AlterCollectionRoleCompModPrimaryKey} * */ @@ -144,17 +147,17 @@ const wasCompositePkChangedInTransitionFromRegularToComposite = (_) => (collecti if (idsOfColumns.length !== amountOfColumnsInRegularPk) { // We return false, because it wouldn't count as transition between regular PK and composite PK // if composite PK does not constraint exactly 1 column - return noTransition; + return PkTransitionDto.noTransition(); } const idOfPkColumn = idsOfColumns[0]; const oldColumnJsonSchema = Object.values(collection.role.properties) .find(columnJsonSchema => columnJsonSchema.GUID === idOfPkColumn); if (!oldColumnJsonSchema) { - return noTransition; + return PkTransitionDto.noTransition(); } const isOldColumnARegularPrimaryKey = oldColumnJsonSchema?.primaryKey && !oldColumnJsonSchema?.compositePrimaryKey; if (!isOldColumnARegularPrimaryKey) { - return noTransition; + return PkTransitionDto.noTransition(); } const constraintOptions = getCustomPropertiesOfRegularPkForComparisonWithRegularPkOptions(oldColumnJsonSchema); const areOptionsEqual = newPrimaryKeys.some((compositePk) => { @@ -458,9 +461,6 @@ const wasFieldChangedToBeARegularPk = (_) => (columnJsonSchema, collection) => { * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => PkTransitionDto} * */ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJsonSchema, collection) => { - const noTransition = { - didTransitionHappen: false, - } const oldName = columnJsonSchema.compMod.oldField.name; const oldColumnJsonSchema = collection.role.properties[oldName]; @@ -468,7 +468,7 @@ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJson const wasTheFieldAnyPrimaryKey = Boolean(oldColumnJsonSchema?.primaryKey); if (!(isRegularPrimaryKey && wasTheFieldAnyPrimaryKey)) { - return noTransition; + return PkTransitionDto.noTransition(); } /** @@ -503,16 +503,13 @@ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJson } } - return noTransition; + return PkTransitionDto.noTransition(); } /** * @return {(columnJsonSchema: AlterCollectionColumnDto, collection: AlterCollectionDto) => PkTransitionDto} * */ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJsonSchema, collection) => { - const noTransition = { - didTransitionHappen: false, - } const oldName = columnJsonSchema.compMod.oldField.name; const oldColumnJsonSchema = collection.role.properties[oldName]; @@ -520,7 +517,7 @@ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJson const isTheFieldAnyPrimaryKey = Boolean(columnJsonSchema?.primaryKey); if (!(wasRegularPrimaryKey && isTheFieldAnyPrimaryKey)) { - return noTransition; + return PkTransitionDto.noTransition(); } /** @@ -555,7 +552,7 @@ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJson } } - return noTransition; + return PkTransitionDto.noTransition(); } /** From 7a5533a57576a23d7f73650d20563a3fe83ffa72 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jun 2023 18:27:20 +0300 Subject: [PATCH 06/14] Replaced hardcoded transition dto with a factory method --- .../entityHelpers/primaryKeyHelper.js | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index c07d06c..bcc7191 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -42,6 +42,17 @@ class PkTransitionDto { } } + /** + * @param wasPkChangedInTransition {boolean} + * @return {PkTransitionDto} + * */ + static transition(wasPkChangedInTransition) { + return { + didTransitionHappen: false, + wasPkChangedInTransition + } + } + } /** @@ -125,10 +136,7 @@ const wasCompositePkChangedInTransitionFromCompositeToRegular = (_) => (collecti return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); }); - return { - didTransitionHappen: true, - wasPkChangedInTransition: !areOptionsEqual, - } + return PkTransitionDto.transition(!areOptionsEqual); } /** @@ -168,10 +176,7 @@ const wasCompositePkChangedInTransitionFromRegularToComposite = (_) => (collecti return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); }); - return { - didTransitionHappen: true, - wasPkChangedInTransition: !areOptionsEqual, - } + return PkTransitionDto.transition(!areOptionsEqual); } /** @@ -497,10 +502,7 @@ const wasRegularPkChangedInTransitionFromCompositeToRegular = (_) => (columnJson const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(oldCompositePk); return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); }); - return { - didTransitionHappen: true, - wasPkChangedInTransition: !areOptionsEqual, - } + return PkTransitionDto.transition(!areOptionsEqual); } return PkTransitionDto.noTransition(); @@ -546,10 +548,7 @@ const wasRegularPkChangedInTransitionFromRegularToComposite = (_) => (columnJson const oldCompositePkAsRegularPkOptions = getCustomPropertiesOfCompositePkForComparisonWithRegularPkOptions(oldCompositePk); return _(oldCompositePkAsRegularPkOptions).differenceWith(constraintOptions, _.isEqual).isEmpty(); }); - return { - didTransitionHappen: true, - wasPkChangedInTransition: !areOptionsEqual, - } + return PkTransitionDto.transition(!areOptionsEqual); } return PkTransitionDto.noTransition(); From 090ba653db9644e46ffe86bd445128be064d4478 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jun 2023 16:22:55 +0300 Subject: [PATCH 07/14] Fixed incorrectly set flag --- .../alterScriptHelpers/entityHelpers/primaryKeyHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index bcc7191..9d86932 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -48,7 +48,7 @@ class PkTransitionDto { * */ static transition(wasPkChangedInTransition) { return { - didTransitionHappen: false, + didTransitionHappen: true, wasPkChangedInTransition } } From e9ff505e627bf1e452e60b2cb89f439c8e9d307e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jun 2023 17:43:24 +0300 Subject: [PATCH 08/14] Sorting of PK statements --- .../entityHelpers/primaryKeyHelper.js | 183 ++++++++++++------ 1 file changed, 119 insertions(+), 64 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index 9d86932..034747a 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -9,18 +9,6 @@ const { const amountOfColumnsInRegularPk = 1; -/** - * @return {(collection: AlterCollectionDto) => boolean} - * */ - -/** - * @param entityName {string} - * @return {string} - * */ -const getDefaultConstraintName = (entityName) => { - return `${entityName}_pk`; -} - class PkTransitionDto { /** @@ -55,6 +43,56 @@ class PkTransitionDto { } +class PkScriptModificationDto { + + /** + * @type string + * */ + script + + /** + * @type boolean + * */ + isDropScript + + /** + * @type {string} + * */ + fullTableName + + /** + * @type {boolean} + * */ + isActivated + + /** + * @param fullTableName {string} + * @param script {string} + * @param isDropScript {boolean} + * @param isActivated {boolean} + * */ + constructor( + script, + fullTableName, + isDropScript, + isActivated + ) { + this.script = script; + this.isDropScript = isDropScript; + this.fullTableName = fullTableName; + this.isActivated = isActivated; + } + +} + +/** + * @param entityName {string} + * @return {string} + * */ +const getDefaultConstraintName = (entityName) => { + return `${entityName}_pk`; +} + /** * @param optionHolder {AlterCollectionColumnPrimaryKeyOptionDto} * @return {} @@ -64,15 +102,7 @@ const extractOptionsForComparisonWithRegularPkOptions = (optionHolder) => { constraintName: optionHolder.constraintName, indexStorageParameters: optionHolder.indexStorageParameters, indexTablespace: optionHolder.indexTablespace, - indexInclude: optionHolder.indexInclude?.map(e => { - const indexIncludeEntry = { - keyId: e.keyId, - } - if (e.type) { - indexIncludeEntry.type = e.type; - } - return indexIncludeEntry; - }), + indexInclude: optionHolder.indexInclude, } } @@ -255,9 +285,9 @@ const getCreateCompositePKDDLProviderConfig = (_) => ( } /** - * @return {(collection: AlterCollectionDto) => Array} + * @return {(collection: AlterCollectionDto) => Array} * */ -const getAddCompositePkScripts = (_, ddlProvider) => (collection) => { +const getAddCompositePkScriptDtos = (_, ddlProvider) => (collection) => { const { getFullCollectionName, getSchemaOfAlterCollection, @@ -291,21 +321,20 @@ const getAddCompositePkScripts = (_, ddlProvider) => (collection) => { return newPrimaryKeys .map((newPk) => { const ddlConfig = getCreateCompositePKDDLProviderConfig(_)(newPk, entityName, collection); - return ddlProvider.createKeyConstraint( + const statementDto = ddlProvider.createKeyConstraint( fullTableName, collection.isActivated, ddlConfig ); + return new PkScriptModificationDto(statementDto.statement, fullTableName, false, statementDto.isActivated); }) - .filter(Boolean) - .map(scriptDto => AlterScriptDto.getInstance([scriptDto.statement], scriptDto.isActivated, false)) - .filter(Boolean); + .filter(scriptDto => Boolean(scriptDto.script)); } /** - * @return {(collection: AlterCollectionDto) => Array} + * @return {(collection: AlterCollectionDto) => Array} * */ -const getDropCompositePkScripts = (_, ddlProvider) => (collection) => { +const getDropCompositePkScriptDtos = (_, ddlProvider) => (collection) => { const { getFullCollectionName, getSchemaOfAlterCollection, @@ -336,26 +365,27 @@ const getDropCompositePkScripts = (_, ddlProvider) => (collection) => { return oldPrimaryKeys .map((oldPk) => { - let constraintName = wrapInQuotes(getDefaultConstraintName(entityName)); + let constraintName = getDefaultConstraintName(entityName); if (oldPk.constraintName) { - constraintName = wrapInQuotes(oldPk.constraintName); + constraintName = oldPk.constraintName; } - return ddlProvider.dropPkConstraint(fullTableName, constraintName); + const ddlConstraintName = wrapInQuotes(constraintName); + const script = ddlProvider.dropPkConstraint(fullTableName, ddlConstraintName); + return new PkScriptModificationDto(script, fullTableName, true, collection.isActivated); }) - .map(scriptLine => AlterScriptDto.getInstance([scriptLine], collection.isActivated, true)) - .filter(Boolean); + .filter(scriptDto => Boolean(scriptDto.script)); } /** - * @return {(collection: AlterCollectionDto) => Array} + * @return {(collection: AlterCollectionDto) => Array} * */ -const getModifyCompositePkScripts = (_, ddlProvider) => (collection) => { - const dropCompositePkScripts = getDropCompositePkScripts(_, ddlProvider)(collection); - const addCompositePkScripts = getAddCompositePkScripts(_, ddlProvider)(collection); +const getModifyCompositePkScriptDtos = (_, ddlProvider) => (collection) => { + const dropCompositePkScriptDtos = getDropCompositePkScriptDtos(_, ddlProvider)(collection); + const addCompositePkScriptDtos = getAddCompositePkScriptDtos(_, ddlProvider)(collection); return [ - ...dropCompositePkScripts, - ...addCompositePkScripts, + ...dropCompositePkScriptDtos, + ...addCompositePkScriptDtos, ].filter(Boolean); } @@ -587,9 +617,9 @@ const wasRegularPkModified = (_) => (columnJsonSchema, collection) => { } /** - * @return {(collection: AlterCollectionDto) => Array} + * @return {(collection: AlterCollectionDto) => Array} * */ -const getAddPkScripts = (_, ddlProvider) => (collection) => { +const getAddPkScriptDtos = (_, ddlProvider) => (collection) => { const { getFullCollectionName, getSchemaOfAlterCollection, @@ -613,20 +643,20 @@ const getAddPkScripts = (_, ddlProvider) => (collection) => { }) .map(([name, jsonSchema]) => { const ddlConfig = getCreateRegularPKDDLProviderConfig(_)(name, jsonSchema, entityName, collection); - return ddlProvider.createKeyConstraint( + const statementDto = ddlProvider.createKeyConstraint( fullTableName, collection.isActivated, ddlConfig ); + return new PkScriptModificationDto(statementDto.statement, fullTableName, false, statementDto.isActivated); }) - .map(scriptDto => AlterScriptDto.getInstance([scriptDto.statement], scriptDto.isActivated, false)) - .filter(Boolean); + .filter(scriptDto => Boolean(scriptDto.script)); } /** - * @return {(collection: AlterCollectionDto) => Array} + * @return {(collection: AlterCollectionDto) => Array} * */ -const getDropPkScript = (_, ddlProvider) => (collection) => { +const getDropPkScriptDto = (_, ddlProvider) => (collection) => { const { getFullCollectionName, getSchemaOfAlterCollection, @@ -652,37 +682,62 @@ const getDropPkScript = (_, ddlProvider) => (collection) => { .map(([name, jsonSchema]) => { const oldName = jsonSchema.compMod.oldField.name; const oldJsonSchema = collection.role.properties[oldName]; - const constraintName = wrapInQuotes(getConstraintNameForRegularPk(oldJsonSchema, entityName)); - return ddlProvider.dropPkConstraint(fullTableName, constraintName); + const ddlConstraintName = wrapInQuotes(getConstraintNameForRegularPk(oldJsonSchema, entityName)); + + const script = ddlProvider.dropPkConstraint(fullTableName, ddlConstraintName); + return new PkScriptModificationDto(script, fullTableName, true, collection.isActivated); }) - .map(scriptLine => AlterScriptDto.getInstance([scriptLine], collection.isActivated, true)) - .filter(Boolean); + .filter(scriptDto => Boolean(scriptDto.script)); } /** - * @return {(collection: AlterCollectionDto) => Array} + * @return {(collection: AlterCollectionDto) => Array} * */ -const getModifyPkScripts = (_, ddlProvider) => (collection) => { - const dropPkScripts = getDropPkScript(_, ddlProvider)(collection); - const addPkScripts = getAddPkScripts(_, ddlProvider)(collection); +const getModifyPkScriptDtos = (_, ddlProvider) => (collection) => { + const dropPkScriptDtos = getDropPkScriptDto(_, ddlProvider)(collection); + const addPkScriptDtos = getAddPkScriptDtos(_, ddlProvider)(collection); return [ - ...dropPkScripts, - ...addPkScripts, + ...dropPkScriptDtos, + ...addPkScriptDtos, ].filter(Boolean); } +/** + * @param constraintDtos {PkScriptModificationDto[]} + * @return {PkScriptModificationDto[]} + * */ +const sortModifyPkConstraints = (constraintDtos) => { + return constraintDtos.sort((c1, c2) => { + if (c1.fullTableName === c2.fullTableName) { + // Number(true) = 1, Number(false) = 0; + // This ensures that DROP script appears before CREATE script + // if the same table has 2 scripts that drop and recreate PK + return Number(c2.isDropScript) - Number(c1.isDropScript); + } + // This sorts all statements based on full table name, ASC + return c1.fullTableName < c2.fullTableName; + }); +} + /** * @return {(collection: AlterCollectionDto) => Array} * */ const getModifyPkConstraintsScriptDtos = (_, ddlProvider) => (collection) => { - const modifyCompositePkScripts = getModifyCompositePkScripts(_, ddlProvider)(collection); - const modifyPkScripts = getModifyPkScripts(_, ddlProvider)(collection); - - return [ - ...modifyCompositePkScripts, - ...modifyPkScripts, - ].filter(Boolean); + const modifyCompositePkScriptDtos = getModifyCompositePkScriptDtos(_, ddlProvider)(collection); + const modifyPkScriptDtos = getModifyPkScriptDtos(_, ddlProvider)(collection); + + const allDtos = [ + ...modifyCompositePkScriptDtos, + ...modifyPkScriptDtos, + ]; + const sortedAllDtos = sortModifyPkConstraints(allDtos); + + return sortedAllDtos + .map(dto => { + return AlterScriptDto.getInstance([dto.script], dto.isActivated, dto.isDropScript); + }) + .filter(Boolean); } module.exports = { From 0a944e08e54f5f7d758d9c6313c26f4e16c371da Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jun 2023 17:46:17 +0300 Subject: [PATCH 09/14] removing empty strings is back; --- .../entityHelpers/primaryKeyHelper.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index 034747a..270def0 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -102,7 +102,15 @@ const extractOptionsForComparisonWithRegularPkOptions = (optionHolder) => { constraintName: optionHolder.constraintName, indexStorageParameters: optionHolder.indexStorageParameters, indexTablespace: optionHolder.indexTablespace, - indexInclude: optionHolder.indexInclude, + indexInclude: optionHolder.indexInclude?.map(e => { + const indexIncludeEntry = { + keyId: e.keyId, + } + if (e.type) { + indexIncludeEntry.type = e.type; + } + return indexIncludeEntry; + }), } } From c603afc700d70769d935704c6c73ec06adaea150 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jun 2023 18:03:33 +0300 Subject: [PATCH 10/14] Removed sanitizing of empty strings --- .../entityHelpers/primaryKeyHelper.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index 270def0..034747a 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -102,15 +102,7 @@ const extractOptionsForComparisonWithRegularPkOptions = (optionHolder) => { constraintName: optionHolder.constraintName, indexStorageParameters: optionHolder.indexStorageParameters, indexTablespace: optionHolder.indexTablespace, - indexInclude: optionHolder.indexInclude?.map(e => { - const indexIncludeEntry = { - keyId: e.keyId, - } - if (e.type) { - indexIncludeEntry.type = e.type; - } - return indexIncludeEntry; - }), + indexInclude: optionHolder.indexInclude, } } From 2bd759fd3ed427ab0527114ac7323a7d03a42016 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Jun 2023 11:21:47 +0300 Subject: [PATCH 11/14] More consistent naming of PKs with Postgres spec --- .../alterScriptHelpers/entityHelpers/primaryKeyHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js index 034747a..40b2029 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/primaryKeyHelper.js @@ -90,7 +90,7 @@ class PkScriptModificationDto { * @return {string} * */ const getDefaultConstraintName = (entityName) => { - return `${entityName}_pk`; + return `${entityName}_pkey`; } /** From 6a29535b951ea966c768b9d6548196bc247bd41b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Jun 2023 12:36:57 +0300 Subject: [PATCH 12/14] Made a not-null checkbox mandatory checked if a column is a PK --- .../field_level/fieldLevelConfig.json | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/properties_pane/field_level/fieldLevelConfig.json b/properties_pane/field_level/fieldLevelConfig.json index 31a7301..6423763 100644 --- a/properties_pane/field_level/fieldLevelConfig.json +++ b/properties_pane/field_level/fieldLevelConfig.json @@ -2,9 +2,9 @@ * Copyright © 2016-2017 by IntegrIT S.A. dba Hackolade. All rights reserved. * * The copyright to the computer software herein is the property of IntegrIT S.A. -* The software may be used and/or copied only with the written permission of -* IntegrIT S.A. or in accordance with the terms and conditions stipulated in -* the agreement/contract under which the software has been supplied. +* The software may be used and/or copied only with the written permission of +* IntegrIT S.A. or in accordance with the terms and conditions stipulated in +* the agreement/contract under which the software has been supplied. In order to define custom properties for any object's properties pane, you may copy/paste from the following, @@ -71,8 +71,8 @@ making sure that you maintain a proper JSON format. ] }, // “groupInput” can have the following states - 0 items, 1 item, and many items. -// “blockInput” has only 2 states - 0 items or 1 item. -// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing +// “blockInput” has only 2 states - 0 items or 1 item. +// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing // and forward-engineering in particular. { "propertyName": "Block", @@ -100,7 +100,7 @@ making sure that you maintain a proper JSON format. "propertyKeyword": "keyList", "propertyType": "fieldList", "template": "orderedList" - }, + }, { "propertyName": "List with attribute", "propertyKeyword": "keyListOrder", @@ -193,7 +193,33 @@ making sure that you maintain a proper JSON format. "propertyName": "Not null", "propertyKeyword": "required", "enableForReference": true, - "propertyType": "checkbox" + "propertyType": "checkbox", + "dependency": { + "key": "primaryKey", + "value": true + }, + "disabled": true, + "defaultValue": true + }, + { + "propertyName": "Not null", + "propertyKeyword": "required", + "enableForReference": true, + "propertyType": "checkbox", + "dependency": { + "type": "or", + "values": [ + { + "key": "primaryKey", + "value": false + }, + { + "key": "primaryKey", + "exists": false + } + ] + }, + "defaultValue": false }, "default", { @@ -214,7 +240,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -1123,7 +1149,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -1608,7 +1634,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -2082,7 +2108,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -2518,7 +2544,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -3059,7 +3085,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -3475,7 +3501,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -3912,7 +3938,7 @@ making sure that you maintain a proper JSON format. "tooltip": "This column is part of the table composite primary key definition. Please refer to this definition if you want more information or to update the Primary Key definition", "dependency": { "key": "compositePrimaryKey", - "value": true + "value": true } }, { @@ -4771,4 +4797,4 @@ making sure that you maintain a proper JSON format. } ] } -} \ No newline at end of file +} From ce9ba0cdf7b3a405093c99d4cc75661d38655e96 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Jun 2023 14:12:34 +0300 Subject: [PATCH 13/14] not-null checkbox rollback --- .../field_level/fieldLevelConfig.json | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/properties_pane/field_level/fieldLevelConfig.json b/properties_pane/field_level/fieldLevelConfig.json index 6423763..ca31f1c 100644 --- a/properties_pane/field_level/fieldLevelConfig.json +++ b/properties_pane/field_level/fieldLevelConfig.json @@ -193,33 +193,7 @@ making sure that you maintain a proper JSON format. "propertyName": "Not null", "propertyKeyword": "required", "enableForReference": true, - "propertyType": "checkbox", - "dependency": { - "key": "primaryKey", - "value": true - }, - "disabled": true, - "defaultValue": true - }, - { - "propertyName": "Not null", - "propertyKeyword": "required", - "enableForReference": true, - "propertyType": "checkbox", - "dependency": { - "type": "or", - "values": [ - { - "key": "primaryKey", - "value": false - }, - { - "key": "primaryKey", - "exists": false - } - ] - }, - "defaultValue": false + "propertyType": "checkbox" }, "default", { From c39edd64af0f9b0321cc96722e0109cc6ba95b0c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Jun 2023 14:33:56 +0300 Subject: [PATCH 14/14] placed back not-null checkbox sync with primary key checkbox --- .../field_level/fieldLevelConfig.json | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/properties_pane/field_level/fieldLevelConfig.json b/properties_pane/field_level/fieldLevelConfig.json index ca31f1c..6423763 100644 --- a/properties_pane/field_level/fieldLevelConfig.json +++ b/properties_pane/field_level/fieldLevelConfig.json @@ -193,7 +193,33 @@ making sure that you maintain a proper JSON format. "propertyName": "Not null", "propertyKeyword": "required", "enableForReference": true, - "propertyType": "checkbox" + "propertyType": "checkbox", + "dependency": { + "key": "primaryKey", + "value": true + }, + "disabled": true, + "defaultValue": true + }, + { + "propertyName": "Not null", + "propertyKeyword": "required", + "enableForReference": true, + "propertyType": "checkbox", + "dependency": { + "type": "or", + "values": [ + { + "key": "primaryKey", + "value": false + }, + { + "key": "primaryKey", + "exists": false + } + ] + }, + "defaultValue": false }, "default", {