Skip to content

fix: adjust generation to resolve issues with MTX#325

Draft
stefanrudi wants to merge 23 commits into
mainfrom
fix/mtx-upgrade
Draft

fix: adjust generation to resolve issues with MTX#325
stefanrudi wants to merge 23 commits into
mainfrom
fix/mtx-upgrade

Conversation

@stefanrudi

@stefanrudi stefanrudi commented May 27, 2026

Copy link
Copy Markdown
Contributor

Related to #321

  • Add per-tenant cds.xt.DeploymentService.after('deploy') hook so artifacts are deployed against the freshly created tenant schema (skipping the t0 metadata tenant)
  • The changes for SQLite and Postgres ensures that the plugins doesn't crash for multitenant-applications; however it solves symptoms that occurs because the triggers are generated during the on served event (SQLite -> cds.compile.to.sql runs in parallel and lead to the issue that triggers were registered before the table exist)
  • Only emit Changes_CT_INDEX / Changes_CT_parent_INDEX .hdbindex artifacts when the Changes table is in the compiled model (fixes requires db://SAP_CHANGELOG_CHANGES … not provided by any file HDI deploy errors)
  • Make enhanceModel work on xtended runtime CSNs (extensibility upgrades)
  • Invoke enhanceModel inside cds.compiler.to.hdi.migration and on cds.xt.ModelProviderService.{getCsn, getExtCsn} so HANA HDI builds and MPS consumers always see ChangeView (fixes invalid column name CHANGEVIEW_0.PARENT_ENTITYKEY on upgrades)
  • Skip ensureUndeployJsonHasTriggerPattern() in MTX (no local undeploy.json to maintain)
  • Add new mtx tests in `tests/mtx/mtx.test.js

@stefanrudi
stefanrudi requested a review from a team as a code owner May 27, 2026 07:57
@stefanrudi stefanrudi changed the title fix: add after deploy handler for SQLite and Postgres fix: adjust generation to resolves issues with mtx May 27, 2026
@stefanrudi stefanrudi changed the title fix: adjust generation to resolves issues with mtx fix: adjust generation to resolves issues with MTX May 27, 2026
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Fix: Add After-Deploy Handlers for SQLite and Postgres in MTX Scenarios

Bug Fix

🐛 Resolves multiple deployment failures in multi-tenant (MTX) applications by introducing after('deploy') handlers on cds.xt.DeploymentService for SQLite and Postgres. This ensures triggers, indexes, and ChangeView definitions are deployed using the correct tenant CSN model — after tables already exist — rather than during the served event where race conditions could occur.

Additionally fixes HDI deployment failures caused by .hdbindex artifacts being added unconditionally even when the sap.changelog.Changes table is absent from the migration delta, and corrects extensibility upgrade errors caused by enhanceModel not being called on the tenant CSN before HANA compilation.

Changes

  • cds-plugin.js: Registers the new registerSQLiteDeploymentHandler() and registerPostgresDeploymentHandler() handlers on startup.

  • lib/sqlite/register.js: Refactored into a _deploySQLiteTriggersAndLabels(model) helper. Added _deployChangeViews(csn) to handle service-level ChangeView DDL. Introduced registerSQLiteDeploymentHandler() which hooks into cds.xt.DeploymentService after each tenant deploy, calling enhanceModel on the tenant CSN (since cds.on('loaded') is never fired by ModelProviderService.getCsn()). The existing deploySQLiteTriggers() now skips execution in MTX scenarios. Triggers and indexes are now deployed sequentially to avoid referencing tables before they exist.

  • lib/postgres/register.js: Added _deployChangeViews(csn) and registerPostgresDeploymentHandler() mirroring the SQLite approach. Fixed a redundant return ddl in the compiler hook. Exports updated to include the new handler.

  • lib/hana/register.js: Calls enhanceModel(csn) at the start of the HDI migration compiler hook to ensure the CSN is enriched during extensibility upgrades. Moved .hdbindex artifact generation inside the if (triggers.length > 0) block to prevent HDI make-graph failures when the sap.changelog.Changes table is unchanged. Skips ensureUndeployJsonHasTriggerPattern() in multitenancy scenarios.

  • CHANGELOG.md: Documents all four fixes under the upcoming release.

Jira Issues

  • GitHub #321: HDI upgrade deploy fails: sap.changelog.Changes_CT_INDEX.hdbindex references db://SAP_CHANGELOG_CHANGES, which is not in the migration delta when the table is unchanged

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.21.0

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces solid fixes for multi-tenant startup crashes and HDI deployment failures. There are a few substantive issues to address: a potential TypeError from unguarded regex match results in the dropTriggers chain, missing null-guards for mps (ModelProviderService) in both the SQLite and Postgres deployment handlers which would crash on .getCsn(), a data-loss risk from the non-atomic delete+insert of label data, and a misleading comment in the HDI compiler hook around the enhanceModel idempotency behavior.

PR Bot Information

Version: 1.21.0

  • Correlation ID: 311b991b-5506-4553-9768-7eded64459cc
  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet
  • File Content Strategy: Full file content

Comment thread lib/sqlite/register.js Outdated
Comment thread lib/sqlite/register.js Outdated
Comment thread lib/postgres/register.js Outdated
Comment thread lib/sqlite/register.js Outdated
Comment thread lib/hana/register.js Outdated
@stefanrudi
stefanrudi marked this pull request as draft May 27, 2026 08:00
@stefanrudi stefanrudi changed the title fix: adjust generation to resolves issues with MTX fix: adjust generation to resolve issues with MTX May 27, 2026
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.

1 participant