@sap/cds-compiler 2.15.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -1590
- package/bin/cdsc.js +36 -33
- package/doc/CHANGELOG_ARCHIVE.md +1592 -0
- package/doc/CHANGELOG_BETA.md +3 -4
- package/doc/CHANGELOG_DEPRECATED.md +35 -1
- package/doc/{DeprecatedOptions.md → DeprecatedOptions_v2.md} +3 -1
- package/doc/Versioning.md +20 -1
- package/lib/api/.eslintrc.json +2 -2
- package/lib/api/main.js +220 -103
- package/lib/api/options.js +15 -85
- package/lib/api/validate.js +6 -10
- package/lib/base/keywords.js +216 -109
- package/lib/base/message-registry.js +60 -20
- package/lib/base/messages.js +65 -24
- package/lib/base/model.js +44 -2
- package/lib/checks/actionsFunctions.js +7 -5
- package/lib/checks/annotationsOData.js +1 -1
- package/lib/checks/cdsPersistence.js +1 -0
- package/lib/checks/elements.js +6 -6
- package/lib/checks/invalidTarget.js +1 -1
- package/lib/checks/nonexpandableStructured.js +1 -1
- package/lib/checks/queryNoDbArtifacts.js +2 -1
- package/lib/checks/selectItems.js +5 -1
- package/lib/checks/types.js +4 -2
- package/lib/checks/utils.js +2 -2
- package/lib/checks/validator.js +2 -1
- package/lib/compiler/assert-consistency.js +15 -10
- package/lib/compiler/builtins.js +87 -9
- package/lib/compiler/define.js +2 -2
- package/lib/compiler/extend.js +59 -11
- package/lib/compiler/finalize-parse-cdl.js +20 -9
- package/lib/compiler/index.js +25 -11
- package/lib/compiler/moduleLayers.js +7 -0
- package/lib/compiler/populate.js +13 -13
- package/lib/compiler/propagator.js +3 -3
- package/lib/compiler/resolve.js +193 -218
- package/lib/compiler/shared.js +47 -76
- package/lib/compiler/tweak-assocs.js +9 -10
- package/lib/compiler/utils.js +5 -0
- package/lib/edm/csn2edm.js +18 -21
- package/lib/edm/edmPreprocessor.js +25 -30
- package/lib/edm/edmUtils.js +10 -24
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +8 -30
- package/lib/gen/language.tokens +105 -114
- package/lib/gen/languageLexer.interp +1 -34
- package/lib/gen/languageLexer.js +889 -1007
- package/lib/gen/languageLexer.tokens +95 -106
- package/lib/gen/languageParser.js +20632 -22313
- package/lib/json/from-csn.js +56 -49
- package/lib/json/to-csn.js +10 -8
- package/lib/language/antlrParser.js +2 -2
- package/lib/language/docCommentParser.js +61 -38
- package/lib/language/errorStrategy.js +52 -40
- package/lib/language/genericAntlrParser.js +303 -229
- package/lib/language/language.g4 +573 -629
- package/lib/language/multiLineStringParser.js +14 -42
- package/lib/language/textUtils.js +44 -0
- package/lib/main.d.ts +27 -42
- package/lib/main.js +104 -81
- package/lib/model/csnRefs.js +1 -1
- package/lib/model/csnUtils.js +170 -283
- package/lib/model/revealInternalProperties.js +28 -8
- package/lib/model/sortViews.js +32 -31
- package/lib/optionProcessor.js +12 -21
- package/lib/render/.eslintrc.json +1 -1
- package/lib/render/DuplicateChecker.js +4 -7
- package/lib/render/manageConstraints.js +70 -2
- package/lib/render/toCdl.js +334 -339
- package/lib/render/toHdbcds.js +19 -15
- package/lib/render/toRename.js +44 -22
- package/lib/render/toSql.js +53 -51
- package/lib/render/utils/common.js +15 -1
- package/lib/render/utils/sql.js +20 -19
- package/lib/sql-identifier.js +6 -0
- package/lib/transform/db/.eslintrc.json +3 -2
- package/lib/transform/db/cdsPersistence.js +5 -15
- package/lib/transform/db/constraints.js +1 -1
- package/lib/transform/db/expansion.js +7 -6
- package/lib/transform/db/flattening.js +18 -19
- package/lib/transform/db/views.js +3 -3
- package/lib/transform/draft/.eslintrc.json +2 -2
- package/lib/transform/draft/db.js +6 -6
- package/lib/transform/draft/odata.js +6 -7
- package/lib/transform/forHanaNew.js +19 -22
- package/lib/transform/forOdataNew.js +10 -12
- package/lib/transform/localized.js +22 -16
- package/lib/transform/odata/toFinalBaseType.js +10 -10
- package/lib/transform/odata/typesExposure.js +3 -3
- package/lib/transform/odata/utils.js +1 -38
- package/lib/transform/transformUtilsNew.js +63 -77
- package/lib/transform/translateAssocsToJoins.js +2 -2
- package/lib/transform/universalCsn/.eslintrc.json +2 -2
- package/lib/transform/universalCsn/coreComputed.js +11 -6
- package/lib/transform/universalCsn/universalCsnEnricher.js +33 -5
- package/lib/utils/file.js +3 -3
- package/lib/utils/timetrace.js +20 -21
- package/package.json +35 -4
- package/doc/ApiMigration.md +0 -237
- package/doc/CommandLineMigration.md +0 -58
- package/doc/ErrorMessages.md +0 -175
- package/doc/FioriAnnotations.md +0 -94
- package/doc/ODataTransformation.md +0 -273
- package/lib/backends.js +0 -529
- package/lib/fix_antlr4-8_warning.js +0 -56
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
const msg = require('../base/messages');
|
|
15
15
|
|
|
16
16
|
const $inferred = Symbol.for('cds.$inferred');
|
|
17
|
+
const $location = Symbol.for('cds.$location');
|
|
17
18
|
|
|
18
19
|
class NOT_A_DICTIONARY {} // used for consol.log display
|
|
19
20
|
|
|
@@ -96,6 +97,7 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
96
97
|
_annotate: reveal,
|
|
97
98
|
_deps: dependencyInfo,
|
|
98
99
|
_status: primOrString, // is a string anyway
|
|
100
|
+
$annotations: as => as.map( $annotation ),
|
|
99
101
|
$messageFunctions: () => '‹some functions›',
|
|
100
102
|
}
|
|
101
103
|
unique_id = 1;
|
|
@@ -149,7 +151,7 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
149
151
|
|
|
150
152
|
function shortenName( node, parent ) {
|
|
151
153
|
const name = reveal( node, parent );
|
|
152
|
-
if (name && typeof name === 'object' && name.absolute) {
|
|
154
|
+
if (name && typeof name === 'object' && name.absolute && node.kind) {
|
|
153
155
|
const text = artifactIdentifier( parent );
|
|
154
156
|
delete name.absolute;
|
|
155
157
|
delete name.select;
|
|
@@ -178,11 +180,20 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
178
180
|
return r;
|
|
179
181
|
}
|
|
180
182
|
|
|
183
|
+
function $annotation( anno ) { // property for cds-lsp
|
|
184
|
+
const { name, $flatten } = anno.value || anno;
|
|
185
|
+
const value = ($flatten)
|
|
186
|
+
? { name: reveal( name ), $flatten: $flatten.map( $annotation ) }
|
|
187
|
+
: `@${name?.absolute}`;
|
|
188
|
+
return { value, location: locationString( anno.location || anno.name.location ) };
|
|
189
|
+
}
|
|
190
|
+
|
|
181
191
|
function columns( nodes, query ) {
|
|
182
192
|
// If we will have specified elements, we need another test to see columns in --parse-cdl
|
|
183
|
-
return nodes &&
|
|
184
|
-
|
|
185
|
-
|
|
193
|
+
return nodes && array( nodes,
|
|
194
|
+
c => (c._parent && c._parent.elements)
|
|
195
|
+
? artifactIdentifier( c, query )
|
|
196
|
+
: reveal( c, nodes ) );
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
function elements( dict, parent ) {
|
|
@@ -215,7 +226,7 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
215
226
|
if (!node || typeof node !== 'object')
|
|
216
227
|
return primOrString( node );
|
|
217
228
|
if (Array.isArray(node)) // with args
|
|
218
|
-
return
|
|
229
|
+
return array( node, reveal );
|
|
219
230
|
// Make unexpected prototype visible with node-10+:
|
|
220
231
|
const r = Object.create( Object.getPrototypeOf(node)
|
|
221
232
|
? NOT_A_DICTIONARY.prototype
|
|
@@ -225,6 +236,8 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
225
236
|
}
|
|
226
237
|
if (node[$inferred] && !node['[$inferred]'])
|
|
227
238
|
r['[$inferred]'] = node[$inferred];
|
|
239
|
+
if (node[$location] && !node['[$location]'])
|
|
240
|
+
r['[$location]'] = locationString( node[$location] );
|
|
228
241
|
return r;
|
|
229
242
|
}
|
|
230
243
|
|
|
@@ -239,7 +252,7 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
239
252
|
if (node == null || typeof node !== 'object' )
|
|
240
253
|
return primOrString( node );
|
|
241
254
|
if (Array.isArray(node))
|
|
242
|
-
return
|
|
255
|
+
return array( node, revealNonEnum );
|
|
243
256
|
|
|
244
257
|
if (Object.getPrototypeOf( node ))
|
|
245
258
|
return artifactIdentifier( node, parent );
|
|
@@ -250,7 +263,7 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
250
263
|
if (node == null || typeof node !== 'object' )
|
|
251
264
|
return node
|
|
252
265
|
if (Array.isArray(node))
|
|
253
|
-
return
|
|
266
|
+
return array( node, n => reveal( n, node, name ) );
|
|
254
267
|
|
|
255
268
|
const asLinkTest = kindsRepresentedAsLinks[ node.kind ];
|
|
256
269
|
if (asLinkTest && asLinkTest( node, parent, name ))
|
|
@@ -280,6 +293,13 @@ function revealInternalProperties( model, nameOrPath ) {
|
|
|
280
293
|
}
|
|
281
294
|
}
|
|
282
295
|
|
|
296
|
+
function array( node, fn ) {
|
|
297
|
+
const r = node.map( n => fn( n, node ) );
|
|
298
|
+
if (node[$location])
|
|
299
|
+
r.push( { $location: locationString( node[$location] ) } );
|
|
300
|
+
return r;
|
|
301
|
+
}
|
|
302
|
+
|
|
283
303
|
function artifactIdentifier( node, parent ) {
|
|
284
304
|
if (Array.isArray(node))
|
|
285
305
|
return node.map( a => artifactIdentifier( a, node ) );
|
|
@@ -335,7 +355,7 @@ function primOrString( node ) {
|
|
|
335
355
|
if (node == null || typeof node !== 'object')
|
|
336
356
|
return node
|
|
337
357
|
if (Array.isArray(node))
|
|
338
|
-
return
|
|
358
|
+
return array( node, primOrString );
|
|
339
359
|
if (Object.getPrototypeOf( node ))
|
|
340
360
|
return '' + node;
|
|
341
361
|
else
|
package/lib/model/sortViews.js
CHANGED
|
@@ -21,7 +21,7 @@ const { ModelError } = require("../base/error");
|
|
|
21
21
|
*/
|
|
22
22
|
function sortTopologically(csn, _dependents, _dependencies){
|
|
23
23
|
const layers = [];
|
|
24
|
-
let { zero, nonZero } =
|
|
24
|
+
let { zero, nonZero } = _calculateDepth(Object.entries(csn.definitions), _dependents, _dependencies);
|
|
25
25
|
while (zero.length !== 0){
|
|
26
26
|
const currentLayer = [];
|
|
27
27
|
zero.forEach(([artifactName, artifact]) => {
|
|
@@ -34,46 +34,46 @@ function sortTopologically(csn, _dependents, _dependencies){
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
layers.push(currentLayer);
|
|
37
|
-
({zero, nonZero} =
|
|
37
|
+
({zero, nonZero} = _findWithXPointers(nonZero, 0, _dependents, _dependencies));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
return { layers, leftover: nonZero };
|
|
41
|
+
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
function _calculateDepth(definitionsArray, _dependents, _dependencies) {
|
|
44
|
+
const zero = [];
|
|
45
|
+
const nonZero = [];
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return {
|
|
56
|
-
zero,
|
|
57
|
-
nonZero
|
|
47
|
+
definitionsArray.forEach(([artifactName, artifact]) => {
|
|
48
|
+
if(artifact[_dependencies]) {
|
|
49
|
+
artifact.$pointers = artifact[_dependencies].size;
|
|
50
|
+
nonZero.push([artifactName, artifact]);
|
|
51
|
+
} else {
|
|
52
|
+
artifact.$pointers = 0;
|
|
53
|
+
zero.push([artifactName, artifact]);
|
|
58
54
|
}
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
zero,
|
|
58
|
+
nonZero
|
|
59
59
|
}
|
|
60
|
+
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
definitionsArray.forEach(([artifactName, artifact]) => {
|
|
66
|
-
if(artifact.$pointers !== undefined && artifact.$pointers === x) {
|
|
67
|
-
zero.push([artifactName, artifact]);
|
|
68
|
-
} else {
|
|
69
|
-
nonZero.push([artifactName, artifact]);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
62
|
+
function _findWithXPointers(definitionsArray, x, _dependents, _dependencies){
|
|
63
|
+
const zero = [];
|
|
64
|
+
const nonZero = [];
|
|
72
65
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
definitionsArray.forEach(([artifactName, artifact]) => {
|
|
67
|
+
if(artifact.$pointers !== undefined && artifact.$pointers === x) {
|
|
68
|
+
zero.push([artifactName, artifact]);
|
|
69
|
+
} else {
|
|
70
|
+
nonZero.push([artifactName, artifact]);
|
|
76
71
|
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
zero,
|
|
76
|
+
nonZero
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -83,6 +83,7 @@ function sortTopologically(csn, _dependents, _dependencies){
|
|
|
83
83
|
* be run beforehand to resolve association usages.
|
|
84
84
|
*
|
|
85
85
|
* @param {object} sql Map of <object name>: "CREATE STATEMENT"
|
|
86
|
+
* @param {CSN.Model} csn
|
|
86
87
|
*
|
|
87
88
|
* @returns {{name: string, sql: string}[]} Sorted array of artifact name / "CREATE STATEMENTS" pairs
|
|
88
89
|
*
|
package/lib/optionProcessor.js
CHANGED
|
@@ -34,7 +34,6 @@ optionProcessor
|
|
|
34
34
|
.option(' --beta-mode')
|
|
35
35
|
.option(' --beta <list>')
|
|
36
36
|
.option(' --deprecated <list>')
|
|
37
|
-
.option(' --hana-flavor')
|
|
38
37
|
.option(' --direct-backend')
|
|
39
38
|
.option(' --parse-only')
|
|
40
39
|
.option(' --fallback-parser <type>', ['cdl', 'csn', 'csn!'])
|
|
@@ -107,21 +106,12 @@ optionProcessor
|
|
|
107
106
|
--beta-mode Enable all unsupported, incomplete (beta) features
|
|
108
107
|
--beta <list> Comma separated list of unsupported, incomplete (beta) features to use.
|
|
109
108
|
Valid values are:
|
|
110
|
-
addTextsLanguageAssoc
|
|
111
109
|
hanaAssocRealCardinality
|
|
112
110
|
mapAssocToJoinCardinality
|
|
113
111
|
ignoreAssocPublishingInUnion
|
|
114
112
|
--deprecated <list> Comma separated list of deprecated options.
|
|
115
113
|
Valid values are:
|
|
116
|
-
|
|
117
|
-
v1KeysForTemporal
|
|
118
|
-
parensAsStrings
|
|
119
|
-
projectionAsQuery
|
|
120
|
-
renderVirtualElements
|
|
121
|
-
unmanagedUpInComponent
|
|
122
|
-
createLocalizedViews
|
|
123
|
-
redirectInSubQueries
|
|
124
|
-
--hana-flavor Compile with backward compatibility for HANA CDS (incomplete)
|
|
114
|
+
eagerPersistenceForGeneratedEntities
|
|
125
115
|
--parse-only Stop compilation after parsing and write result to <stdout>
|
|
126
116
|
--fallback-parser <type> If the language cannot be deduced by the file's extensions, use this
|
|
127
117
|
parser as a fallback. Valid values are:
|
|
@@ -207,7 +197,7 @@ optionProcessor.command('H, toHana')
|
|
|
207
197
|
|
|
208
198
|
optionProcessor.command('O, toOdata')
|
|
209
199
|
.option('-h, --help')
|
|
210
|
-
.option('-v, --version <version>', ['v2', 'v4', 'v4x'])
|
|
200
|
+
.option('-v, --odata-version <version>', ['v2', 'v4', 'v4x'])
|
|
211
201
|
.option('-x, --xml')
|
|
212
202
|
.option('-j, --json')
|
|
213
203
|
.option(' --odata-containment')
|
|
@@ -226,10 +216,10 @@ optionProcessor.command('O, toOdata')
|
|
|
226
216
|
|
|
227
217
|
Options
|
|
228
218
|
-h, --help Show this help text
|
|
229
|
-
-v, --version <version> ODATA version
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
219
|
+
-v, --odata-version <version> ODATA version
|
|
220
|
+
v2: ODATA V2
|
|
221
|
+
v4: (default) ODATA V4
|
|
222
|
+
v4x: { version: 'v4', odataContainment:true, format:'structured' }
|
|
233
223
|
-x, --xml (default) Generate XML output (separate or combined)
|
|
234
224
|
-j, --json Generate JSON output as "<svc>.json" (not available for v2)
|
|
235
225
|
-c, --csn Generate "odata_csn.json" with ODATA-preprocessed model
|
|
@@ -250,7 +240,7 @@ optionProcessor.command('O, toOdata')
|
|
|
250
240
|
hdbcds : Names as HANA CDS would generate them from the same CDS
|
|
251
241
|
source (like "quoted", but using element names with dots)
|
|
252
242
|
-s, --service-names <list> List of comma-separated service names to be rendered
|
|
253
|
-
(default) empty, all services are rendered
|
|
243
|
+
(default) empty, all services are rendered
|
|
254
244
|
`);
|
|
255
245
|
|
|
256
246
|
optionProcessor.command('C, toCdl')
|
|
@@ -269,7 +259,7 @@ optionProcessor.command('Q, toSql')
|
|
|
269
259
|
.option('-n, --names <style>', ['plain', 'quoted', 'hdbcds'])
|
|
270
260
|
.option(' --render-virtual')
|
|
271
261
|
.option(' --joinfk')
|
|
272
|
-
.option('-d, --dialect <dialect>', ['hana', 'sqlite', 'plain'])
|
|
262
|
+
.option('-d, --dialect <dialect>', ['hana', 'sqlite', 'plain', 'postgres'])
|
|
273
263
|
.option('-u, --user <user>')
|
|
274
264
|
.option('-l, --locale <locale>')
|
|
275
265
|
.option('-s, --src <style>', ['sql', 'hdi'])
|
|
@@ -300,9 +290,10 @@ optionProcessor.command('Q, toSql')
|
|
|
300
290
|
--render-virtual Render virtual elements in views and draft tables
|
|
301
291
|
--joinfk Create JOINs for foreign key accesses
|
|
302
292
|
-d, --dialect <dialect> SQL dialect to be generated:
|
|
303
|
-
plain
|
|
304
|
-
hana
|
|
305
|
-
sqlite
|
|
293
|
+
plain : (default) Common SQL - no assumptions about DB restrictions
|
|
294
|
+
hana : SQL with HANA specific language features
|
|
295
|
+
sqlite : Common SQL for sqlite
|
|
296
|
+
postgres : Common SQL for postgres - beta-feature
|
|
306
297
|
-u, --user <user> Value for the "$user" variable
|
|
307
298
|
-l, --locale <locale> Value for the "$user.locale" variable in "sqlite"/"plain" dialect
|
|
308
299
|
-s, --src <style> Generate SQL source files as <artifact>.<suffix>
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Usage: Create an instance to process artifacts which should be checked for collision.
|
|
3
3
|
* First call addArtifact to specify the current artifact,
|
|
4
4
|
* then call addElement to register the elements of the current artifact.
|
|
5
|
-
* Finally call the "done" function to check for duplicates.
|
|
6
|
-
* In addition the internal structures will be reinitialized to enable reuse of the instance.
|
|
5
|
+
* Finally, call the "done" function to check for duplicates.
|
|
6
|
+
* In addition, the internal structures will be reinitialized to enable reuse of the instance.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
+
const { forEach } = require('../utils/objectUtils');
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* database name - uppercase if not quoted
|
|
13
15
|
*
|
|
@@ -121,9 +123,4 @@ class DuplicateChecker {
|
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
function forEach(obj, callback) {
|
|
125
|
-
for (const key in obj)
|
|
126
|
-
callback(key, obj[key]);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
126
|
module.exports = DuplicateChecker;
|
|
@@ -6,11 +6,78 @@ const {
|
|
|
6
6
|
getResultingName,
|
|
7
7
|
} = require('../model/csnUtils');
|
|
8
8
|
const { forEach } = require('../utils/objectUtils');
|
|
9
|
+
const { makeMessageFunction } = require('../base/messages');
|
|
10
|
+
const { optionProcessor } = require('../optionProcessor');
|
|
11
|
+
const { transformForHanaWithCsn } = require('../transform/forHanaNew');
|
|
9
12
|
|
|
10
13
|
const {
|
|
11
14
|
renderReferentialConstraint, getIdentifierUtils,
|
|
12
15
|
} = require('./utils/sql');
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Used only by `cdsc manageConstraints`.
|
|
19
|
+
* Not part of our API, yet.
|
|
20
|
+
*
|
|
21
|
+
* @param {CSN.Model} csn
|
|
22
|
+
* @param {CSN.Options} options
|
|
23
|
+
*/
|
|
24
|
+
function alterConstraintsWithCsn(csn, options) {
|
|
25
|
+
const { error } = makeMessageFunction(csn, options, 'manageConstraints');
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
drop, alter, names, src, violations,
|
|
29
|
+
} = options.manageConstraints || {};
|
|
30
|
+
|
|
31
|
+
if (drop && alter)
|
|
32
|
+
error(null, null, 'Option “--drop” can\'t be combined with “--alter”');
|
|
33
|
+
|
|
34
|
+
options.sqlDialect = 'hana';
|
|
35
|
+
options.sqlMapping = names || 'plain';
|
|
36
|
+
|
|
37
|
+
// Of course we want the database constraints
|
|
38
|
+
options.assertIntegrityType = 'DB';
|
|
39
|
+
|
|
40
|
+
const transformedOptions = _transformSqlOptions(csn, options);
|
|
41
|
+
const forSqlCsn = transformForHanaWithCsn(csn, transformedOptions, 'to.sql');
|
|
42
|
+
|
|
43
|
+
if (violations && src && src !== 'sql')
|
|
44
|
+
error(null, null, `Option “--violations“ can't be combined with source style “${src}“`);
|
|
45
|
+
|
|
46
|
+
let intermediateResult;
|
|
47
|
+
if (violations)
|
|
48
|
+
intermediateResult = listReferentialIntegrityViolations(forSqlCsn, transformedOptions);
|
|
49
|
+
else
|
|
50
|
+
intermediateResult = manageConstraints(forSqlCsn, transformedOptions);
|
|
51
|
+
|
|
52
|
+
return intermediateResult;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _transformSqlOptions(model, options) {
|
|
56
|
+
// Merge options with defaults.
|
|
57
|
+
options = Object.assign({ sqlMapping: 'plain', sqlDialect: 'plain' }, options);
|
|
58
|
+
options.toSql = true;
|
|
59
|
+
|
|
60
|
+
if (!options.src && !options.csn)
|
|
61
|
+
options.src = 'sql';
|
|
62
|
+
|
|
63
|
+
const { warning, error } = makeMessageFunction(model, options, 'to.sql');
|
|
64
|
+
|
|
65
|
+
optionProcessor.verifyOptions(options, 'toSql', true)
|
|
66
|
+
.forEach(complaint => warning(null, null, `${complaint}`));
|
|
67
|
+
|
|
68
|
+
if (options.sqlDialect !== 'hana') {
|
|
69
|
+
// CDXCORE-465, 'quoted' and 'hdbcds' are to be used in combination with dialect 'hana' only
|
|
70
|
+
if (options.sqlMapping === 'quoted' || options.sqlMapping === 'hdbcds')
|
|
71
|
+
error(null, null, `Option "{ sqlDialect: '${options.sqlDialect}' }" can't be combined with "{ sqlMapping: '${options.sqlMapping}' }"`);
|
|
72
|
+
|
|
73
|
+
// No non-HANA SQL for HDI
|
|
74
|
+
if (options.src === 'hdi')
|
|
75
|
+
error(null, null, `Option "{ sqlDialect: '${options.sqlDialect}' }" can't be used for HDI"`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return options;
|
|
79
|
+
}
|
|
80
|
+
|
|
14
81
|
/**
|
|
15
82
|
* This render middleware can be used to generate SQL DDL ALTER TABLE <table> ALTER / ADD / DROP CONSTRAINT <constraint> statements for a given CDL model.
|
|
16
83
|
* Moreover, it can be used to generate .hdbconstraint artifacts.
|
|
@@ -38,7 +105,7 @@ function manageConstraints(csn, options) {
|
|
|
38
105
|
return;
|
|
39
106
|
}
|
|
40
107
|
let alterTableStatement = '';
|
|
41
|
-
alterTableStatement += `${indent}ALTER TABLE ${quoteSqlId(getResultingName(csn, options.
|
|
108
|
+
alterTableStatement += `${indent}ALTER TABLE ${quoteSqlId(getResultingName(csn, options.sqlMapping, constraint.dependentTable))}`;
|
|
42
109
|
if (renderAlterConstraintStatement)
|
|
43
110
|
alterTableStatement += `\n${indent}ALTER ${renderedConstraint};`;
|
|
44
111
|
else if (drop)
|
|
@@ -172,7 +239,7 @@ function listReferentialIntegrityViolations(csn, options) {
|
|
|
172
239
|
}
|
|
173
240
|
|
|
174
241
|
function quoteAndGetResultingName(id) {
|
|
175
|
-
return quoteSqlId(getResultingName(csn, options.
|
|
242
|
+
return quoteSqlId(getResultingName(csn, options.sqlMapping, id));
|
|
176
243
|
}
|
|
177
244
|
|
|
178
245
|
return resultArtifacts;
|
|
@@ -192,6 +259,7 @@ function getListOfAllConstraints(csn) {
|
|
|
192
259
|
}
|
|
193
260
|
|
|
194
261
|
module.exports = {
|
|
262
|
+
alterConstraintsWithCsn,
|
|
195
263
|
manageConstraints,
|
|
196
264
|
listReferentialIntegrityViolations,
|
|
197
265
|
};
|