Skip to content

Commit a373078

Browse files
refactor(db): extract domain stores from database runtime (#6987)
## Summary Finish the remaining database-store extraction tracked by [TheSentinel454#2](TheSentinel454#2) in one reviewable PR. This consolidates the previously stacked domain slices after #6782 merged. It preserves the runtime/store boundary established by #6660, #6668, #6700, and #6782 while separating database runtime infrastructure from domain-owned persistence: - `runtime/` owns pool construction and sizing, writer/reader routing, read sessions and route proofs, transaction infrastructure, observability primitives, replica fencing, health support, migrations, and cross-cutting runtime tests. - `store/` owns domain records, SQL, row parsing, locks and invariants, `Db` domain methods, focused tests, and logical-operation datastore spans. - `lib.rs` remains a 57-line compatibility facade that preserves existing crate-root paths and `Db` method signatures through re-exports. Domain coverage includes API tokens, authentication allowlists, reminders, event queries, threads, reactions, feeds, users and DMs, push, workflows/runs/approvals, relay membership and invites, product feedback, moderation/admin moderation, relay admin actions/operators, git repositories, archived identities, usage, partition maintenance, deletion, channel membership inherited from merged #6782, and the final runtime/store layout. The branch has been rebased onto current `main`. Database changes that landed there were incorporated rather than overwritten: `relay_admin_actions.rs` and `relay_operators.rs` now live under `store/`, their 27 public `Db` wrappers and existing behavior remain intact, and every wrapper has exactly one fixed-name datastore span. Concurrent changes to migration, moderation, admin moderation, and error handling are also retained. ### Exact base and head - Base: `main` at `ed11c8d8bf0a17402be5cf243724f89471530d2f` - Head: `codex/issue-2-store-extraction` at `be24430472d1a87ac5c0d6026c620cd6caea3537` ### Related issue - Structural tracker: [TheSentinel454#2](TheSentinel454#2) - Domain trackers: [#6](TheSentinel454#6), [#7](TheSentinel454#7), [#12](TheSentinel454#12), [#13](TheSentinel454#13) - Acceptance trackers: [#17](TheSentinel454#17), [#19](TheSentinel454#19) This supersedes #6783, #6784, #6787, #6788, #6789, #6792, #6820, #6794, #6796, #6797, #6798, #6799, #6804, #6805, #6806, #6808, #6809, #6811, #6812, #6813, #6814, #6815, and #6890. Their discussions remain available for review history. ### #17 / #19 acceptance - Preserves the metric names, fixed labels, transaction/lock timing boundaries, and privacy/cardinality constraints introduced by #6700. - Keeps exactly one datastore span per public logical operation, including the 27 relay-admin wrappers added on `main`. - Removes `store_ownership.rs`; physical ownership and focused source guards now enforce the boundary directly. - Leaves no `impl Db`, domain SQL, focused domain test group, or datastore span in `lib.rs`. - Preserves existing public paths such as `buzz_db::channel`, `buzz_db::event`, and `buzz_db::workflow` through crate-root re-exports while keeping internal `runtime` and `store` namespaces private. ### Non-goals - No SQL, schema, locking, transaction, retry, timeout, or client-visible behavior changes. - No generic store traits, domain handles, broad `PgExecutor` migration, new store crate, raw pool accessor, or broader directory reorganization. - No tracker issues are closed by this PR. ### Risk The cumulative diff is large but structural. Risk is primarily module-path, ownership, or conflict-resolution drift. It is mitigated by preserving public re-exports, comparing the newly moved `main` implementations to their upstream source, source guards, touched-crate compilation, PostgreSQL-backed test coverage, and an independent exact-head review on a separate clean Blox workstation. ### Testing Author workstation `buzz-tornquist-pr-6987-rebase`, rebased branch ending at exact head `be24430472d1a87ac5c0d6026c620cd6caea3537`: - `cargo fmt --all --check` - `cargo clippy -p buzz-db -p buzz-relay --all-targets -- -D warnings` - `cargo test -p buzz-db --lib` — 113 passed, 240 PostgreSQL tests intentionally ignored - `cargo test -p buzz-db --test observability_source` — 2 passed - PostgreSQL-backed `buzz-db` coverage under native PostgreSQL — 235 passed in the shared serial run; the five shared-state/config-sensitive cases passed as isolated reruns against fresh schemas, including the two owner-limit tests with their fixture's `BUZZ_MAX_COMMUNITIES_PER_OWNER=3` - `cargo test -p buzz-relay --lib -- --test-threads=1` under native PostgreSQL/Redis — 991 passed; the three current-month partition-sensitive identity-archive cases passed after provisioning the August 2026 test partition; 87 infrastructure-marked tests remained ignored - Source/diff guards — relay-admin implementation bodies match current `main`; all 27 public wrapper signatures are retained; exactly one datastore span wraps each wrapper; `lib.rs` has zero `impl Db` blocks and zero datastore spans; no duplicate top-level relay-admin modules or `store_ownership.rs`; `error.rs` matches current `main` Independent clean review workstation `buzz-tornquist-pr-6987-review`, detached at exact head `be24430472d1a87ac5c0d6026c620cd6caea3537`: - `cargo fmt --all --check` - `cargo clippy -p buzz-db -p buzz-relay --all-targets -- -D warnings` - `cargo test -p buzz-db --lib` — 113 passed, 240 ignored - `cargo test -p buzz-db --test observability_source` — 2 passed - Exact-head ownership/re-export/instrumentation audit — no remaining actionable findings --------- Signed-off-by: OpenAI Codex <[email protected]> Signed-off-by: tornquist <[email protected]> Co-authored-by: OpenAI Codex <[email protected]>
1 parent 2f66ee2 commit a373078

37 files changed

Lines changed: 9060 additions & 8712 deletions

‎crates/buzz-db/src/lib.rs‎

Lines changed: 30 additions & 7510 deletions
Large diffs are not rendered by default.

‎crates/buzz-db/src/reaction.rs‎

Lines changed: 0 additions & 418 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ mod tests {
897897
assert!(migrations[32].sql.as_str().contains("kind = 30179"));
898898
assert!(migrations[32].sql.as_str().contains("search_tsv"));
899899
assert!(!migrations[0].sql.as_str().contains("30179"));
900-
assert!(include_str!("../../../schema/schema.sql")
900+
assert!(include_str!("../../../../schema/schema.sql")
901901
.contains("kind IN (1059, 30179, 30300, 30350, 30622, 44100, 44101, 44200)"));
902902

903903
// Public push-gateway authority is intentionally deployment-global and
@@ -1040,7 +1040,7 @@ mod tests {
10401040
.contains("CREATE INDEX relay_invites_expires_at_idx ON relay_invites (expires_at)"));
10411041
assert!(!relay_invites.contains("_operator_global_tables"));
10421042

1043-
let desired_schema = include_str!("../../../schema/schema.sql");
1043+
let desired_schema = include_str!("../../../../schema/schema.sql");
10441044
assert!(
10451045
desired_schema.contains("CREATE TABLE join_policy_acceptances"),
10461046
"desired-state schema must include join-policy evidence used by invite claims",
@@ -1156,7 +1156,7 @@ mod tests {
11561156
// parameters. Its post-apply reconciliation must restore and verify
11571157
// both parts of the live heartbeat contract for fresh bootstraps.
11581158
let pgschema_reconciliation =
1159-
include_str!("../../../scripts/reconcile-schema-after-pgschema.sql");
1159+
include_str!("../../../../scripts/reconcile-schema-after-pgschema.sql");
11601160
assert!(pgschema_reconciliation
11611161
.contains("ALTER TABLE replica_heartbeat SET (vacuum_truncate = false)"));
11621162
assert!(pgschema_reconciliation.contains("INSERT INTO replica_heartbeat (id) VALUES (1)"));
@@ -1309,7 +1309,7 @@ mod tests {
13091309
.sql
13101310
.as_str()
13111311
.contains("error_code"));
1312-
assert!(include_str!("../../../schema/schema.sql").contains("error_code TEXT"));
1312+
assert!(include_str!("../../../../schema/schema.sql").contains("error_code TEXT"));
13131313
}
13141314

13151315
#[test]
@@ -1480,7 +1480,7 @@ mod tests {
14801480
let migrator_run_to = ["MIGRATOR", ".run_to("].concat();
14811481

14821482
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
1483-
let this_file = manifest_dir.join("src/migration.rs");
1483+
let this_file = manifest_dir.join("src/runtime/migration.rs");
14841484
let crates_dir = manifest_dir.parent().expect("workspace crates dir");
14851485
// The push gateway migrates its own dedicated authority database; it
14861486
// never holds relay tenant tables, so it is exempt from the relay

‎crates/buzz-db/src/runtime/mod.rs‎

Lines changed: 1044 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

crates/buzz-db/src/replica_fence.rs renamed to crates/buzz-db/src/runtime/replica_fence.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
//! observes `token >= M` on its own connection has, by WAL/storage replay
2020
//! order, also replayed every commit that preceded M's commit; every
2121
//! transaction then partitions into exactly three buckets:
22-
//! (a) finished before the activity scan — its commit precedes `M`'s
23-
//! commit, so the replica session has replayed it;
24-
//! (b) open at the activity scan — represented by `xact_start`, so it is
25-
//! bounded by the `oldest_xact_start` term;
26-
//! (c) started after the activity scan — its deferred floor guard runs
27-
//! after `S`, so it cannot commit a row with
28-
//! `created_at < S - floor`.
22+
//! (a) finished before the activity scan — its commit precedes `M`'s
23+
//! commit, so the replica session has replayed it;
24+
//! (b) open at the activity scan — represented by `xact_start`, so it is
25+
//! bounded by the `oldest_xact_start` term;
26+
//! (c) started after the activity scan — its deferred floor guard runs
27+
//! after `S`, so it cannot commit a row with
28+
//! `created_at < S - floor`.
2929
//! There is no fourth bucket. Each committed token `M` therefore proves a
3030
//! **fence wall** of `min(oldest_xact_start, S) - floor - clock_margin`:
3131
//! every channel-window row with `created_at <= fence_wall(M)` is present

0 commit comments

Comments
 (0)