Skip to content

Commit 70524ce

Browse files
HCK-13009: comment alter statement for deactivated objects (#162)
* add script generation options config * fix order of constrains in alter statement and fix escape default value logic in alter statement * add browser support * delete unnecessary .then statement * adjust column types whose default values need to be wrapped with escape characters * fix missing COMMENT ON statements for UDT * HCK-13009: comment related alter statement to deactivated objects * delete debugger
1 parent 13aac1d commit 70524ce

File tree

18 files changed

+249
-74
lines changed

18 files changed

+249
-74
lines changed

forward_engineering/alterScript/alterScriptFromDeltaHelper.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const {
3838
getDeleteContainerSequencesScriptDtos,
3939
getAddContainerSequencesScriptDtos,
4040
} = require('./alterScriptHelpers/containerHelpers/sequencesHelper');
41+
const { isObjectInDeltaModelActivated } = require('../utils/general');
4142

4243
/**
4344
* @param dto {{
@@ -53,12 +54,20 @@ const getAlterContainersScriptDtos = ({ collection }) => {
5354
const addContainersScriptDtos = []
5455
.concat(addedContainers)
5556
.filter(Boolean)
56-
.map(container => getAddContainerScriptDto(Object.keys(container.properties)[0]));
57+
.map(container => {
58+
const [containerName, containerData] = Object.entries(container.properties)[0];
59+
const isActivated = isObjectInDeltaModelActivated(containerData);
60+
return getAddContainerScriptDto(containerName, isActivated);
61+
});
5762

5863
const deleteContainersScriptDtos = []
5964
.concat(deletedContainers)
6065
.filter(Boolean)
61-
.map(container => getDeleteContainerScriptDto(Object.keys(container.properties)[0]));
66+
.map(container => {
67+
const [containerName, containerData] = Object.entries(container.properties)[0];
68+
const isActivated = isObjectInDeltaModelActivated(containerData);
69+
return getDeleteContainerScriptDto(containerName, isActivated);
70+
});
6271

6372
const modifyContainersScriptDtos = []
6473
.concat(modifiedContainers)

forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ const dropSchema = schemaName => {
2929

3030
/**
3131
* @param {string} containerName
32+
* @param {boolean} isActivated
3233
* @return {AlterScriptDto | undefined}
3334
* */
34-
const getAddContainerScriptDto = containerName => {
35+
const getAddContainerScriptDto = (containerName, isActivated = true) => {
3536
const script = createSchemaOnly(wrapInQuotes(containerName));
36-
return AlterScriptDto.getInstance([script], true, false);
37+
return AlterScriptDto.getInstance([script], isActivated, false);
3738
};
3839

3940
/**
4041
* @param {string} containerName
42+
* @param {boolean} isActivated
4143
* @return {AlterScriptDto | undefined}
4244
* */
43-
const getDeleteContainerScriptDto = containerName => {
45+
const getDeleteContainerScriptDto = (containerName, isActivated = true) => {
4446
const script = dropSchema(wrapInQuotes(containerName));
45-
return AlterScriptDto.getInstance([script], true, true);
47+
return AlterScriptDto.getInstance([script], isActivated, true);
4648
};
4749

4850
/**

forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ const {
1515
getAdditionalDataForDdlProvider,
1616
} = require('./entityHelpers/indexesHelper');
1717
const { getModifiedDefaultColumnValueScriptDtos } = require('./columnHelpers/defaultValueHelper');
18-
const { getEntityName, getFullTableName, getNamePrefixedWithSchemaName, wrapInQuotes } = require('../../utils/general');
18+
const {
19+
getEntityName,
20+
getFullTableName,
21+
getNamePrefixedWithSchemaName,
22+
wrapInQuotes,
23+
isParentContainerActivated,
24+
isObjectInDeltaModelActivated,
25+
} = require('../../utils/general');
1926

2027
/**
2128
* @return {(collection: AlterCollectionDto) => AlterScriptDto | undefined}
@@ -124,6 +131,9 @@ const getAddColumnsByConditionScriptDtos =
124131
const fullName = getNamePrefixedWithSchemaName(tableName, schemaName);
125132
const schemaData = { schemaName, dbVersion };
126133

134+
const isContainerActivated = isParentContainerActivated(collection);
135+
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
136+
127137
const scripts = _.toPairs(collection.properties)
128138
.filter(([name, jsonSchema]) => predicate([name, jsonSchema]))
129139
.map(([name, jsonSchema]) => {
@@ -134,18 +144,22 @@ const getAddColumnsByConditionScriptDtos =
134144
externalDefinitions,
135145
});
136146

137-
return createColumnDefinitionBySchema({
147+
const columnDefinition = createColumnDefinitionBySchema({
138148
name,
139149
jsonSchema,
140150
parentJsonSchema: collectionSchema,
141151
ddlProvider,
142152
schemaData,
143153
definitionJsonSchema,
144154
});
155+
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
156+
return { columnDefinition, isActivated };
145157
})
146-
.map(ddlProvider.convertColumnDefinition)
147-
.map(columnDefinition => ddlProvider.addColumn(fullName, columnDefinition))
148-
.map(addColumnScript => AlterScriptDto.getInstance([addColumnScript], true, false));
158+
.map(({ columnDefinition, isActivated }) => ({
159+
script: ddlProvider.addColumn(fullName, ddlProvider.convertColumnDefinition(columnDefinition)),
160+
isActivated,
161+
}))
162+
.map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false));
149163

150164
return scripts.filter(Boolean);
151165
};
@@ -204,13 +218,17 @@ const getDeleteColumnsByConditionScriptDtos = app => (collection, predicate) =>
204218
const schemaName = collectionSchema.compMod?.keyspaceName;
205219
const fullTableName = getNamePrefixedWithSchemaName(tableName, schemaName);
206220

221+
const isContainerActivated = isParentContainerActivated(collection);
222+
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
223+
207224
return _.toPairs(collection.properties)
208225
.filter(([name, jsonSchema]) => predicate([name, jsonSchema]))
209-
.map(([name]) => {
226+
.map(([name, jsonSchema]) => {
210227
const columnNameForDDL = wrapInQuotes(name);
211-
return ddlProvider.dropColumn(fullTableName, columnNameForDDL);
228+
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
229+
return { script: ddlProvider.dropColumn(fullTableName, columnNameForDDL), isActivated };
212230
})
213-
.map(dropColumnScript => AlterScriptDto.getInstance([dropColumnScript], true, true))
231+
.map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, true))
214232
.filter(Boolean);
215233
};
216234

forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const _ = require('lodash');
22
const { AlterScriptDto } = require('../types/AlterScriptDto');
3-
const { getUdtName, wrapInQuotes, checkFieldPropertiesChanged } = require('../../utils/general');
3+
const {
4+
getUdtName,
5+
wrapInQuotes,
6+
checkFieldPropertiesChanged,
7+
isObjectInDeltaModelActivated,
8+
} = require('../../utils/general');
49

510
/**
611
* @return {(jsonSchema: Object) => AlterScriptDto | undefined}
@@ -44,7 +49,7 @@ const getCreateUdtScriptDto =
4449
const udt = { ...updatedUdt, properties: columnDefinitions };
4550

4651
const script = ddlProvider.createUdt(udt);
47-
return AlterScriptDto.getInstance([script], true, false);
52+
return AlterScriptDto.getInstance([script], jsonSchema.isActivated, false);
4853
};
4954

5055
/**
@@ -56,10 +61,10 @@ const getDeleteUdtScriptDto = app => udt => {
5661
const ddlUdtName = wrapInQuotes(getUdtName(udt));
5762
if (udt.type === 'domain') {
5863
const script = ddlProvider.dropDomain(ddlUdtName);
59-
return AlterScriptDto.getInstance([script], true, true);
64+
return AlterScriptDto.getInstance([script], udt.isActivated, true);
6065
} else {
6166
const script = ddlProvider.dropType(ddlUdtName);
62-
return AlterScriptDto.getInstance([script], true, true);
67+
return AlterScriptDto.getInstance([script], udt.isActivated, true);
6368
}
6469
};
6570

@@ -97,7 +102,7 @@ const getAddColumnToTypeScriptDtos =
97102
})
98103
.map(ddlProvider.convertColumnDefinition)
99104
.map(columnDefinition => ddlProvider.alterTypeAddAttribute(fullName, columnDefinition))
100-
.map(script => AlterScriptDto.getInstance([script], true, false))
105+
.map(script => AlterScriptDto.getInstance([script], udt.isActivated, false))
101106
.filter(Boolean);
102107
};
103108

@@ -108,11 +113,12 @@ const getDeleteColumnFromTypeScriptDtos = app => udt => {
108113
const ddlProvider = require('../../ddlProvider/ddlProvider')(null, null, app);
109114

110115
const fullName = wrapInQuotes(udt.code || udt.name);
116+
const isActivated = isObjectInDeltaModelActivated(udt);
111117

112118
return _.toPairs(udt.properties)
113119
.filter(([name, jsonSchema]) => !jsonSchema.compMod)
114120
.map(([name]) => ddlProvider.alterTypeDropAttribute(fullName, wrapInQuotes(name)))
115-
.map(script => AlterScriptDto.getInstance([script], true, true))
121+
.map(script => AlterScriptDto.getInstance([script], isActivated, true))
116122
.filter(Boolean);
117123
};
118124

@@ -123,6 +129,7 @@ const getModifyColumnOfTypeScriptDtos = app => udt => {
123129
const ddlProvider = require('../../ddlProvider/ddlProvider')(null, null, app);
124130

125131
const fullName = wrapInQuotes(udt.code || udt.name);
132+
const isActivated = isObjectInDeltaModelActivated(udt);
126133

127134
const renameColumnScripts = _.values(udt.properties)
128135
.filter(jsonSchema => checkFieldPropertiesChanged(jsonSchema.compMod, ['name']))
@@ -131,7 +138,7 @@ const getModifyColumnOfTypeScriptDtos = app => udt => {
131138
const newAttributeDDLName = wrapInQuotes(jsonSchema.compMod.newField.name);
132139
return ddlProvider.alterTypeRenameAttribute(fullName, oldAttributeDDLName, newAttributeDDLName);
133140
})
134-
.map(script => AlterScriptDto.getInstance([script], true, false));
141+
.map(script => AlterScriptDto.getInstance([script], isActivated, false));
135142

136143
const changeTypeScripts = _.toPairs(udt.properties)
137144
.filter(([name, jsonSchema]) => checkFieldPropertiesChanged(jsonSchema.compMod, ['type', 'mode']))
@@ -140,7 +147,7 @@ const getModifyColumnOfTypeScriptDtos = app => udt => {
140147
const newDataType = jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type;
141148
return ddlProvider.alterTypeChangeAttributeType(fullName, attributeDDLName, newDataType);
142149
})
143-
.map(script => AlterScriptDto.getInstance([script], true, false));
150+
.map(script => AlterScriptDto.getInstance([script], isActivated, false));
144151

145152
return [...renameColumnScripts, ...changeTypeScripts].filter(Boolean);
146153
};

forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const _ = require('lodash');
22
const { AlterScriptDto } = require('../../types/AlterScriptDto');
3-
const { checkFieldPropertiesChanged, getFullTableName, wrapInQuotes } = require('../../../utils/general');
3+
const {
4+
checkFieldPropertiesChanged,
5+
getFullTableName,
6+
wrapInQuotes,
7+
isObjectInDeltaModelActivated,
8+
isParentContainerActivated,
9+
} = require('../../../utils/general');
410
const assignTemplates = require('../../../utils/assignTemplates');
511
const templates = require('../../../ddlProvider/templates');
612

@@ -63,6 +69,8 @@ const hasPrecisionOrScaleChanged = (collection, oldFieldName, currentJsonSchema)
6369
* */
6470
const getUpdateTypesScriptDtos = collection => {
6571
const fullTableName = getFullTableName(collection);
72+
const isContainerActivated = isParentContainerActivated(collection);
73+
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
6674

6775
return _.toPairs(collection.properties)
6876
.filter(([name, jsonSchema]) => {
@@ -79,9 +87,10 @@ const getUpdateTypesScriptDtos = collection => {
7987
const typeName = jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type;
8088
const columnName = wrapInQuotes(name);
8189
const typeConfig = _.pick(jsonSchema, ['length', 'precision', 'scale']);
82-
return alterColumnType(fullTableName, columnName, typeName, typeConfig);
90+
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
91+
return { script: alterColumnType(fullTableName, columnName, typeName, typeConfig), isActivated };
8392
})
84-
.map(script => AlterScriptDto.getInstance([script], true, false));
93+
.map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false));
8594
};
8695

8796
module.exports = {

forward_engineering/alterScript/alterScriptHelpers/columnHelpers/commentsHelper.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const _ = require('lodash');
22
const { AlterScriptDto } = require('../../types/AlterScriptDto');
3-
const { getFullColumnName, wrapComment } = require('../../../utils/general');
3+
const {
4+
getFullColumnName,
5+
wrapComment,
6+
isObjectInDeltaModelActivated,
7+
isParentContainerActivated,
8+
} = require('../../../utils/general');
49
const assignTemplates = require('../../../utils/assignTemplates');
510
const templates = require('../../../ddlProvider/templates');
611

@@ -22,6 +27,8 @@ const updateColumnComment = (columnName, comment) => {
2227
* @return {AlterScriptDto[]}
2328
* */
2429
const getUpdatedCommentOnColumnScriptDtos = collection => {
30+
const isContainerActivated = isParentContainerActivated(collection);
31+
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
2532
return _.toPairs(collection.properties)
2633
.filter(([name, jsonSchema]) => {
2734
const newComment = jsonSchema.description;
@@ -33,9 +40,10 @@ const getUpdatedCommentOnColumnScriptDtos = collection => {
3340
const newComment = jsonSchema.description;
3441
const ddlComment = wrapComment(newComment);
3542
const columnName = getFullColumnName(collection, name);
36-
return updateColumnComment(columnName, ddlComment);
43+
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
44+
return { script: updateColumnComment(columnName, ddlComment), isActivated };
3745
})
38-
.map(script => AlterScriptDto.getInstance([script], true, false));
46+
.map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false));
3947
};
4048

4149
/**
@@ -55,6 +63,8 @@ const dropColumnComment = columnName => {
5563
* @return {AlterScriptDto[]}
5664
* */
5765
const getDeletedCommentOnColumnScriptDtos = collection => {
66+
const isContainerActivated = isParentContainerActivated(collection);
67+
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
5868
return _.toPairs(collection.properties)
5969
.filter(([name, jsonSchema]) => {
6070
const newComment = jsonSchema.description;
@@ -64,9 +74,10 @@ const getDeletedCommentOnColumnScriptDtos = collection => {
6474
})
6575
.map(([name, jsonSchema]) => {
6676
const columnName = getFullColumnName(collection, name);
67-
return dropColumnComment(columnName);
77+
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
78+
return { script: dropColumnComment(columnName), isActivated };
6879
})
69-
.map(script => AlterScriptDto.getInstance([script], true, true));
80+
.map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, true));
7081
};
7182

7283
/**

forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const { toPairs } = require('lodash');
22
const { AlterScriptDto } = require('../../types/AlterScriptDto');
3-
const { getFullTableName, wrapInQuotes } = require('../../../utils/general');
3+
const {
4+
getFullTableName,
5+
wrapInQuotes,
6+
isObjectInDeltaModelActivated,
7+
isParentContainerActivated,
8+
} = require('../../../utils/general');
49
const { decorateDefault } = require('../../../ddlProvider/ddlHelpers/columnDefinitionHelper');
510
const assignTemplates = require('../../../utils/assignTemplates');
611
const templates = require('../../../ddlProvider/templates');
@@ -26,8 +31,11 @@ const updateColumnDefaultValue = ({ tableName, columnName, defaultValue }) => {
2631
* @param {Object} props.collection
2732
* @returns { Array<AlterScriptDto> }
2833
* */
29-
const getUpdatedDefaultColumnValueScriptDtos = ({ collection }) =>
30-
toPairs(collection.properties)
34+
const getUpdatedDefaultColumnValueScriptDtos = ({ collection }) => {
35+
const isContainerActivated = isParentContainerActivated(collection);
36+
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
37+
38+
return toPairs(collection.properties)
3139
.filter(([_name, jsonSchema]) => {
3240
const newDefault = jsonSchema.default;
3341
const oldName = jsonSchema.compMod.oldField.name;
@@ -43,10 +51,12 @@ const getUpdatedDefaultColumnValueScriptDtos = ({ collection }) =>
4351
columnName: wrapInQuotes(columnName),
4452
defaultValue: decorateDefault(type, newDefaultValue, isArrayType),
4553
};
46-
return updateColumnDefaultValue(scriptGenerationConfig);
54+
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
55+
return { script: updateColumnDefaultValue(scriptGenerationConfig), isActivated };
4756
})
48-
.map(script => AlterScriptDto.getInstance([script], true, false))
57+
.map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, false))
4958
.filter(Boolean);
59+
};
5060

5161
/**
5262
* @param {Object} props
@@ -67,8 +77,11 @@ const dropColumnDefaultValue = ({ tableName, columnName }) => {
6777
* @param {Object} props.collection
6878
* @returns { Array<AlterScriptDto> }
6979
* */
70-
const getDeletedDefaultColumnValueScriptDtos = ({ collection }) =>
71-
toPairs(collection.properties)
80+
const getDeletedDefaultColumnValueScriptDtos = ({ collection }) => {
81+
const isContainerActivated = isParentContainerActivated(collection);
82+
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
83+
84+
return toPairs(collection.properties)
7285
.filter(([_name, jsonSchema]) => {
7386
const newDefault = jsonSchema.default;
7487
const oldName = jsonSchema.compMod.oldField.name;
@@ -77,15 +90,17 @@ const getDeletedDefaultColumnValueScriptDtos = ({ collection }) =>
7790
const hasNewValue = newDefault !== undefined;
7891
return hasPrevValue && !hasNewValue;
7992
})
80-
.map(([columnName]) => {
93+
.map(([columnName, jsonSchema]) => {
8194
const scriptGenerationConfig = {
8295
tableName: getFullTableName(collection),
8396
columnName: wrapInQuotes(columnName),
8497
};
85-
return dropColumnDefaultValue(scriptGenerationConfig);
98+
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
99+
return { script: dropColumnDefaultValue(scriptGenerationConfig), isActivated };
86100
})
87-
.map(script => AlterScriptDto.getInstance([script], true, true))
101+
.map(({ script, isActivated }) => AlterScriptDto.getInstance([script], isActivated, true))
88102
.filter(Boolean);
103+
};
89104

90105
/**
91106
* @param {Object} props

0 commit comments

Comments
 (0)