@@ -4,43 +4,36 @@ const applyToInstanceHelper = require('./applyToInstanceHelper');
44
55module . exports = {
66 generateScript ( data , logger , callback , app ) {
7- callback ( new Error ( 'Forward-Engineering of delta model on entity level is not supported' ) ) ;
7+ const {
8+ getAlterContainersScripts,
9+ getAlterCollectionsScripts,
10+ getAlterViewScripts,
11+ getAlterModelDefinitionsScripts,
12+ } = require ( './helpers/alterScriptFromDeltaHelper' ) ;
13+
14+ const collection = JSON . parse ( data . jsonSchema ) ;
15+ if ( ! collection ) {
16+ throw new Error (
17+ '"comparisonModelCollection" is not found. Alter script can be generated only from Delta model' ,
18+ ) ;
19+ }
20+
21+ const dbVersion = data . modelData [ 0 ] ?. dbVersion ;
22+ const containersScripts = getAlterContainersScripts ( collection ) ;
23+ const collectionsScripts = getAlterCollectionsScripts ( collection , app , dbVersion ) ;
24+ const viewScripts = getAlterViewScripts ( collection , app ) ;
25+ const modelDefinitionsScripts = getAlterModelDefinitionsScripts ( collection , app ) ;
26+
27+ callback (
28+ null ,
29+ [ ...containersScripts , ...collectionsScripts , ...viewScripts , ...modelDefinitionsScripts ] . join ( '\n\n' ) ,
30+ ) ;
831 } ,
932 generateViewScript ( data , logger , callback , app ) {
1033 callback ( new Error ( 'Forward-Engineering of delta model on view level is not supported' ) ) ;
1134 } ,
1235 generateContainerScript ( data , logger , callback , app ) {
13- try {
14- const {
15- getComparisonModelCollection,
16- getAlterContainersScripts,
17- getAlterCollectionsScripts,
18- getAlterViewScripts,
19- getAlterModelDefinitionsScripts,
20- } = require ( './helpers/alterScriptFromDeltaHelper' ) ;
21-
22- const collection = getComparisonModelCollection ( data . collections ) ;
23- if ( ! collection ) {
24- throw new Error (
25- '"comparisonModelCollection" is not found. Alter script can be generated only from Delta model' ,
26- ) ;
27- }
28-
29- const dbVersion = data . modelData [ 0 ] ?. dbVersion ;
30- const containersScripts = getAlterContainersScripts ( collection ) ;
31- const collectionsScripts = getAlterCollectionsScripts ( collection , app , dbVersion ) ;
32- const viewScripts = getAlterViewScripts ( collection , app ) ;
33- const modelDefinitionsScripts = getAlterModelDefinitionsScripts ( collection , app ) ;
34-
35- callback (
36- null ,
37- [ ...containersScripts , ...collectionsScripts , ...viewScripts , ...modelDefinitionsScripts ] . join ( '\n\n' ) ,
38- ) ;
39- } catch ( e ) {
40- logger . log ( 'error' , { message : e . message , stack : e . stack } , 'Cassandra Forward-Engineering Error' ) ;
41-
42- callback ( { message : e . message , stack : e . stack } ) ;
43- }
36+ callback ( new Error ( 'Forward-Engineering of delta model on container level is not supported' ) ) ;
4437 } ,
4538 getDatabases ( connectionInfo , logger , callback , app ) {
4639 logger . progress ( { message : 'Find all databases' } ) ;
0 commit comments