summaryrefslogtreecommitdiffstats
path: root/src/db/mod.rs
diff options
context:
space:
mode:
authordev <dev@localhost>2026-11-20 17:13:44 +0000
committerdev <dev@localhost>2026-11-20 17:13:44 +0000
commit8cd32e5309b14f5264813e5f2ce6ecdb5aa41fb4 (patch)
tree2ce6c30a688ef3fb15af5639e22cfc230f8f3627 /src/db/mod.rs
parentb73bb60403c3f2e7fc55d5038831912e8371e3a6 (diff)
downloadaur-build-8cd32e5309b14f5264813e5f2ce6ecdb5aa41fb4.tar.gz
aur-build-8cd32e5309b14f5264813e5f2ce6ecdb5aa41fb4.zip
db: one module per aggregate, and an interface you can read
queries.rs was 1,501 lines holding 83 queries across seventeen aggregates, separated by comment banners that said "settings", "release", "notices" and then kept them in one file. The banners were the design; they just never got files. Each one has one now, verbatim — the split is provably content-only, the moved text being identical to the original as a sorted set of lines. model.rs and builds.rs were each two concerns deep, so they became directories. model.rs held what a row looks like and, separately, the state machines that say which moves are legal; builds.rs held the build machine and, below its own `step rows` banner, the step machine. The impl_state_enum! macro implements StateEnum for all five enums from one place, so it moved with its invocations rather than being exported across a boundary to chase them. They are directories rather than new sibling modules on purpose: `db::model::CandidateState` and `db::builds::steps` are used across the crate and by the integration tests, and renaming them would be a bigger change than the one being made. No call site and no test changed. db/mod.rs now lists its interface instead of spraying one. `pub use model::*` and `pub use queries::*` are gone, replaced by seventeen explicit exports, and the query modules are private — so a query that was not chosen for export is not reachable, and the width of the module is visible from its own text rather than only from a grep. The ratchet caught the win immediately: db.glob went 2 -> 0, which failed a_shrunk_interface_is_written_back until the budget was written back at the new value. db is off the glob allowlist now rather than holding a stale zero. 277 passed / 0 failed, clippy -D warnings clean, largest file in src/db 363 lines (candidates.rs, unchanged from before this work).
Diffstat (limited to 'src/db/mod.rs')
-rw-r--r--src/db/mod.rs72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 95833be..d4befcc 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -3,10 +3,77 @@ pub mod builds;
pub mod candidates;
pub mod migrations;
pub mod model;
-pub mod queries;
+
+// The queries this module owns, one module per aggregate. They are private:
+// the interface is what `pub use` names below, not the file layout, so a
+// caller cannot reach a query that was not chosen for export.
+mod audit;
+mod invariants;
+mod metrics;
+mod notices;
+mod packages;
+mod pkgbases;
+mod publish_writes;
+mod releases;
+mod repos;
+mod retention;
+mod settings;
+mod snapshots;
+mod stage_b;
+mod staleness;
+mod subscriptions;
+mod world;
pub use migrations::MIGRATIONS;
-pub use model::*;
+
+pub use model::{
+ BUILD_STEPS, BuildState, CandidateRow, CandidateState, Identity, Recipe, ReleaseRow,
+ ReleaseState, SourceDigest, SourceEntry, StageBCacheRow, StateEnum, StepState,
+ SubscriptionState, UpstreamPin, WorldMember, candidate_kind, json_or, notice_kind,
+};
+pub use audit::{AuditEntry, AuditRow, audit, audit_in, audit_system, list_audit};
+pub use invariants::{Unbuilt, approved_but_unbuilt, index_pkgbase_drift, unapproved_index_entries};
+pub use metrics::{
+ artifact_bytes_served, build_state_counts, count_index_packages, count_pending_reviews,
+ count_published_releases, count_subscriptions, count_unacknowledged_notices,
+ last_gc_age_secs, last_poll_age_secs, oldest_queued_age_secs, pending_review_ages_secs,
+};
+pub use notices::{NoticeRow, acknowledge_notice, list_notices, put_notice, put_notice_once};
+pub use packages::{
+ PackageRow, accepted_recipe, builds_for_pkgbase, index_artifact, index_packages,
+ index_version, is_ours, our_package_names,
+};
+pub use pkgbases::{
+ Pkgbase, cas_accepted_release, get_pkgbase, get_pkgbase_by_id, list_pkgbases, set_aur_head,
+ set_unpinable,
+};
+pub use publish_writes::{
+ NewRelease, accepted_pointer_in, artifact_id_by_digest_in, artifact_path,
+ cas_accepted_release_in, insert_package_in, insert_release_in, remove_index_packages_in,
+ remove_package_by_name_in,
+};
+pub use releases::{
+ accepted_release, all_published_releases, release_by_id, releases_for_pkgbase,
+ withdraw_release_in,
+};
+pub use repos::{ensure_repo, repo_id};
+pub use retention::{
+ ArtifactPaths, mark_release_purged, pkgbase_release_pointers, published_release_ids,
+ record_gc_run, release_artifact_paths, serving_release_ids,
+};
+pub use settings::{all_settings, set_setting, setting, setting_i64};
+pub use snapshots::{SnapshotRow, put_snapshot, snapshot_by_commit, snapshot_by_id};
+pub use stage_b::{stage_b_cache_get, stage_b_cache_put, stage_b_recent};
+pub use staleness::{
+ NewArtifact, approval_note, candidate_snapshot_id, index_recipes, insert_artifact_in,
+ published_world_members, put_source_cache, served_vs_offered_pkgvers, source_cache_path,
+ subscription_poll_interval,
+};
+pub use subscriptions::{
+ Subscription, due_subscriptions, get_subscription, list_subscriptions, note_check,
+ set_subscription_state, subscribe,
+};
+pub use world::{put_world_snapshot, world_members};
pub(crate) fn state_col<T: StateEnum>(col: usize, text: &str) -> rusqlite::Result<T> {
T::parse(text).ok_or_else(|| {
@@ -21,7 +88,6 @@ pub(crate) fn state_col<T: StateEnum>(col: usize, text: &str) -> rusqlite::Resul
})
}
-pub use queries::*;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};