Skip to content

Conversation

@stefanrudi
Copy link
Collaborator

@stefanrudi stefanrudi commented Oct 24, 2025

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

  • Insert the composite key into db column
  • Consider localisation within objectID in trigger
  • Support Large Strings (LargeString leading to failing insert #173)
  • Add test cases for Java
  • Provide trigger for SQLite and H2 for local development
  • Update and extend test cases
  • Create migration plan
  • Update documentation

@stefanrudi stefanrudi self-assigned this Oct 24, 2025
@stefanrudi stefanrudi changed the title feat: Refactor change-tracking logic to db trigger [wip] feat: Refactor change-tracking logic to db trigger Oct 29, 2025
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())`;
Copy link
Contributor

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.


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`;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants