Skip to content

feat(okapi-exposed): ExposedConnectionProvider support for multiple databases - #97

Merged
rawo merged 3 commits into
mainfrom
bugfix/issue-96
Jul 31, 2026
Merged

feat(okapi-exposed): ExposedConnectionProvider support for multiple databases#97
rawo merged 3 commits into
mainfrom
bugfix/issue-96

Conversation

@rawo

@rawo rawo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fix (ExposedConnectionProvider.kt): added a required database: Database constructor param; withConnection now reads database.transactionManager.currentOrNull() (per-database transaction manager) instead of the global TransactionManager.currentOrNull(), matching the existing pattern in ExposedTransactionRunner/ExposedTransactionContextValidator. KDoc updated to explain the multi-database scoping and the breaking change.

Tests: updated ExposedConnectionProviderTest.kt to pass a Database, plus two new regression tests — one confirming it throws when only a different database's transaction is active, one confirming it still resolves correctly when nested inside a transaction on another database.

Verified the fix guards a real regression two ways:

  1. Reverting the main-code change entirely broke compilation of the test suite (signature-level guard).
  2. Keeping the new constructor but reverting only the internal lookup to the global TransactionManager made the new "different Database" test fail exactly as expected, confirming it's a genuine behavioral guard, not just a compile-time one.

CHANGELOG.md: added an ### Changed (BREAKING) entry under [Unreleased] documenting the constructor change and linking issue #96, per this project's post-1.0.0 semver discipline.

ktlintCheck and the full okapi-exposed test suite (11 tests) pass clean.

Copilot AI review requested due to automatic review settings July 31, 2026 07:42
Copilot AI previously approved these changes Jul 31, 2026

Copilot AI 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.

🟢 Ready to approve

The behavior change is narrowly scoped, aligned with existing module patterns, and is covered by targeted regression tests plus a documented breaking-change entry.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR fixes a multi-database correctness issue in okapi-exposed by scoping ExposedConnectionProvider to a specific Exposed Database, aligning it with the existing ExposedTransactionRunner/ExposedTransactionContextValidator behavior and preventing accidental use of another database’s active transaction.

Changes:

  • Make ExposedConnectionProvider require a database: Database constructor param and use database.transactionManager.currentOrNull() instead of the global TransactionManager.currentOrNull().
  • Expand unit tests to cover multi-database scenarios (wrong-db active transaction throws; nested cross-db transactions still resolve correctly).
  • Document the breaking change under [Unreleased] in CHANGELOG.md.
File summaries
File Description
okapi-exposed/src/main/kotlin/com/softwaremill/okapi/exposed/ExposedConnectionProvider.kt Scope connection lookup to a specific Database and update KDoc + error message accordingly.
okapi-exposed/src/test/kotlin/com/softwaremill/okapi/exposed/ExposedConnectionProviderTest.kt Update tests for new constructor signature and add multi-database regression coverage.
CHANGELOG.md Add a breaking-change entry describing the new required constructor parameter and behavior change.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings July 31, 2026 08:08

Copilot AI 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.

🟡 Not ready to approve

The added nested multi-database regression test currently doesn’t exercise the key “outbox transaction outer, other DB transaction inner” case, so a reversion to global transaction resolution could go undetected.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

okapi-exposed/src/test/kotlin/com/softwaremill/okapi/exposed/ExposedConnectionProviderTest.kt:57

  • The nested-transaction test currently nests transaction(otherDb) { transaction(outboxDb) { ... } }, which would still pass even if withConnection incorrectly used the global TransactionManager.currentOrNull() (because the outbox transaction is innermost in that scenario). To actually guard the multi-DB nesting behavior, invert the nesting (outboxDb outer, otherDb inner) and assert the connection belongs to the outbox DB (e.g., by checking the JDBC URL), not just that it’s open.
    test("resolves the outbox Database's transaction even when nested inside a transaction on another Database") {
        val connectionWasOpen: Boolean = transaction(otherDb) {
            transaction(outboxDb) {
                provider.withConnection { conn -> !conn.isClosed }
            }
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings July 31, 2026 08:48
Copilot AI dismissed their stale review, a newer Copilot review was requested July 31, 2026 08:50

Copilot AI 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.

🟢 Ready to approve

The change aligns ExposedConnectionProvider with existing per-database patterns, and the added tests meaningfully validate the regression scenario and expected behavior.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@rawo
rawo merged commit effc8eb into main Jul 31, 2026
9 checks passed
@rawo
rawo deleted the bugfix/issue-96 branch July 31, 2026 08:59
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.

2 participants