From 5c5562ce0292ed98a2a5cbff0048fa9bbdfb0c2d Mon Sep 17 00:00:00 2001 From: Vitalii Bedletskyi Date: Tue, 16 Jun 2026 16:43:45 +0300 Subject: [PATCH] HCK-9477: fe for cross schema indexes --- .../ddlProvider/ddlHelpers/indexHelper.js | 21 +++++- .../ddlProvider/ddlProvider.js | 12 ++++ forward_engineering/types.d.ts | 64 ++++++++++++++----- .../entity_level/entityLevelConfig.json | 6 ++ 4 files changed, 85 insertions(+), 18 deletions(-) diff --git a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js index 9e5db0d..2516721 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js @@ -1,13 +1,30 @@ +/** + * @import { IndexDto } from '../../types' + */ + const _ = require('lodash'); -const { escapeSingleQuote, normalizeLineEndings } = require('../../utils/general'); +const { normalizeLineEndings } = require('../../utils/general'); module.exports = ({ prepareName, getNamePrefixedWithSchemaName }) => { const getIndexType = indexType => { return indexType ? ` ${_.toUpper(indexType)}` : ''; }; + /** + * + * @param param0 + * @param {IndexDto} param0.index + * @returns {string} + */ const getIndexName = ({ index }) => { - return index.indxName ? ` ${getNamePrefixedWithSchemaName(index.indxName, index.schemaName)}` : ''; + if (!index.indxName) { + return ''; + } + + // `index.indxSchema` - is custom schema name from cross schema indexes, specified manually by user + // `index.schemaName` - is schema name where the actually table created + const schemaName = index.indxSchema || index.schemaName; + return ` ${getNamePrefixedWithSchemaName(index.indxName, schemaName)}`; }; /** diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index 030a770..78f58ef 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -1,3 +1,7 @@ +/** + * @import { IndexDto } from '../types' + */ + const _ = require('lodash'); const defaultTypes = require('../configs/defaultTypes'); const descriptors = require('../configs/descriptors'); @@ -502,6 +506,14 @@ module.exports = (baseProvider, options, app) => { return { ...indexData, schemaName: schemaData.schemaName, indexAnnotations: indexData.indexAnnotations }; }, + /** + * + * @param {string} tableName + * @param {IndexDto} index + * @param {Record} [dbData] + * @param {boolean} [isParentActivated] + * @returns {string} + */ createIndex(tableName, index, dbData, isParentActivated = true) { const name = getIndexName({ index }); const hasKeys = !!index.indxKey.length || !!_.trim(index.column_expression); diff --git a/forward_engineering/types.d.ts b/forward_engineering/types.d.ts index 093457e..344d627 100644 --- a/forward_engineering/types.d.ts +++ b/forward_engineering/types.d.ts @@ -1,28 +1,60 @@ export type ColumnDefinition = { - name: string; - type: string; - isActivated: boolean; - length?: number; - precision?: number; - primaryKey?: boolean; - scale?: number; - timePrecision?: number; - unique?: boolean; - primaryKeyOptions?: Array<{ GUID: string; constraintName: string }> - uniqueKeyOptions?: Array<{ GUID: string; constraintName: string }> + name: string; + type: string; + isActivated: boolean; + length?: number; + precision?: number; + primaryKey?: boolean; + scale?: number; + timePrecision?: number; + unique?: boolean; + primaryKeyOptions?: Array<{ GUID: string; constraintName: string }>; + uniqueKeyOptions?: Array<{ GUID: string; constraintName: string }>; }; export type ConstraintDtoColumn = { - name: string; - isActivated: boolean; + name: string; + isActivated: boolean; }; export type KeyType = 'PRIMARY KEY' | 'UNIQUE'; export type ConstraintDto = { - keyType: KeyType; - name: string; - columns: ConstraintDtoColumn[]; + keyType: KeyType; + name: string; + columns: ConstraintDtoColumn[]; }; export type JsonSchema = Record; + +export type Annotation = { + annotationName?: string; + annotationValue?: string; +}; + +export type IndexKeyDto = { + name?: string | null; + type?: string; + keyId?: string; +}; + +export type IndexDto = { + id?: string; + indxName?: string; + isActivated?: boolean; + ifNotExist?: boolean; + indxSchema?: string; // cross schema name specified manually by user + indxType?: string; + schemaName?: string; + indxKey: IndexKeyDto[]; + column_expression?: string; + indxDescription?: string; + comments?: string; + tablespace?: string; + index_properties?: string; + index_attributes?: string; + index_compression?: string; + logging_clause?: string; + indexAnnotations?: Annotation[]; + indxComments?: string; +}; diff --git a/properties_pane/entity_level/entityLevelConfig.json b/properties_pane/entity_level/entityLevelConfig.json index 8876435..0c6035a 100644 --- a/properties_pane/entity_level/entityLevelConfig.json +++ b/properties_pane/entity_level/entityLevelConfig.json @@ -1100,6 +1100,12 @@ making sure that you maintain a proper JSON format. "propertyKeyword": "ifNotExist", "propertyType": "checkbox" }, + { + "propertyName": "Index schema", + "propertyKeyword": "indxSchema", + "propertyTooltip": "", + "propertyType": "text" + }, { "propertyName": "Type", "propertyKeyword": "indxType",