Skip to content

nebw #2: contract/catalog drift detection, Asset Review, semver adoption - #736

Draft
larsgeorge-db wants to merge 2 commits into
nebw-bugfixesfrom
nebw-contract-drift
Draft

larsgeorge-db wants to merge 2 commits into
nebw-bugfixesfrom
nebw-contract-drift

Conversation

@larsgeorge-db

Copy link
Copy Markdown
Collaborator

Summary

nebw feature #2: detect when an external catalog's schema has drifted from the data contract that governs it, surface the diff through an Asset Review, and adopt an approved change as either a new contract version (semver-bumped) or an in-place update.

Deterministic, no LLM (per scoping decision). Reuses the existing ContractChangeAnalyzer (diff + suggested bump), build_odcs_from_db, and clone_for_new_version.

Base is nebw-bugfixes (stacked on PR #735); it will retarget/merge cleanly once #735 lands on development.

Changes

  • DataContractsManager.build_candidate_odcs_from_schema_info() — turns a live connector SchemaInfo (columns + PK/FK from the UC-import work in nebw batch: custom UUID, RDF export fix, asset-type relationship CRUD, UC FK/PK import #735) into the aliased ODCS shape the analyzer consumes, so the current catalog state can be diffed against the contract.
  • DataContractsManager.replace_contract_schema() — swap a contract's schema objects in place from ODCS schema data.
  • ContractDriftManageranalyze_contract_drift, find_linked_asset_fqn, adopt_drift, create_drift_review.
    • In-place vs new version is severity-driven: breaking changes (major) are forced to a new version; a bump override may not weaken the required severity.
    • create_drift_review opens an Asset Review with the diff summary + suggested bump, deduped against any already-open review for the same asset.
  • Routes: POST /data-contracts/{id}/check-drift, /adopt-drift, /create-drift-review (resolve live schema via the connection's connector).

Testing

11 unit tests: detection (none/minor/major), adoption (new-version / in-place / breaking-reject / override-guard / no-drift), review creation + dedup. No cross-suite pollution (the drift module purges rows that the internal commit() in clone/replace would otherwise leak). Broader contract/version/review suites stay green (91 passed).

Follow-ups (documented, not in this PR)

  • Wire the existing data_contract_validation cluster job (which already detects drift) to auto-create reviews. It runs against Lakebase with no access to app managers, so needs a job-side reimplementation or app callback.
  • Indirect schema-verification path when no live connection exists.

Note

Push used SKIP_SECRET_SCAN=1 for the same pre-existing historical secrets already on main/development (see #735); none are new in this branch.

Detect when an external catalog's schema has drifted from the governing
data contract and adopt an approved change as a new version or in place.

Deterministic only (no LLM): reuses ContractChangeAnalyzer for the diff and
suggested semver bump, build_odcs_from_db for the contract side, and
clone_for_new_version for versioning.

New:
- DataContractsManager.build_candidate_odcs_from_schema_info(): turns a live
  connector SchemaInfo (columns + PK/FK from the UC import work) into the
  aliased ODCS shape the analyzer consumes, so the current catalog state can
  be diffed against the contract.
- DataContractsManager.replace_contract_schema(): swap a contract's schema
  objects in place from ODCS schema data (used by in-place adoption).
- ContractDriftManager: analyze_contract_drift(), find_linked_asset_fqn(),
  and adopt_drift(). The in-place-vs-new-version choice is severity-driven:
  breaking changes (major) are forced to a new version; a bump override may
  not weaken the required severity.
- Routes: POST /data-contracts/{id}/check-drift and /adopt-drift, resolving
  live schema via the connection's connector.

Scheduled drift-check job + auto-creating an Asset Review from detected drift
land in follow-up commits on this branch. See docs/plans/nebw-contract-drift.md.

Session: claude -r 01d95399-c840-4b99-b76c-735490295c66
Add ContractDriftManager.create_drift_review(): on detected drift, open an
Asset Review for a steward with the diff summary and suggested bump, deduped
against any already-open review for the same asset FQN. Exposed via
POST /data-contracts/{id}/create-drift-review (resolves live schema through the
connection's connector, runs analysis, creates the review when drift exists).

Per decision, drift->review is app-side/on-demand in this PR; wiring the
existing data_contract_validation cluster job to auto-create reviews is a
documented follow-up (it runs against Lakebase with no access to app managers).

Tests cover review creation, open-review dedup, and the no-reviews-manager
path; the drift test module purges committed rows (clone/replace commit
internally) so it does not pollute other suites.

Session: claude -r 01d95399-c840-4b99-b76c-735490295c66
@larsgeorge-db
larsgeorge-db requested a review from a team as a code owner August 19, 2026 18:50
@larsgeorge-db
larsgeorge-db marked this pull request as draft September 14, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant