Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions forward_engineering/ddlProvider/ddlHelpers/indexHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@ module.exports = ({ prepareName, getNamePrefixedWithSchemaName }) => {
return ` ${getNamePrefixedWithSchemaName(index.indxName, schemaName)}`;
};

/**
* Builds the LOCAL/GLOBAL partition clause for CREATE INDEX.
* Partition options are emitted before other index attributes per Oracle CREATE INDEX syntax.
*
* @param {Pick<IndexDto, 'indxPartitionScope' | 'indxPartitionClause'>} param0
* @param {'local' | 'global' | '' | undefined} [param0.indxPartitionScope]
* @param {string | undefined} [param0.indxPartitionClause] Clause appended after LOCAL or GLOBAL (e.g. `STORE IN (...)` or `PARTITION BY RANGE (...)`).
* @returns {string} ` LOCAL`, ` LOCAL <clause>`, ` GLOBAL <clause>`, or an empty string.
*/
const getIndexPartitionOptions = ({ indxPartitionScope, indxPartitionClause }) => {
const scope = _.toLower(_.trim(indxPartitionScope));
const clause = _.trim(indxPartitionClause);

if (!scope) {
return '';
}

if (scope === 'local') {
return clause ? ` LOCAL ${clause}` : ' LOCAL';
}

if (scope === 'global') {
if (!clause) {
return '';
}

return ` GLOBAL ${clause}`;
}

return '';
};

/**
* @param indxKey {Array<Object> | undefined}
* @param column_expression {string | undefined}
Expand All @@ -50,6 +82,13 @@ module.exports = ({ prepareName, getNamePrefixedWithSchemaName }) => {
return '';
};

/**
* Builds index options for CREATE INDEX and ALTER INDEX ... REBUILD statements.
* Partition options precede logging, tablespace, compression, and free-form index properties.
*
* @param {IndexDto} param0
* @returns {string}
*/
const getIndexOptions = ({
indxDescription,
comments,
Expand All @@ -60,17 +99,20 @@ module.exports = ({ prepareName, getNamePrefixedWithSchemaName }) => {
logging_clause,
indxKey,
column_expression,
indxPartitionScope,
indxPartitionClause,
}) => {
const partitionOptions = getIndexPartitionOptions({ indxPartitionScope, indxPartitionClause });
const loggingClause = logging_clause ? ` ${_.toUpper(logging_clause)}` : '';
const tableSpacePart = tablespace ? ` TABLESPACE ${tablespace}` : '';
const indexCompression = index_compression ? ` ${index_compression}` : '';

let options = `${loggingClause}${tableSpacePart}${indexCompression}`;
let options = `${partitionOptions}${loggingClause}${tableSpacePart}${indexCompression}`;

if (index_properties) {
options = ` ${normalizeLineEndings(index_properties)}`;
options = `${partitionOptions} ${normalizeLineEndings(index_properties)}`;
} else if (index_attributes) {
options = ` ${normalizeLineEndings(index_attributes)}`;
options = `${partitionOptions} ${normalizeLineEndings(index_attributes)}`;
}
const isKeysEmpty = _.isEmpty(indxKey) && _.isEmpty(column_expression);

Expand Down
2 changes: 2 additions & 0 deletions forward_engineering/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ export type IndexDto = {
index_compression?: string;
logging_clause?: string;
indexAnnotations?: Annotation[];
indxPartitionScope?: string;
indxPartitionClause?: string;
indxComments?: string;
};
17 changes: 17 additions & 0 deletions properties_pane/entity_level/entityLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,23 @@ making sure that you maintain a proper JSON format.
]
}
},
{
"propertyName": "Partition scope",
"propertyKeyword": "indxPartitionScope",
"propertyType": "select",
"defaultValue": "",
"options": ["", "local", "global"]
},
{
"propertyName": "Index partition clause",
"propertyKeyword": "indxPartitionClause",
"propertyType": "details",
"template": "codeEditor",
"markdown": false,
"templateOptions": {
"editorDialect": "sql"
}
},
{
"propertyName": "Comments",
"propertyKeyword": "indxComments",
Expand Down
17 changes: 17 additions & 0 deletions properties_pane/view_level/viewLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,23 @@
"defaultValue": "logging",
"options": ["", "logging", "nologging", "filesystem_like_logging"]
},
{
"propertyName": "Partition scope",
"propertyKeyword": "indxPartitionScope",
"propertyType": "select",
"defaultValue": "",
"options": ["", "local", "global"]
},
{
"propertyName": "Index partition clause",
"propertyKeyword": "indxPartitionClause",
"propertyType": "details",
"template": "codeEditor",
"markdown": false,
"templateOptions": {
"editorDialect": "sql"
}
},
{
"propertyName": "Comments",
"propertyKeyword": "indxComments",
Expand Down
Loading