From a34f5847befd057d36f4728e695f1667979a77af Mon Sep 17 00:00:00 2001 From: Vitalii Bedletskyi Date: Tue, 23 Jun 2026 13:50:29 +0300 Subject: [PATCH] HCK-16561: add support of global/local cluase for indexes --- .../ddlProvider/ddlHelpers/indexHelper.js | 48 +++++++++++++++++-- forward_engineering/types.d.ts | 2 + .../entity_level/entityLevelConfig.json | 17 +++++++ .../view_level/viewLevelConfig.json | 17 +++++++ 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js index 2516721..87af732 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js @@ -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} 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 `, ` GLOBAL `, 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 | undefined} * @param column_expression {string | undefined} @@ -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, @@ -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); diff --git a/forward_engineering/types.d.ts b/forward_engineering/types.d.ts index 344d627..05d8074 100644 --- a/forward_engineering/types.d.ts +++ b/forward_engineering/types.d.ts @@ -56,5 +56,7 @@ export type IndexDto = { index_compression?: string; logging_clause?: string; indexAnnotations?: Annotation[]; + indxPartitionScope?: string; + indxPartitionClause?: string; indxComments?: string; }; diff --git a/properties_pane/entity_level/entityLevelConfig.json b/properties_pane/entity_level/entityLevelConfig.json index 0c6035a..ad55f20 100644 --- a/properties_pane/entity_level/entityLevelConfig.json +++ b/properties_pane/entity_level/entityLevelConfig.json @@ -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", diff --git a/properties_pane/view_level/viewLevelConfig.json b/properties_pane/view_level/viewLevelConfig.json index ff953a9..ad661df 100644 --- a/properties_pane/view_level/viewLevelConfig.json +++ b/properties_pane/view_level/viewLevelConfig.json @@ -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",