Skip to content

Commit e190338

Browse files
HCK-14640: handle index expressions
1 parent c9f2a7c commit e190338

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

forward_engineering/ddlProvider/ddlHelpers/indexHelper.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const {
1010
const assignTemplates = require('../../utils/assignTemplates');
1111
const templates = require('../templates');
1212

13+
/**
14+
* @param {object} params
15+
* @param {Record<string, unknown>} params.index
16+
* @returns {string[]}
17+
*/
18+
const getIndexExpressions = ({ index }) => {
19+
return _.map(index.indxExpression, ({ value = '' }) => _.trim(value)).filter(Boolean);
20+
};
21+
1322
const mapIndexKey = ({ name, sortOrder, nullsOrder, collation, opclass }) => {
1423
const sortOrderStr = sortOrder ? ` ${sortOrder}` : '';
1524
const nullsOrderStr = nullsOrder ? ` ${nullsOrder}` : '';
@@ -20,8 +29,10 @@ const mapIndexKey = ({ name, sortOrder, nullsOrder, collation, opclass }) => {
2029
return `${wrapInQuotes(name)}${collationStr}${opclassStr}${sortOrderStr}${nullsOrderStr}`;
2130
};
2231

23-
const getIndexKeys = ({ columns = [], isParentActivated, isAllColumnsDeactivated }) => {
24-
return getColumnsList(columns, isAllColumnsDeactivated, isParentActivated, mapIndexKey);
32+
const getIndexKeys = ({ columns = [], indexExpressions, isParentActivated, isAllColumnsDeactivated }) => {
33+
return indexExpressions.length
34+
? ' (' + indexExpressions.join(', ') + ')'
35+
: getColumnsList(columns, isAllColumnsDeactivated, isParentActivated, mapIndexKey);
2536
};
2637

2738
const getIndexOptions = (index, isParentActivated) => {
@@ -93,8 +104,10 @@ const getValue = value => {
93104

94105
const createIndex = (tableName, index, dbData, isParentActivated = true) => {
95106
const isNameEmpty = !index.indxName && index.ifNotExist;
107+
const indexExpressions = getIndexExpressions({ index });
108+
const hasKeys = index.columns.length || indexExpressions.length;
96109

97-
if (!index.columns.length || isNameEmpty) {
110+
if (!hasKeys || isNameEmpty) {
98111
return '';
99112
}
100113

@@ -116,6 +129,7 @@ const createIndex = (tableName, index, dbData, isParentActivated = true) => {
116129

117130
const keys = getIndexKeys({
118131
columns: indexColumns,
132+
indexExpressions,
119133
isParentActivated,
120134
isAllColumnsDeactivated,
121135
});

0 commit comments

Comments
 (0)