Skip to content

feat: a baseline that covers bundles applied outside ExponetDB (ADR-0040, OD-72) - #69

Merged
davdxpx merged 3 commits into
mainfrom
feat/baseline-covers-bundles
Nov 4, 2026
Merged

davdxpx merged 3 commits into
mainfrom
feat/baseline-covers-bundles

Conversation

@davdxpx

@davdxpx davdxpx commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Summary

Why. A target imported after other targets of its project applied stream bundles, whose history already holds their effect, could not be baselined at the stream's head. Planning counts only exponetdb ledger rows as applied, so every such bundle stayed pending. The case is REOSA production: 40 bundles went to staging through ExponetDB and reached production as legacy files. Owner decision OD-72 (a), recorded in #68.

What. The baseline plan request takes covers, a list of stream bundle ids. On the CLI this is migration import baseline <report> --covers <ids>.

Planning refuses a cover when:

  • the id is unknown to the stream;
  • the set is not closed under dependsOn (MIGRATION_DEPENDENCY_UNKNOWN);
  • the bundle has no dependencies (MIGRATION_DEPENDENCY_MISSING, because in a baselined stream only baselines are roots);
  • it is on production without staging evidence. This uses collectEvidence, the same function as a migration plan, with no break-glass.

On production, planning also requires:

  • a verify.sql for every covered bundle;
  • that each verify.sql is admitted and resolved as the observer. The consumer code it calls is bound into the plan.

Apply:

  • writes one ledger row per covered bundle before the baseline:<slug> row. Each row uses the bundle's own id, origin legacy_import, provenance legacy_applied_statements and source.covered = true. The target ledger's schema is unchanged;
  • re-reads the staging evidence in checkBindings.

Planning afterwards. planOrder counts a legacy_import row with a bundle id as an applied bundle.

Verification. The baseline's run gains a runtime layer: each covered verify.sql, from the newest revision with the recorded checksum. A failure fails the run, which keeps production plans blocked through migration.dependencies-verified. The layer keeps one failure per covered bundle, and migration status reads each covered row's own share. A corrected verify.sql is a new revision of the same checksum, so migration verify baseline:<slug> picks it up.

serve holds observer sessions only. So there is no plan-time dry run of verify.sql; it runs as the verifier in the worker.

Contract. BaselinePlanRequest.covers is additive and optional. The generated OpenAPI and SDK and the CLI reference are regenerated.

Docs. New ADR-0040, legacy-import.md Step 6 and §3, and the ADR index.

An independent review found no P1. Its three P2 and one of its P3 findings are fixed in e1f34e00: verify.sql required on production, consumer code bound, evidence re-read at apply, each covered row's own status.

Order. Merge #68 first, because ADR-0040 links OD-72 there. A redeploy happens only on the owner's word (W10-D10).

Test plan

  • packages/migrations-engine integration suite on PostgreSQL 16, 17 and 18: 22 files, 261 tests passed. This includes the new baseline-covers.int.test.ts with 18 tests:
    • refusals for an uncovered dependency, an unknown id and a cover without staging evidence;
    • a covered row written and verified;
    • the next production plan holding only what production lacks;
    • a covered verify.sql that does not hold, failing the baseline and the row.
  • Unit tests: migrations-engine, application, contracts, sdk, cli and server.
  • Typecheck of every affected package, biome check ., verify:generated, golden:check and boundaries.
  • Owner review and merge.
  • Redeploy on the owner's word, then the REOSA production import with --covers.

Developed by @davdxpx

…040, OD-72)

A target imported after other targets of its project applied stream bundles,
whose history holds their effect, names those bundles in its baseline
(covers). Each becomes a ledger row of the baseline under the bundle's own id
(origin legacy_import, provenance legacy_applied_statements, covered: true),
before the baseline row. Planning counts such rows as applied bundles; the set
is closed under dependsOn and needs staging evidence on production; the
baseline's verification runs their verify.sql as its runtime layer (newest
revision with the recorded checksum). serve holds observer sessions only, so
there is no plan-time dry run.

Contract: BaselinePlanRequest.covers (additive). CLI: migration import
baseline --covers. Integration test on real PostgreSQL added; not run yet
(the local Docker daemon does not start).

Developed by @davdxpx
…al PostgreSQL

A covered bundle without dependencies is refused (MIGRATION_DEPENDENCY_MISSING):
in a stream with a baseline only baselines are roots, so every later plan on the
target would fail on it. The integration test now baselines staging and
production on one history and passes on PostgreSQL 16, 17 and 18.

Developed by @davdxpx
…mer code bound, evidence re-read at apply, a covered row's own status

- A production cover without verify.sql is refused: nothing would check its
  effect there.
- Each covered verify.sql is admitted and resolved as the observer at planning;
  the consumer code it calls is bound into the plan and checked when it runs.
- checkBindings re-reads the staging evidence of production covers.
- The runtime layer keeps one failure per covered bundle that did not hold, and
  migration status reads each covered row's own share (it read passed before).
- Integration test: a covered verify.sql that does not hold fails the baseline
  and the row (PostgreSQL 16, 17, 18).

Developed by @davdxpx
@davdxpx
davdxpx merged commit e14685e into main Nov 4, 2026
15 of 18 checks passed
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