-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcommon.js
More file actions
84 lines (74 loc) · 2.48 KB
/
common.js
File metadata and controls
84 lines (74 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { isEqual } = require('lodash');
const { escapeQuotes, getTimestamp, getName } = require('../../helpers/utils');
const getCompMod = containerData => containerData.role?.compMod ?? {};
const checkCompModEqual = ({ new: newItem, old: oldItem } = {}) => isEqual(newItem, oldItem);
const setEntityKeys = ({ idToNameHashTable, idToActivatedHashTable, entity }) => {
const setKeyArray = obj =>
Array.isArray(obj)
? obj.map(item => ({
...item,
name: idToNameHashTable[item.keyId],
isActivated: idToActivatedHashTable[item.keyId],
}))
: [];
return {
...entity,
clusteringKey: setKeyArray(entity.clusteringKey),
timeUnitpartitionKey: setKeyArray(entity.timeUnitpartitionKey),
rangeOptions: [
{
...(entity.rangeOptions ?? {}),
rangePartitionKey: setKeyArray(entity.rangeOptions?.rangePartitionKey),
},
],
};
};
const getModifyOptions = ({ jsonSchema, app, options }) => {
const { tab } = app.require('@hackolade/ddl-fe-utils').general;
const { getLabels } = require('../../helpers/general')(app);
const optionsToUpdate = [];
Object.entries(options).forEach(([customOptionName, columnOptionName]) => {
const { new: newOptionValue, old: oldOptionValue } = jsonSchema.compMod[customOptionName] || {};
if (!isEqual(newOptionValue, oldOptionValue)) {
switch (customOptionName) {
case 'businessName': {
const name = getName(jsonSchema.role);
if (name !== newOptionValue) {
const value = newOptionValue ? `"${newOptionValue}"` : 'NULL';
optionsToUpdate.push(`${columnOptionName}=${value}`);
}
break;
}
case 'description': {
const value = newOptionValue ? `"${escapeQuotes(newOptionValue)}"` : 'NULL';
optionsToUpdate.push(`${columnOptionName}=${value}`);
break;
}
case 'expiration': {
const value = newOptionValue ? `TIMESTAMP "${getTimestamp(newOptionValue)}"` : 'NULL';
optionsToUpdate.push(`${columnOptionName}=${value}`);
break;
}
case 'labels': {
const value = newOptionValue.length ? `[\n${tab(getLabels(newOptionValue))}\n]` : 'NULL';
optionsToUpdate.push(`labels=${value}`);
break;
}
default: {
const value = newOptionValue === undefined || newOptionValue === '' ? 'NULL' : newOptionValue;
optionsToUpdate.push(`${columnOptionName}=${value}`);
}
}
}
});
if (!optionsToUpdate.length) {
return '';
}
return tab(optionsToUpdate.join(',\n'));
};
module.exports = {
getCompMod,
checkCompModEqual,
setEntityKeys,
getModifyOptions,
};