-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathoptionsHelper.js
More file actions
43 lines (35 loc) · 1.32 KB
/
optionsHelper.js
File metadata and controls
43 lines (35 loc) · 1.32 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
const _ = require('lodash');
const { getFullName, wrapByBackticks, escapeQuotes } = require('../../../helpers/utils');
const templates = require('../../../configs/templates');
const columnOptions = {
'description': 'description',
};
const getModifiedColumnOptionScripts = ({ collection, app, tableData }) => {
const { assignTemplates } = app.require('@hackolade/ddl-fe-utils');
const { tab } = app.require('@hackolade/ddl-fe-utils').general;
return _.toPairs(collection.properties)
.map(([name, jsonSchema]) => {
const oldName = jsonSchema.compMod.oldField.name;
const optionsToUpdate = [];
Object.entries(columnOptions).forEach(([customOptionName, columnOptionName]) => {
const newOptionValue = jsonSchema[customOptionName];
const oldOptionValue = collection.role.properties[oldName]?.[customOptionName];
if (newOptionValue !== oldOptionValue) {
const value = newOptionValue ? `"${escapeQuotes(newOptionValue)}"` : 'NULL';
optionsToUpdate.push(`${columnOptionName}=${value}`);
}
});
if (!optionsToUpdate.length) {
return '';
}
return assignTemplates(templates.alterColumnOptions, {
tableName: tableData.name,
columnName: wrapByBackticks(name),
options: tab(optionsToUpdate.join(',\n')),
});
})
.filter(Boolean);
};
module.exports = {
getModifiedColumnOptionScripts,
};