diff --git a/forward_engineering/api.js b/forward_engineering/api.js index 0210e88..779c8a6 100644 --- a/forward_engineering/api.js +++ b/forward_engineering/api.js @@ -4,43 +4,36 @@ const applyToInstanceHelper = require('./applyToInstanceHelper'); module.exports = { generateScript(data, logger, callback, app) { - callback(new Error('Forward-Engineering of delta model on entity level is not supported')); + const { + getAlterContainersScripts, + getAlterCollectionsScripts, + getAlterViewScripts, + getAlterModelDefinitionsScripts, + } = require('./helpers/alterScriptFromDeltaHelper'); + + const collection = JSON.parse(data.jsonSchema); + if (!collection) { + throw new Error( + '"comparisonModelCollection" is not found. Alter script can be generated only from Delta model', + ); + } + + const dbVersion = data.modelData[0]?.dbVersion; + const containersScripts = getAlterContainersScripts(collection); + const collectionsScripts = getAlterCollectionsScripts(collection, app, dbVersion); + const viewScripts = getAlterViewScripts(collection, app); + const modelDefinitionsScripts = getAlterModelDefinitionsScripts(collection, app); + + callback( + null, + [...containersScripts, ...collectionsScripts, ...viewScripts, ...modelDefinitionsScripts].join('\n\n'), + ); }, generateViewScript(data, logger, callback, app) { callback(new Error('Forward-Engineering of delta model on view level is not supported')); }, generateContainerScript(data, logger, callback, app) { - try { - const { - getComparisonModelCollection, - getAlterContainersScripts, - getAlterCollectionsScripts, - getAlterViewScripts, - getAlterModelDefinitionsScripts, - } = require('./helpers/alterScriptFromDeltaHelper'); - - const collection = getComparisonModelCollection(data.collections); - if (!collection) { - throw new Error( - '"comparisonModelCollection" is not found. Alter script can be generated only from Delta model', - ); - } - - const dbVersion = data.modelData[0]?.dbVersion; - const containersScripts = getAlterContainersScripts(collection); - const collectionsScripts = getAlterCollectionsScripts(collection, app, dbVersion); - const viewScripts = getAlterViewScripts(collection, app); - const modelDefinitionsScripts = getAlterModelDefinitionsScripts(collection, app); - - callback( - null, - [...containersScripts, ...collectionsScripts, ...viewScripts, ...modelDefinitionsScripts].join('\n\n'), - ); - } catch (e) { - logger.log('error', { message: e.message, stack: e.stack }, 'Cassandra Forward-Engineering Error'); - - callback({ message: e.message, stack: e.stack }); - } + callback(new Error('Forward-Engineering of delta model on container level is not supported')); }, getDatabases(connectionInfo, logger, callback, app) { logger.progress({ message: 'Find all databases' }); diff --git a/forward_engineering/config.json b/forward_engineering/config.json index 3211eee..fb157b3 100644 --- a/forward_engineering/config.json +++ b/forward_engineering/config.json @@ -1,30 +1,14 @@ { - "options": [ + "type": "ddl", + "ddlType": "plugin", + "mode": "pgsql", + "fileExtensions": [ { - "name": "Create Script", - "keyword": "create", - "type": "ddl", - "ddlType": "plugin", - "mode": "pgsql", - "fileExtensions": [ - { - "value": "sql", - "label": "SQL" - } - ] - }, - { - "name": "Alter Script from Delta model", - "keyword": "alterFromDelta", - "cliOnly": true, - "fileExtensions": [ - { - "value": "sql", - "label": "SQL" - } - ] + "value": "sql", + "label": "SQL" } ], + "hasUpdateScript": false, "namePrefix": "PostgreSQL", "level": { "container": true, @@ -39,5 +23,9 @@ "feLevelSelector": { "container": true, "model": true + }, + "compMode": { + "entity": true, + "container": false } } \ No newline at end of file diff --git a/localization/en.json b/localization/en.json index 9212313..4b8197a 100644 --- a/localization/en.json +++ b/localization/en.json @@ -8,6 +8,7 @@ "MAIN_MENU___INSERT_FIELD": "Insert Column", "MAIN_MENU___APPEND_FIELD": "Append Column", "MAIN_MENU___REVERSE_DB_COLLECTIONS": "PostgreSQL schemas...", + "MAIN_MENU___FORWARD_CHANGE_COLLECTIONS": "PostgreSQL Alter Script", "TOOLBAR___ADD_BUCKET": "Add schema", "TOOLBAR___ADD_COLLECTION": "Add table", "TOOLBAR___ADD_VIEW": "Add View",