You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### Description
This PR refactors the replication category. Now all checks share the
same PostgreSQL connection. The new `postgres.LazyConn` is not
thread-safe. It is used for executing checks sequentially.
Once the check finishes, the cleanup function must be called.
#### Type of Change
Please select the relevant option(s):
- [ ] 🐛 Bug fix (non-breaking change that fixes an issue)
- [ ] ✨ New feature (non-breaking change that adds functionality)
- [ ] 💥 Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 📚 Documentation update
- [x] 🔧 Refactoring (no functional changes)
- [ ] ⚡ Performance improvement
- [ ] 🧪 Test coverage improvement
- [ ] 🔨 Build/CI changes
- [ ] 🧹 Code cleanup
#### Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [x] All existing tests pass
#### Checklist
- [x] Code follows project style guidelines
- [x] Self-review completed
- [x] Code is well-commented
- [ ] Documentation updated where necessary
- One file per category of concrete checks (`connectivity.go`, `replication.go`, …).
11
11
12
+
The shared-conn primitive lives one floor down at `internal/postgres.LazyConn` so other callers can reuse it.
13
+
12
14
## Adding a new check
13
15
14
16
Adding a check is meant to be a small, mechanical edit. Keep it that way.
@@ -21,6 +23,7 @@ Adding a check is meant to be a small, mechanical edit. Keep it that way.
21
23
-**Return `error` only when the check itself couldn't run** (timeout, internal bug, malformed input). A detected problem is a `Finding`, not an error.
22
24
-**Put remediation in `Finding.Message`** — the user should be able to act on it without reading source.
23
25
3.**Materialise instances in the category builder** (e.g. `BuildConnectivityChecks`). The builder is the applicability gate: it reads `*stream.Config` and decides which instances are relevant. Inapplicable checks are silently omitted today; an explicit "skipped: <reason>" mechanism is deferred (see `docs/migration_preflight_issue.md` "Architecture decisions" #6).
26
+
-**If checks in the category share a Postgres connection**, call `postgres.NewLazyConn(url)` in the builder, hand `src.Acquire` (a `postgres.AcquireFunc`) to every check, and return `src.Close` as the cleanup. See `BuildReplicationChecks` for the pattern. The engine runs sequentially, so the first check to call `Source(ctx)` opens the conn and the rest reuse it. A failed dial is memoised too — only one connection attempt happens, even if every check reports its own check error.
24
27
4.**Tests.** Unit-test the check directly against mocked dependencies (`internal/postgres/mocks` has the postgres conn mock). For new categories, exercise the builder selection path through the cmd layer too.
0 commit comments