refactor(server): move the catalog's SQL into repositories - #45
Merged
Merged
Conversation
The models, routes, providers and platform-pricing handlers no longer
carry SQL: services::{model,provider,pricing}_repository hold every
statement, verbatim, one function per statement or transaction. The
handlers keep validation, audit and the router / cache refresh. The row
types those queries return (ModelRow, ModelIdRow, ModelRouteRow,
PlatformPricing) move with them.
No behaviour change. admin_catalog.rs pins the endpoints that had no
integration test (route PATCH/delete, the flat route listing, batch
weights and toggles, bulk model operations, the unrouted cleanup,
provider edit and delete, pricing); it passes against both the old and
the new code.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of the per-domain PRs that take SQL out of
crates/server/src/handlers(238 directsqlx::querycalls across ~30 handler files). This one covers the catalog:models.rs(32),providers.rs(10),platform_pricing.rs(2).What moved
services::model_repository—modelsandmodel_routes: paging/filtering, insert/update/delete, bulk toggles and deletes, route CRUD, the flat route listing, the batch import (its transaction now lives here), batch weights (same), and the route's log identity for the history sparkline.services::provider_repository— live-provider lookups, insert/update, clearing learned protocols, and the soft delete + route drop transaction.services::pricing_repository— theplatform_pricingsingleton.ModelRow,ModelIdRow,ModelRouteRow,PlatformPricing) move with them;openapi.rsimportsModelRowfrom there.Every statement is carried over verbatim. Handlers keep permission checks, validation, audit, and the router / weight-cache / cost-tracker refresh. This follows the convention
services/mod.rsalready lays down (handlers call repositories;user_repositorywas the first).No behaviour change — checked
admin_catalog.rsadds integration tests for the endpoints no test reached: route create (duplicate / unknown model / unknown provider), PATCH with clear-vs-absent semantics and cap validation, delete, the flat listing unfiltered and filtered, batch weights, batch enable toggle, batch delete, list status filters (active / disabled / unrouted), model ids, bulk set-enabled (only changed rows count), bulk delete, single delete, unrouted cleanup, provider get/list/rename/base-URL change (learned protocols cleared) / delete (routes dropped), pricing get/patch/validation. They pass against the code before this change and after it.Incremental build: measured, no crate split
The plan considered splitting the biggest handler groups into their own crates. Measured on this machine (4 cargo jobs, other builds running; median of 3, after warm-up),
cargo build -p think-watch-serverafter editing one string literal:handlers/models.rshandlers/admin/users.rsmain.rs(binary only — the link floor)cargo check -p think-watch-serverafter the same edits: 2.0–2.1 s for the whole 37k-line crate. The rebuild is dominated by linking the binary, which a crate split does not shorten; the most a split could save is the ~1 s of the server crate's own incremental codegen, while every integration-test binary still links everything. Not worth a crate boundary, so the restructuring stays inside the crate.Checks
fmt, clippy (
--all-targets,--lib), 679 unit tests, full integration suite on own containers (273 passed).🤖 Generated with Claude Code