From fcf3d9698dfc62f93f57ffbabd76e3ead3df5999 Mon Sep 17 00:00:00 2001 From: chulanovskyi Date: Thu, 26 Sep 2024 19:37:02 +0300 Subject: [PATCH] feat: added missing options to FE script --- forward_engineering/configs/templates.js | 9 +++++ forward_engineering/ddlProvider.js | 47 +++++++++++++--------- forward_engineering/helpers/tableHelper.js | 20 +++++++++ 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/forward_engineering/configs/templates.js b/forward_engineering/configs/templates.js index fed0813c..994543cc 100644 --- a/forward_engineering/configs/templates.js +++ b/forward_engineering/configs/templates.js @@ -20,12 +20,21 @@ module.exports = { '${warehouse}' + '${externalVolume}' + '${catalog}' + + '${catalogTableName}' + + '${catalogNamespace}' + + '${catalogSync}' + + '${metadataFilePath}' + + '${replaceInvalidCharacters}' + + '${autoRefresh}' + + '${storageSerializationPolicy}' + '${baseLocation}' + '${refreshMode}' + '${initialize}' + '${clusterKeys}' + '${dataRetentionTime}' + '${maxDataExtensionTime}' + + '${changeTracking}' + + '${defaultDdlCollation}' + '${copyGrants}' + '${comment}' + '${tagsStatement}' + diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index ad07854f..6ea7cc94 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -764,38 +764,34 @@ module.exports = (baseProvider, options, app) => { }, hydrateTable({ tableData, entityData, jsonSchema }) { - const keyConstraints = keyHelper.getTableKeyConstraints({ jsonSchema }); const firstTab = head(entityData) ?? {}; + const schemaName = getName(firstTab.isCaseSensitive, get(tableData, 'schemaData.schemaName')); const databaseName = getName(firstTab.isCaseSensitive, get(tableData, 'schemaData.databaseName')); const tableName = getName(firstTab.isCaseSensitive, tableData.name); const fullName = getFullName(databaseName, getFullName(schemaName, tableName)); + const fileFormat = firstTab.external ? firstTab.externalFileFormat : firstTab.fileFormat; + const getLocation = location => { return location.namespace ? location.namespace + location.path : location.path; }; - const fileFormat = firstTab.external ? firstTab.externalFileFormat : firstTab.fileFormat; + const keyConstraints = keyHelper.getTableKeyConstraints({ jsonSchema }); + + const entityLevelCompositeKeysReducer = (keys, data) => ({ + ...keys, + [data.name]: data.columns.map(column => { + return { name: column.name, isActivated: column.isActivated }; + }), + }); + const entityLevelCompositePrimaryKeys = keyConstraints .filter(({ keyType }) => keyType === 'PRIMARY KEY') - .reduce((keys, data) => { - return { - ...keys, - [data.name]: data.columns.map(column => { - return { name: column.name, isActivated: column.isActivated }; - }), - }; - }, {}); + .reduce(entityLevelCompositeKeysReducer, {}); const entityLevelCompositeUniqueKeys = keyConstraints .filter(({ keyType }) => keyType === 'UNIQUE') - .reduce((keys, data) => { - return { - ...keys, - [data.name]: data.columns.map(column => { - return { name: column.name, isActivated: column.isActivated }; - }), - }; - }, {}); + .reduce(entityLevelCompositeKeysReducer, {}); const compositePrimaryKeys = tableData.columnDefinitions .filter(column => column.compositePrimaryKey) @@ -842,7 +838,7 @@ module.exports = (baseProvider, options, app) => { return { ...tableData, fullName, - name: getName(firstTab.isCaseSensitive, tableData.name), + name: tableName, temporary: firstTab.temporary, transient: firstTab.transient, external: firstTab.external, @@ -857,11 +853,22 @@ module.exports = (baseProvider, options, app) => { initialize: firstTab.initialize, query: firstTab.query, externalVolume: firstTab.externalVolume, - catalog: firstTab.catalog, baseLocation: firstTab.baseLocation, maxDataExtensionTime: !isNaN(firstTab.MAX_DATA_EXTENSION_TIME_IN_DAYS) ? firstTab.MAX_DATA_EXTENSION_TIME_IN_DAYS : '', + catalog: firstTab.catalog, + catalogMgmt: firstTab.catalogMgmt, + catalogExternal: firstTab.catalogExternal, + catalogSync: firstTab.catalogSync, + storageSerializationPolicy: firstTab.storageSerializationPolicy, + changeTracking: firstTab.changeTracking, + defaultDdlCollation: firstTab.defaultDdlCollation, + catalogTableName: firstTab.catalogTableName, + catalogNamespace: firstTab.catalogNamespace, + metadataFilePath: firstTab.metadataFilePath, + replaceInvalidCharacters: firstTab.replaceInvalidCharacters, + autoRefresh: firstTab.autoRefresh, }, selectStatement: firstTab.selectStatement, isCaseSensitive: firstTab.isCaseSensitive, diff --git a/forward_engineering/helpers/tableHelper.js b/forward_engineering/helpers/tableHelper.js index f7f6f6ee..7d52279e 100644 --- a/forward_engineering/helpers/tableHelper.js +++ b/forward_engineering/helpers/tableHelper.js @@ -92,6 +92,15 @@ module.exports = app => { externalVolume, catalog, baseLocation, + catalogSync, + storageSerializationPolicy, + changeTracking, + defaultDdlCollation, + catalogTableName, + catalogNamespace, + metadataFilePath, + replaceInvalidCharacters, + autoRefresh, }, } = tableData; @@ -116,6 +125,17 @@ module.exports = app => { transient: preSpace(transient && 'TRANSIENT'), iceberg: preSpace(iceberg && 'ICEBERG'), dynamic: preSpace(dynamic && 'DYNAMIC'), + catalogSync: catalogSync ? `CATALOG_SYNC = '${catalogSync}'\n` : '', + storageSerializationPolicy: storageSerializationPolicy + ? `STORAGE_SERIALIZATION_POLICY = ${storageSerializationPolicy}\n` + : '', + changeTracking: changeTracking ? 'CHANGE_TRACKING = TRUE\n' : '', + defaultDdlCollation: defaultDdlCollation ? `DEFAULT_DDL_COLLATION = '${defaultDdlCollation}'\n` : '', + catalogTableName: catalogTableName ? `CATALOG_TABLE_NAME = '${catalogTableName}'\n` : '', + catalogNamespace: catalogNamespace ? `CATALOG_NAMESPACE = '${catalogNamespace}'\n` : '', + metadataFilePath: metadataFilePath ? `METADATA_FILE_PATH = '${metadataFilePath}'\n` : '', + replaceInvalidCharacters: replaceInvalidCharacters ? 'REPLACE_INVALID_CHARACTERS = TRUE\n' : '', + autoRefresh: autoRefresh ? 'AUTO_REFRESH = TRUE\n' : '', }; };