-
Notifications
You must be signed in to change notification settings - Fork 15
[wip] feat: Refactor change-tracking logic to db trigger #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| const insertSQL = `INSERT INTO sap_changelog_Changes | ||
| (ID, ATTRIBUTE, VALUECHANGEDFROM, VALUECHANGEDTO, ENTITY, ENTITYKEY, OBJECTID, ROOTENTITY, ROOTENTITYKEY, ROOTOBJECTID, CREATEDAT, CREATEDBY, VALUEDATATYPE, MODIFICATION, TRANSACTIONID) | ||
| VALUES | ||
| (RANDOM_UUID(), '${col.name}', NULL, ${sqlExpr}, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), CURRENT_USER(), '${col.type}', 'create', TRANSACTION_ID())`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CURRENT_TIMESTAMP and CURRENT_USER are very likely supposed to be $now and $user. For their SQL equivelent it is defined at @sap/cds-compiler/lib/render/utils/common.js.
lib/trigger/hdi.js
Outdated
|
|
||
| function considerLargeString(val) { | ||
| // CASE WHEN LENGTH(:val) > 5000 THEN LEFT(:val, 4997) || '...' ELSE :val END | ||
| return val === 'NULL' ? 'NULL' : `CASE WHEN LENGTH(${val}) > 5000 THEN LEFT(${val}, 4997) || '...' ELSE ${val} END`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a re use function if it would have used cqn.
This PR introduces a new version of the change-tracking plugin where the creation of changes and changelogs are done by DB trigger instead of event handlers. This allow performance advantages and support for both runtimes.
Before Merge
LargeStringleading to failing insert #173)