@cap-js/change-tracking 2.0.0-beta.2 → 2.0.0-beta.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 +21 -1
- package/README.md +87 -244
- package/cds-plugin.js +1 -1
- package/index.cds +326 -41
- package/lib/csn-enhancements/annotations.js +77 -0
- package/lib/{model-enhancer.js → csn-enhancements/index.js} +7 -70
- package/lib/csn-enhancements/timezoneProperties.js +81 -0
- package/lib/h2/java-codegen.js +1 -1
- package/lib/hana/register.js +36 -7
- package/lib/hana/sql-expressions.js +1 -1
- package/lib/postgres/register.js +12 -0
- package/lib/postgres/sql-expressions.js +1 -1
- package/lib/sqlite/sql-expressions.js +1 -1
- package/lib/utils/change-tracking.js +6 -2
- package/lib/utils/composition-helpers.js +4 -6
- package/lib/utils/entity-collector.js +67 -42
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
6
6
|
|
|
7
|
-
## Version 2.0.0-beta.
|
|
7
|
+
## Version 2.0.0-beta.5 - tbd
|
|
8
8
|
|
|
9
9
|
### Added
|
|
10
10
|
|
|
@@ -12,6 +12,23 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
|
12
12
|
|
|
13
13
|
### Changed
|
|
14
14
|
|
|
15
|
+
## Version 2.0.0-beta.4 - 16.03.26
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- Tracked Date, DateTime, Time and Timestamp properties are now correctly formatted again.
|
|
20
|
+
- If a tracked property is annotated with `@Common.Timezone` the changelog now considers the Timezone as well.
|
|
21
|
+
|
|
22
|
+
## Version 2.0.0-beta.3 - 13.03.26
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- CSV data for `i18nKeys` and `CHANGE_TRACKING_DUMMY` is now correctly generated during the HANA build
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- Changes from child entities are shown on the parent ChangeView by default
|
|
29
|
+
- Depth of displayed child changes can be configured via `maxDisplayHierarchyDepth`
|
|
30
|
+
- Improved search capabilities for changes
|
|
31
|
+
|
|
15
32
|
## Version 2.0.0-beta.2 - 11.03.26
|
|
16
33
|
|
|
17
34
|
### Fixed
|
|
@@ -51,6 +68,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
|
51
68
|
- Localization is performed on database level and therefore the table `sap.changelog.i18nKeys` that stores localized labels was added
|
|
52
69
|
- Expose localized label fields on `sap.changelog.ChangeView`
|
|
53
70
|
|
|
71
|
+
### Removed
|
|
72
|
+
- Removed configuration option `considerLocalizedValues`
|
|
73
|
+
|
|
54
74
|
## Version 1.1.4 - 03.12.25
|
|
55
75
|
|
|
56
76
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Tracking Plugin for SAP Cloud Application Programming Model (CAP)
|
|
2
2
|
|
|
3
|
-
a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-packages) for automatic capturing, storing, and viewing of
|
|
3
|
+
a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-packages) for automatic capturing, storing, and viewing of change records for modelled entities.
|
|
4
4
|
|
|
5
5
|
[](https://api.reuse.software/info/github.com/cap-js/change-tracking)
|
|
6
6
|
|
|
@@ -19,9 +19,8 @@ a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-package
|
|
|
19
19
|
- [Altered Table View](#altered-table-view)
|
|
20
20
|
- [Disable Lazy Loading](#disable-lazy-loading)
|
|
21
21
|
- [Disable UI Facet generation](#disable-ui-facet-generation)
|
|
22
|
-
|
|
22
|
+
- [Disable Association to Changes Generation](#disable-association-to-changes-generation)
|
|
23
23
|
- [Examples](#examples)
|
|
24
|
-
- [Specify Object ID](#specify-object-id)
|
|
25
24
|
- [Tracing Changes](#tracing-changes)
|
|
26
25
|
- [Don'ts](#donts)
|
|
27
26
|
- [Contributing](#contributing)
|
|
@@ -30,12 +29,23 @@ a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-package
|
|
|
30
29
|
|
|
31
30
|
## Try it Locally
|
|
32
31
|
|
|
33
|
-
To enable change tracking, simply add this self-configuring plugin package to your project
|
|
32
|
+
To enable change tracking, simply add this self-configuring plugin package to your project and add the `@changelog` annotation to your data model, as explained in the [Detailed Explanation](#detailed-explanation).
|
|
34
33
|
|
|
35
34
|
```sh
|
|
36
35
|
npm add @cap-js/change-tracking
|
|
37
36
|
```
|
|
38
37
|
|
|
38
|
+
Alternatively, a full sample application is provided in the `tests/bookshop` folder, against which you can test your changes:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
git clone https://github.com/cap-js/change-tracking
|
|
42
|
+
cd change-tracking
|
|
43
|
+
npm i
|
|
44
|
+
cd tests/bookshop
|
|
45
|
+
cds watch
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
39
49
|
> [!Warning]
|
|
40
50
|
>
|
|
41
51
|
> Please note that if your project is multi-tenant, then the CDS version must be higher than 8.6 and the mtx version higher than 2.5 for change-tracking to work.
|
|
@@ -83,10 +93,6 @@ cds watch
|
|
|
83
93
|
|
|
84
94
|
#### Change History View
|
|
85
95
|
|
|
86
|
-
> [!IMPORTANT]
|
|
87
|
-
> To ensure proper lazy loading of the Change History table, please use **SAPUI5 version 1.120.0** or higher.`<br>`
|
|
88
|
-
> If you wish to *disable* this feature, please see the customization section on how to [disable lazy loading](#disable-lazy-loading).
|
|
89
|
-
|
|
90
96
|
<img width="1300" alt="change-history" src="_assets/changes.png">
|
|
91
97
|
|
|
92
98
|
If you have a Fiori Element application, the CDS plugin automatically provides and generates a view `sap.changelog.ChangeView`, the facet of which is automatically added to the Fiori Object Page of your change-tracked entities/elements. In the UI, this corresponds to the *Change History* table which serves to help you to view and search the stored change records of your modeled entities.
|
|
@@ -95,7 +101,7 @@ If you have a Fiori Element application, the CDS plugin automatically provides a
|
|
|
95
101
|
|
|
96
102
|
### Human-readable Types and Fields
|
|
97
103
|
|
|
98
|
-
By default the implementation looks up *Object Type* names or *Field* names from respective `@title` or `@Common.Label` annotations
|
|
104
|
+
By default the implementation looks up *Object Type* names or *Field* names from respective `@title` or `@Common.Label` annotations and uses the technical name as a fall back.
|
|
99
105
|
|
|
100
106
|
For example, without the `@title` annotation, changes to conversation entries would show up with the technical entity name:
|
|
101
107
|
|
|
@@ -104,7 +110,7 @@ For example, without the `@title` annotation, changes to conversation entries wo
|
|
|
104
110
|
With an annotation, and possible i18n translations like so:
|
|
105
111
|
|
|
106
112
|
```cds
|
|
107
|
-
annotate
|
|
113
|
+
annotate Incidents.conversations with @title: '{i18n>CONVERSATION}';
|
|
108
114
|
```
|
|
109
115
|
|
|
110
116
|
We get a human-readable display for *Object Type*:
|
|
@@ -115,21 +121,39 @@ We get a human-readable display for *Object Type*:
|
|
|
115
121
|
|
|
116
122
|
The changelog annotations for *Object ID* are defined at entity level.
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
For example, having a `@changelog` annotation without any additional identifiers, changes to conversation entries would show up as simple entity IDs:
|
|
124
|
+
Having a `@changelog` annotation without any additional identifiers, changes to conversation entries show up as simple entity IDs:
|
|
121
125
|
|
|
122
126
|
<img width="1300" alt="change-history-id" src="_assets/changes-id-wbox.png">
|
|
123
127
|
|
|
124
|
-
However, this is not advisable
|
|
128
|
+
However, this is not advisable, with an explicit object ID increasing readability as follows:
|
|
125
129
|
|
|
126
130
|
```cds
|
|
127
|
-
annotate
|
|
131
|
+
annotate Incidents.conversation with @changelog: [author, timestamp];
|
|
128
132
|
```
|
|
129
133
|
|
|
130
134
|
<img width="1300" alt="change-history-id-hr" src="_assets/changes-id-hr-wbox.png">
|
|
131
135
|
|
|
132
|
-
|
|
136
|
+
The annotation accepts a list of paths, meaning the following examples are all possible as well:
|
|
137
|
+
|
|
138
|
+
```cds
|
|
139
|
+
type CustomType : String;
|
|
140
|
+
|
|
141
|
+
extend Customers with elements {
|
|
142
|
+
note: CustomType
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
annotate Incidents with @changelog: [
|
|
146
|
+
title, customer.note, urgency.name
|
|
147
|
+
];
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```cds
|
|
151
|
+
annotate Incidents with @changelog: [
|
|
152
|
+
customer.address.city, customer.address.streetAddress, status.criticality
|
|
153
|
+
] {
|
|
154
|
+
title @changelog;
|
|
155
|
+
}
|
|
156
|
+
```
|
|
133
157
|
|
|
134
158
|
### Human-readable Values
|
|
135
159
|
|
|
@@ -153,27 +177,33 @@ customer @changelog: [customer.name];
|
|
|
153
177
|
|
|
154
178
|
<img width="1300" alt="change-history-value-hr" src="_assets/changes-value-hr-wbox.png">
|
|
155
179
|
|
|
180
|
+
### Tracing any kind of change
|
|
181
|
+
|
|
182
|
+
Change tracking is implemented with Database triggers and supports HANA Cloud, SQLite, Postgres and H2.
|
|
183
|
+
|
|
184
|
+
Leveraging database triggers means any change will be tracked no matter how it is represented in the service. Thus tracking changes made via unions, or via views with joins will still work.
|
|
185
|
+
|
|
156
186
|
## Advanced Options
|
|
157
187
|
|
|
158
188
|
### Altered table view
|
|
159
189
|
|
|
160
|
-
The *Change History* view can be easily adapted and configured to your own needs by simply changing or extending it. For example, let's assume we only want to show the first 5 columns in equal spacing, we would extend `
|
|
190
|
+
The *Change History* view can be easily adapted and configured to your own needs by simply changing or extending it. For example, let's assume we only want to show the first 5 columns in equal spacing, we would extend `db/change-tracking.cds` as follows:
|
|
161
191
|
|
|
162
192
|
```cds
|
|
163
193
|
using from '@cap-js/change-tracking';
|
|
164
194
|
|
|
165
195
|
annotate sap.changelog.ChangeView with @(
|
|
166
196
|
UI.LineItem : [
|
|
167
|
-
{ Value:
|
|
168
|
-
{ Value: createdAt
|
|
169
|
-
{ Value: createdBy
|
|
170
|
-
{ Value:
|
|
171
|
-
{ Value: objectID
|
|
197
|
+
{ Value: modificationLabel },
|
|
198
|
+
{ Value: createdAt },
|
|
199
|
+
{ Value: createdBy },
|
|
200
|
+
{ Value: entityLabel },
|
|
201
|
+
{ Value: objectID }
|
|
172
202
|
]
|
|
173
203
|
);
|
|
174
204
|
```
|
|
175
205
|
|
|
176
|
-
In the UI, the *Change History* table now contains
|
|
206
|
+
In the UI, the *Change History* table now contains only the five columns with the desired properties:
|
|
177
207
|
|
|
178
208
|
<img width="1300" alt="change-history-custom" src="_assets/changes-custom.png">
|
|
179
209
|
|
|
@@ -181,7 +211,7 @@ For more information and examples on adding Fiori Annotations, see [Adding SAP F
|
|
|
181
211
|
|
|
182
212
|
### Disable lazy loading
|
|
183
213
|
|
|
184
|
-
To disable the lazy loading feature of the *Change History* table, you can add the following annotation to your `
|
|
214
|
+
To disable the lazy loading feature of the *Change History* table, you can add the following annotation to your `db/change-tracking.cds`:
|
|
185
215
|
|
|
186
216
|
```cds
|
|
187
217
|
using from '@cap-js/change-tracking';
|
|
@@ -191,11 +221,11 @@ annotate sap.changelog.aspect @(UI.Facets: [{
|
|
|
191
221
|
ID : 'ChangeHistoryFacet',
|
|
192
222
|
Label : '{i18n>ChangeHistory}',
|
|
193
223
|
Target: 'changes/@UI.PresentationVariant',
|
|
194
|
-
|
|
224
|
+
@UI.PartOfPreview
|
|
195
225
|
}]);
|
|
196
226
|
```
|
|
197
227
|
|
|
198
|
-
The system now uses the
|
|
228
|
+
The system now uses the SAP Fiori elements default setting `@UI.PartOfPreview: true`, such that the table will always be shown when navigating to that respective Object page.
|
|
199
229
|
|
|
200
230
|
### Disable UI Facet generation
|
|
201
231
|
|
|
@@ -220,10 +250,10 @@ entity SalesOrders {
|
|
|
220
250
|
|
|
221
251
|
### Disable Association to Changes Generation
|
|
222
252
|
|
|
223
|
-
For some scenarios, e.g. when doing `UNION` and the `@changelog`
|
|
253
|
+
For some scenarios, e.g. when doing `UNION` and the `@changelog` annotation is still propagated, the automatic addition of the association to `changes` does not make sense. You can use `@changelog.disable_assoc`for this to be disabled on entity level.
|
|
224
254
|
|
|
225
255
|
> [!IMPORTANT]
|
|
226
|
-
> This will also
|
|
256
|
+
> This will also suppress the addition of the UI facet, since the change-view is no longer available as the target entity.
|
|
227
257
|
|
|
228
258
|
### Select types of changes to track
|
|
229
259
|
|
|
@@ -249,25 +279,39 @@ By default, deleting a record will also automatically delete all associated chan
|
|
|
249
279
|
You can turn this behavior off globally by adding the following switch to the `package.json` of your project
|
|
250
280
|
|
|
251
281
|
```json
|
|
252
|
-
...
|
|
253
282
|
"cds": {
|
|
254
283
|
"requires": {
|
|
255
|
-
...
|
|
256
284
|
"change-tracking": {
|
|
257
285
|
"preserveDeletes": true
|
|
258
286
|
}
|
|
259
|
-
...
|
|
260
287
|
}
|
|
261
288
|
}
|
|
262
|
-
...
|
|
263
289
|
```
|
|
290
|
+
|
|
264
291
|
> [!IMPORTANT]
|
|
265
292
|
> Preserving the change logs of deleted data can have a significant impact on the size of the change logging table, since now such data also survives automated data retention runs.
|
|
266
293
|
> You must implement an own **data retention strategy** for the change logging table in order to manage the size and performance of your database.
|
|
267
294
|
|
|
295
|
+
### Adjust the depth of the entity hierarchy tracking
|
|
296
|
+
|
|
297
|
+
By default, the depth of the changes hierarchy for any entity is 3. This means, its changes as well as the changes of its compositions and the compositions of its compositions are shown on the UI.
|
|
298
|
+
|
|
299
|
+
```json
|
|
300
|
+
"cds": {
|
|
301
|
+
"requires": {
|
|
302
|
+
"change-tracking": {
|
|
303
|
+
"maxDisplayHierarchyDepth": 3
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
> [!IMPORTANT]
|
|
310
|
+
> The depth of the hierarchy has a performance impact, so be careful with increasing it!
|
|
311
|
+
|
|
268
312
|
### Tracking localized values
|
|
269
313
|
|
|
270
|
-
|
|
314
|
+
Localized properties, like `descr` in the example, are respected and the localized value during change log creation is used for the label.
|
|
271
315
|
|
|
272
316
|
```cds
|
|
273
317
|
entity Incidents : cuid, managed {
|
|
@@ -281,129 +325,20 @@ entity Status {
|
|
|
281
325
|
}
|
|
282
326
|
```
|
|
283
327
|
|
|
284
|
-
you can save the localized values into the change log instead of the default values, by setting `considerLocalizedValues`:
|
|
285
|
-
|
|
286
|
-
```json
|
|
287
|
-
...
|
|
288
|
-
"cds": {
|
|
289
|
-
"requires": {
|
|
290
|
-
"change-tracking": {
|
|
291
|
-
"considerLocalizedValues": true
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
...
|
|
296
|
-
```
|
|
297
|
-
|
|
298
328
|
Please be aware this means the localized value is then stored and shown in the change log, e.g. if a user speaking another language accesses the change log later, they will still see the value in the language used by the user who caused the change log.
|
|
299
329
|
|
|
300
330
|
## Examples
|
|
301
331
|
|
|
302
332
|
This section describes modelling cases for further reference, from simple to complex, including the following:
|
|
303
333
|
|
|
304
|
-
- [Specify Object ID](#specify-object-id)
|
|
305
|
-
- [Use Case 1: Annotate single field/multiple fields of associated table(s) as the Object ID](#use-case-1-annotate-single-fieldmultiple-fields-of-associated-tables-as-the-object-id)
|
|
306
|
-
- [Use Case 2: Annotate single field/multiple fields of project customized types as the Object ID](#use-case-2-annotate-single-fieldmultiple-fields-of-project-customized-types-as-the-object-id)
|
|
307
|
-
- [Use Case 3: Annotate chained associated entities from the current entity as the Object ID](#use-case-3-annotate-chained-associated-entities-from-the-current-entity-as-the-object-id)
|
|
308
334
|
- [Tracing Changes](#tracing-changes)
|
|
309
335
|
- [Use Case 1: Trace the changes of child nodes from the current entity and display the meaningful data from child nodes (composition relation)](#use-case-1-trace-the-changes-of-child-nodes-from-the-current-entity-and-display-the-meaningful-data-from-child-nodes-composition-relation)
|
|
310
336
|
- [Use Case 2: Trace the changes of associated entities from the current entity and display the meaningful data from associated entities (association relation)](#use-case-2-trace-the-changes-of-associated-entities-from-the-current-entity-and-display-the-meaningful-data-from-associated-entities-association-relation)
|
|
311
|
-
- [Use Case 3: Trace the changes of
|
|
312
|
-
- [Use Case 4: Trace the changes of chained associated entities from the current entity and display the meaningful data from associated entities (association relation)](#use-case-4-trace-the-changes-of-chained-associated-entities-from-the-current-entity-and-display-the-meaningful-data-from-associated-entities-association-relation)
|
|
313
|
-
- [Use Case 5: Trace the changes of union entity and display the meaningful data](#use-case-5-trace-the-changes-of-union-entity-and-display-the-meaningful-data)
|
|
337
|
+
- [Use Case 3: Trace the changes of chained associated entities from the current entity and display the meaningful data from associated entities (association relation)](#use-case-3-trace-the-changes-of-chained-associated-entities-from-the-current-entity-and-display-the-meaningful-data-from-associated-entities-association-relation)
|
|
314
338
|
- [Don'ts](#donts)
|
|
315
339
|
- [Use Case 1: Don't trace changes for field(s) with `Association to many`](#use-case-1-dont-trace-changes-for-fields-with-association-to-many)
|
|
316
340
|
- [Use Case 2: Don't trace changes for field(s) with *Unmanaged Association*](#use-case-2-dont-trace-changes-for-fields-with-unmanaged-association)
|
|
317
341
|
|
|
318
|
-
### Specify Object ID
|
|
319
|
-
|
|
320
|
-
Use cases for Object ID annotation
|
|
321
|
-
|
|
322
|
-
#### Use Case 1: Annotate single field/multiple fields of associated table(s) as the Object ID
|
|
323
|
-
|
|
324
|
-
Modelling in `db/schema.cds`
|
|
325
|
-
|
|
326
|
-
```cds
|
|
327
|
-
entity Incidents : cuid, managed {
|
|
328
|
-
...
|
|
329
|
-
customer : Association to Customers;
|
|
330
|
-
title : String @title: 'Title';
|
|
331
|
-
urgency : Association to Urgency default 'M';
|
|
332
|
-
status : Association to Status default 'N';
|
|
333
|
-
...
|
|
334
|
-
}
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
Add the following `@changelog` annotations in `srv/change-tracking.cds`
|
|
338
|
-
|
|
339
|
-
```cds
|
|
340
|
-
annotate ProcessorService.Incidents with @changelog: [customer.name, urgency.code, status.criticality] {
|
|
341
|
-
title @changelog;
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-

|
|
346
|
-
|
|
347
|
-
#### Use Case 2: Annotate single field/multiple fields of project customized types as the Object ID
|
|
348
|
-
|
|
349
|
-
Modelling in `db/schema.cds`
|
|
350
|
-
|
|
351
|
-
```cds
|
|
352
|
-
entity Incidents : cuid, managed {
|
|
353
|
-
...
|
|
354
|
-
customer : Association to Customers;
|
|
355
|
-
title : String @title: 'Title';
|
|
356
|
-
...
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
entity Customers : cuid, managed {
|
|
360
|
-
...
|
|
361
|
-
email : EMailAddress; // customized type
|
|
362
|
-
phone : PhoneNumber; // customized type
|
|
363
|
-
...
|
|
364
|
-
}
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
Add the following `@changelog` annotations in `srv/change-tracking.cds`
|
|
368
|
-
|
|
369
|
-
```cds
|
|
370
|
-
annotate ProcessorService.Incidents with @changelog: [customer.email, customer.phone] {
|
|
371
|
-
title @changelog;
|
|
372
|
-
}
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-

|
|
376
|
-
|
|
377
|
-
#### Use Case 3: Annotate chained associated entities from the current entity as the Object ID
|
|
378
|
-
|
|
379
|
-
Modelling in `db/schema.cds`
|
|
380
|
-
|
|
381
|
-
```cds
|
|
382
|
-
entity Incidents : cuid, managed {
|
|
383
|
-
...
|
|
384
|
-
customer : Association to Customers;
|
|
385
|
-
...
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
entity Customers : cuid, managed {
|
|
389
|
-
...
|
|
390
|
-
addresses : Association to Addresses;
|
|
391
|
-
...
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
Add the following `@changelog` annotations in `srv/change-tracking.cds`
|
|
396
|
-
|
|
397
|
-
```cds
|
|
398
|
-
annotate ProcessorService.Incidents with @changelog: [customer.addresses.city, customer.addresses.postCode] {
|
|
399
|
-
title @changelog;
|
|
400
|
-
}
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-

|
|
404
|
-
|
|
405
|
-
> Change-tracking supports annotating chained associated entities from the current entity as object ID of current entity in case the entity in consumer applications is a pure relation table. However, the usage of chained associated entities is not recommended due to performance cost.
|
|
406
|
-
|
|
407
342
|
### Tracing Changes
|
|
408
343
|
|
|
409
344
|
Use cases for tracing changes
|
|
@@ -426,16 +361,14 @@ aspect Conversation: managed, cuid {
|
|
|
426
361
|
}
|
|
427
362
|
```
|
|
428
363
|
|
|
429
|
-
Add the following `@changelog` annotations in `
|
|
364
|
+
Add the following `@changelog` annotations in `db/change-tracking.cds`
|
|
430
365
|
|
|
431
366
|
```cds
|
|
432
|
-
annotate
|
|
367
|
+
annotate Incidents with @changelog: [title] {
|
|
433
368
|
conversation @changelog: [conversation.message];
|
|
434
369
|
}
|
|
435
370
|
```
|
|
436
371
|
|
|
437
|
-

|
|
438
|
-
|
|
439
372
|
#### Use Case 2: Trace the changes of associated entities from the current entity and display the meaningful data from associated entities (association relation)
|
|
440
373
|
|
|
441
374
|
Modelling in `db/schema.cds`
|
|
@@ -455,42 +388,15 @@ entity Customers : cuid, managed {
|
|
|
455
388
|
}
|
|
456
389
|
```
|
|
457
390
|
|
|
458
|
-
Add the following `@changelog` annotations in `
|
|
391
|
+
Add the following `@changelog` annotations in `db/change-tracking.cds`
|
|
459
392
|
|
|
460
393
|
```cds
|
|
461
|
-
annotate
|
|
394
|
+
annotate Incidents with @changelog: [title] {
|
|
462
395
|
customer @changelog: [customer.email];
|
|
463
396
|
}
|
|
464
397
|
```
|
|
465
398
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
#### Use Case 3: Trace the changes of fields defined by project customized types and display the meaningful data
|
|
469
|
-
|
|
470
|
-
Modelling in `db/schema.cds`
|
|
471
|
-
|
|
472
|
-
```cds
|
|
473
|
-
type StatusType : Association to Status;
|
|
474
|
-
|
|
475
|
-
entity Incidents : cuid, managed {
|
|
476
|
-
...
|
|
477
|
-
title : String @title: 'Title';
|
|
478
|
-
status : StatusType default 'N';
|
|
479
|
-
...
|
|
480
|
-
}
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
Add the following `@changelog` annotations in `srv/change-tracking.cds`
|
|
484
|
-
|
|
485
|
-
```cds
|
|
486
|
-
annotate ProcessorService.Incidents with @changelog: [title] {
|
|
487
|
-
status @changelog: [status.code];
|
|
488
|
-
}
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-

|
|
492
|
-
|
|
493
|
-
#### Use Case 4: Trace the changes of chained associated entities from the current entity and display the meaningful data from associated entities (association relation)
|
|
399
|
+
#### Use Case 3: Trace the changes of chained associated entities from the current entity and display the meaningful data from associated entities (association relation)
|
|
494
400
|
|
|
495
401
|
Modelling in `db/schema.cds`
|
|
496
402
|
|
|
@@ -504,73 +410,21 @@ entity Incidents : cuid, managed {
|
|
|
504
410
|
|
|
505
411
|
entity Customers : cuid, managed {
|
|
506
412
|
...
|
|
507
|
-
|
|
413
|
+
address : Composition of one Addresses;
|
|
508
414
|
...
|
|
509
415
|
}
|
|
510
416
|
```
|
|
511
417
|
|
|
512
|
-
Add the following `@changelog` annotations in `
|
|
418
|
+
Add the following `@changelog` annotations in `db/change-tracking.cds`
|
|
513
419
|
|
|
514
420
|
```cds
|
|
515
|
-
annotate
|
|
516
|
-
customer @changelog: [customer.
|
|
421
|
+
annotate Incidents with @changelog: [title] {
|
|
422
|
+
customer @changelog: [customer.address.city, customer.address.streetAddress];
|
|
517
423
|
}
|
|
518
424
|
```
|
|
519
425
|
|
|
520
|
-

|
|
521
|
-
|
|
522
426
|
> Change-tracking supports analyzing chained associated entities from the current entity in case the entity in consumer applications is a pure relation table. However, the usage of chained associated entities is not recommended due to performance cost.
|
|
523
427
|
|
|
524
|
-
#### Use Case 5: Trace the changes of union entity and display the meaningful data
|
|
525
|
-
|
|
526
|
-
`Payable.cds`:
|
|
527
|
-
|
|
528
|
-
```cds
|
|
529
|
-
entity Payables : cuid {
|
|
530
|
-
displayId : String;
|
|
531
|
-
@changelog
|
|
532
|
-
name : String;
|
|
533
|
-
cryptoAmount : Decimal;
|
|
534
|
-
fiatAmount : Decimal;
|
|
535
|
-
};
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
`Payment.cds`:
|
|
539
|
-
|
|
540
|
-
```cds
|
|
541
|
-
entity Payments : cuid {
|
|
542
|
-
displayId : String; //readable ID
|
|
543
|
-
@changelog
|
|
544
|
-
name : String;
|
|
545
|
-
};
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
Union entity in `BusinessTransaction.cds`:
|
|
549
|
-
|
|
550
|
-
```cds
|
|
551
|
-
entity BusinessTransactions as(
|
|
552
|
-
select from payments.Payments{
|
|
553
|
-
key ID,
|
|
554
|
-
displayId,
|
|
555
|
-
name,
|
|
556
|
-
changes : Association to many ChangeView
|
|
557
|
-
on changes.objectID = ID AND changes.entity = 'payments.Payments'
|
|
558
|
-
}
|
|
559
|
-
)
|
|
560
|
-
union all
|
|
561
|
-
(
|
|
562
|
-
select from payables.Payables {
|
|
563
|
-
key ID,
|
|
564
|
-
displayId,
|
|
565
|
-
name,
|
|
566
|
-
changes : Association to many ChangeView
|
|
567
|
-
on changes.objectID = ID AND changes.entity = 'payables.Payables'
|
|
568
|
-
}
|
|
569
|
-
);
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-

|
|
573
|
-
|
|
574
428
|
### Don'ts
|
|
575
429
|
|
|
576
430
|
Don'ts
|
|
@@ -605,17 +459,6 @@ The reason is that: When deploying to relational databases, Associations are map
|
|
|
605
459
|
|
|
606
460
|
This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/change-tracking/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
|
|
607
461
|
|
|
608
|
-
### Testing changes locally
|
|
609
|
-
|
|
610
|
-
In the `tests/bookshop` folder a full sample application is provided, against which you can test your changes:
|
|
611
|
-
|
|
612
|
-
```sh
|
|
613
|
-
git clone https://github.com/cap-js/change-tracking
|
|
614
|
-
npm i
|
|
615
|
-
cd tests/bookshop
|
|
616
|
-
cds watch
|
|
617
|
-
```
|
|
618
|
-
|
|
619
462
|
## Code of Conduct
|
|
620
463
|
|
|
621
464
|
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
|
package/cds-plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const cds = require('@sap/cds');
|
|
2
2
|
|
|
3
|
-
const { enhanceModel } = require('./lib/
|
|
3
|
+
const { enhanceModel } = require('./lib/csn-enhancements');
|
|
4
4
|
const { registerSessionVariableHandlers } = require('./lib/skipHandlers.js');
|
|
5
5
|
const { deploySQLiteTriggers } = require('./lib/sqlite/register.js');
|
|
6
6
|
const { registerPostgresCompilerHook, deployPostgresLabels } = require('./lib/postgres/register.js');
|