Skip to content

Conversation

khanaffan
Copy link
Contributor

imodel-native: iTwin/imodel-native#1162

Issue Summary

  1. Initial Changeset Push:
    OpenSite+ modified the GCS and pushed a changeset.

  2. Schema Import by Civil Connector:
    Civil Connector imported a schema and made additional GCS changes.

  3. PullMerge Failure in OpenSite+:
    OpenSite+ (with no local changes) attempted a PullMerge(), which failed due to the following sequence:

    • A schema changeset was applied.
    • TxnManager disables tracking during applyChangeset(), but afterward, it recomputes ec_cache_* tables, which are tracked.
    • pullMergeEnd() calls saveChanges(), creating a transaction.
    • A subsequent changeset apply detects a rebase is needed.
      • During rebase, it tries to undo the transaction containing ec_cache_* changes.
      • This fails with a FOREIGN_KEY_CONSTRAINT error.
      • The failure occurs because ec_cache_* tables reference ec_class via foreign keys. Reverting the cache tables leads to missing parent ec_class entries.

Solution

  1. Exclude ec_cache_* from Tracking:
    These tables are derived and can be safely recomputed, so they should not be tracked.

  2. Disable NOFKCONSTRAINT Flag for Schema Changesets:
    Since ec_cache_* tables have FK relationships to ec_class and ec_table, cascading deletes must be allowed. This ensures that when primary tables are modified, related cache entries are also cleaned up properly.


Additional Safeguard

  • A warning has been added to flag any local changes detected during PullMergeEnd(), as ideally, there should be none.

@khanaffan khanaffan requested a review from a team as a code owner June 27, 2025 12:15
@khanaffan khanaffan requested a review from Copilot June 27, 2025 12:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a failure in PullMerge() by adding validation and tooling around changeset application.

  • Adds a standalone test to verify that applying a schema changeset with no local edits does not create pending transactions.
  • Introduces exportAsJson in SqliteChangesetReader to help debug and inspect changesets.
  • Updates the change metadata file to document this fix.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
core/backend/src/test/standalone/ApplyChangeset.test.ts New test verifying no local changes after pull merge
core/backend/src/SqliteChangesetReader.ts Added exportAsJson helper for dumping changesets
common/changes/@itwin/core-backend/affank-fix-pullmerge_2025-06-27-11-56.json Metadata entry for this PullMerge fix
Comments suppressed due to low confidence (1)

core/backend/src/SqliteChangesetReader.ts:434

  • The new exportAsJson utility is untested; consider adding unit tests to validate JSON structure, filtering logic, hashing of blobs, and indentation.
  public exportAsJson(

b1.close();
b2.close();

HubMock.shutdown();
Copy link

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

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

The test starts IModelHost but never shuts it down; consider adding an after hook to call await IModelHost.shutdown() and ensure clean teardown.

Copilot uses AI. Check for mistakes.

khanaffan and others added 3 commits June 27, 2025 17:19
…6-27-11-56.json

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants