@sap/cds-compiler 4.9.2 → 4.9.4
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 +8 -0
- package/lib/api/main.js +1 -1
- package/lib/api/options.js +2 -0
- package/lib/transform/db/constraints.js +23 -25
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
Note: `beta` fixes, changes and features are usually not listed in this ChangeLog but [here](doc/CHANGELOG_BETA.md).
|
|
8
8
|
The compiler behavior concerning `beta` features can change at any time without notice.
|
|
9
9
|
|
|
10
|
+
## Version 4.9.4 - 2024-05-21
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- to.sql:
|
|
15
|
+
+ always include `tenant` column in foreign key references.
|
|
16
|
+
+ reject `tenantDiscriminator` option only if sql dialect is `hana` and if `withHanaAssociations` option is set.
|
|
17
|
+
|
|
10
18
|
## Version 4.9.2 - 2024-05-13
|
|
11
19
|
|
|
12
20
|
### Fixed
|
package/lib/api/main.js
CHANGED
|
@@ -1293,7 +1293,7 @@ function lazyload( moduleName ) {
|
|
|
1293
1293
|
* @param {object} messageFunctions Message functions
|
|
1294
1294
|
*/
|
|
1295
1295
|
function handleTenantDiscriminator( options, internalOptions, messageFunctions ) {
|
|
1296
|
-
if (options.tenantDiscriminator && options.withHanaAssociations) {
|
|
1296
|
+
if (options.tenantDiscriminator && options.withHanaAssociations && internalOptions.sqlDialect === 'hana') {
|
|
1297
1297
|
messageFunctions.error('api-invalid-combination', null, {
|
|
1298
1298
|
option: 'tenantDiscriminator',
|
|
1299
1299
|
prop: 'withHanaAssociations',
|
package/lib/api/options.js
CHANGED
|
@@ -172,6 +172,7 @@ module.exports = {
|
|
|
172
172
|
},
|
|
173
173
|
hdi: (options) => {
|
|
174
174
|
const hardOptions = { src: 'hdi', toSql: true, forHana: true };
|
|
175
|
+
// TODO: sqlDialect should be a hard option!
|
|
175
176
|
const defaultOptions = {
|
|
176
177
|
sqlMapping: 'plain', sqlDialect: 'hana', generatedByComment: false, withHanaAssociations: true,
|
|
177
178
|
};
|
|
@@ -179,6 +180,7 @@ module.exports = {
|
|
|
179
180
|
},
|
|
180
181
|
hdbcds: (options) => {
|
|
181
182
|
const hardOptions = { forHana: true };
|
|
183
|
+
// TODO: sqlDialect should be a hard option!
|
|
182
184
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
183
185
|
return translateOptions(options, defaultOptions, hardOptions, { sqlDialect: generateStringValidator([ 'hana' ]) }, undefined, 'to.hdbcds');
|
|
184
186
|
},
|
|
@@ -203,28 +203,28 @@ function createReferentialConstraints( csn, options ) {
|
|
|
203
203
|
// in contrast to foreign keys which stem from managed associations,
|
|
204
204
|
// a tenant foreign key column may have multiple parent keys as partners
|
|
205
205
|
const tenantForeignKey = isTenant && dependentKeyValuePair[0] === 'tenant';
|
|
206
|
-
if ($foreignKeyConstraint && (!tenantForeignKey || $foreignKeyConstraint.upLinkFor))
|
|
206
|
+
if ($foreignKeyConstraint && (!tenantForeignKey || $foreignKeyConstraint.upLinkFor))
|
|
207
207
|
return;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
|
|
209
|
+
const parentKeyValuePair = parentKeys.pop();
|
|
210
|
+
const parentKeyName = parentKeyValuePair[0];
|
|
211
|
+
|
|
212
|
+
const constraint = {
|
|
213
|
+
parentKey: parentKeyName,
|
|
214
|
+
parentTable,
|
|
215
|
+
upLinkFor,
|
|
216
|
+
sourceAssociation,
|
|
217
|
+
onDelete: upLinkFor ? 'CASCADE' : 'RESTRICT',
|
|
218
|
+
validated,
|
|
219
|
+
enforced,
|
|
220
|
+
};
|
|
221
|
+
if (tenantForeignKey) {
|
|
222
|
+
const dontOverwriteUp = dependentKey.$foreignKeyConstraint && dependentKey.$foreignKeyConstraint.some(c => c.sourceAssociation === sourceAssociation && c.parentTable === parentTable);
|
|
223
|
+
const dontOverwriteTexts = dependentKey.$foreignKeyConstraint && dependentKey.$foreignKeyConstraint.some(c => c.sourceAssociation === 'texts' && c.upLinkFor.texts);
|
|
224
|
+
if (!dontOverwriteUp && !dontOverwriteTexts)
|
|
225
|
+
dependentKey.$foreignKeyConstraint = dependentKey.$foreignKeyConstraint ? [ ...dependentKey.$foreignKeyConstraint, constraint ] : [ constraint ];
|
|
212
226
|
}
|
|
213
227
|
else {
|
|
214
|
-
const parentKeyValuePair = parentKeys.pop();
|
|
215
|
-
const parentKeyName = parentKeyValuePair[0];
|
|
216
|
-
|
|
217
|
-
const constraint = {
|
|
218
|
-
parentKey: parentKeyName,
|
|
219
|
-
parentTable,
|
|
220
|
-
upLinkFor,
|
|
221
|
-
sourceAssociation: tenantForeignKey
|
|
222
|
-
? [ sourceAssociation ]
|
|
223
|
-
: sourceAssociation,
|
|
224
|
-
onDelete: upLinkFor ? 'CASCADE' : 'RESTRICT',
|
|
225
|
-
validated,
|
|
226
|
-
enforced,
|
|
227
|
-
};
|
|
228
228
|
dependentKey.$foreignKeyConstraint = constraint;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
@@ -509,13 +509,11 @@ function createReferentialConstraints( csn, options ) {
|
|
|
509
509
|
if (isTenant && artifact.elements?.tenant) {
|
|
510
510
|
const element = artifact.elements.tenant;
|
|
511
511
|
if (element.$foreignKeyConstraint) {
|
|
512
|
-
const
|
|
512
|
+
const tenantConstraints = element.$foreignKeyConstraint;
|
|
513
513
|
delete element.$foreignKeyConstraint;
|
|
514
|
-
// create
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
copy.sourceAssociation = sourceAssociation;
|
|
518
|
-
createReferentialConstraints(copy, 'tenant');
|
|
514
|
+
// create (multiple) foreign key constraint(s) for the tenant column with each association in the dependent entity
|
|
515
|
+
tenantConstraints.forEach((c) => {
|
|
516
|
+
createReferentialConstraints(c, 'tenant');
|
|
519
517
|
});
|
|
520
518
|
}
|
|
521
519
|
}
|