Database governance built for humans and agents — controlling changes and access across every major database.
QueryHistoryService Extraction Design
Date: 2026-07-29 Status: Approved (amended: keep SQLService aliases as deprecated proxies) Ships in: 3.21 (current release 3.20.1); legacy alias removal in a future release, date TBD
Summary
Extract SearchQueryHistories, ListQueryHistories, and GetQueryHistory
from SQLService into a new standalone QueryHistoryService, following the
per-resource service pattern (ChangelogService and RevisionService are the
structural analogs). Unlike the ChangelogService extraction's clean cut, the
old bytebase.v1.SQLService methods are kept as deprecated delegating
proxies for a safe upgrade transition, and removed in a future release
(date TBD).
Rationale for diverging from the changelog decision: the query history RPCs
are called continuously by the SQL Editor over the Connect protocol
(/bytebase.v1.SQLService/SearchQueryHistories etc.). During a rolling
upgrade, browsers holding a cached pre-3.21 frontend bundle keep issuing the
old method names against a new backend; without aliases the History pane
breaks until a hard refresh. Changelogs had no such hot browser-side caller.
After the move, SQLService's non-deprecated surface holds only execution
and utility RPCs: Query, AdminExecute, Export, DiffMetadata,
AICompletion.
Goals
QueryHistoryServiceowns the query history resource (projects/{project}/queryHistories/{id}) and serves the REST routes.- Zero behavior change: same permissions, same REST paths, same wire format, same pagination semantics, same caller-scoping and existence-hiding errors — on both the new methods and the deprecated aliases.
Non-goals
- No store-layer changes (
backend/store/query_history.gountouched). - The write path stays where it is:
createQueryHistoryis an internal store write invoked byQuery/AdminExecute/ExportinsideSQLService, not an RPC.QueryHistoryServiceis read-only, likeChangelogService(whose rows are written by task runs). - No new RPCs, no permission changes (
bb.queryHistories.liststays), no resource-name changes, no newgoogle.api.resourceannotation for QueryHistory (it has none today). - No commitment to a specific alias-removal release in this design; removal is a future labeled-breaking change, date TBD.
Background
SQLServicemixes two concerns: SQL execution (Query/AdminExecute/Export plus utilities) and the query history child resource of Project. The history RPCs are the only project-parented resource CRUD in the service.- The six messages to move (
SearchQueryHistoriesRequest/Response,ListQueryHistoriesRequest/Response,GetQueryHistoryRequest,QueryHistorywith itsTypeenum) are referenced by no other proto file. Package staysbytebase.v1, so fully-qualified names and binary/JSON wire format are unchanged. The alias RPCs reference the moved messages viaimport "v1/query_history_service.proto"— same types, so alias and new method are wire-identical. - Authorization is annotation-driven:
backend/api/auth/auth.goresolves the method descriptor from the invoked full method name viaprotoregistry.GlobalFilesand reads the extensions. The aliases keep theirbytebase.v1.permission/auth_methodannotations, so both paths enforce identical auth —ListQueryHistories(IAM,bb.queryHistories.list) and the two CUSTOM caller-scoped RPCs — with no auth code changes. - Recent hardening carries over verbatim on both paths: SearchQueryHistories rejects the AIP-159 wildcard parent (#21064); ListQueryHistories supports "projects/-" gated on workspace-level permission.
buf.yamllints with the BASIC category;RPC_REQUEST_RESPONSE_UNIQUE(DEFAULT category) is not enforced, so the alias RPCs may share request/response types with the new service.
Design
1. Proto
New proto/v1/v1/query_history_service.proto, modeled on
changelog_service.proto: QueryHistoryService with the three RPCs — HTTP
bindings under /v1/{parent=projects/*}/queryHistories, method_signature,
bytebase.v1.permission, and auth_method annotations carried over
unchanged — plus the six messages moved verbatim (field numbers, comments,
resource references unchanged).
sql_service.proto keeps the three RPCs as aliases with:
option deprecated = true;and a comment pointing atQueryHistoryServiceand the TBD removal;- no
google.api.httpbindings — the REST routes are served solely byQueryHistoryService's gateway registration, so the gateway mux never sees duplicate paths and the OpenAPI spec lists each REST operation once (operationIds becomeQueryHistoryService_*); method_signaturedropped with the bindings (thegoogle/api/client.protoimport had no other users in this file);bytebase.v1.permission/auth_methodannotations kept identical.
The six message definitions leave sql_service.proto; it imports
v1/query_history_service.proto for the alias signatures.
2. Backend
backend/api/v1/query_history_service.go:QueryHistoryServicestruct (embedsv1connect.UnimplementedQueryHistoryServiceHandler, holdsstore— the only dependency the moved code uses),NewQueryHistoryService(store). Moves wholesale fromsql_service.go:SearchQueryHistories,ListQueryHistories,GetQueryHistory,paginatedQueryHistories,resolveQueryHistoryParent, plusconvertToV1QueryHistoryfromsql_service_converter.go(stays a method — it needs the store for the creator lookup).createQueryHistorystays insql_service.go.SQLServicegains aqueryHistoryService *QueryHistoryServicefield (constructed first, injected viaNewSQLService) and keeps three one-line deprecated methods that delegate:func (s *SQLService) SearchQueryHistories(ctx, req) { return s.queryHistoryService.SearchQueryHistories(ctx, req) }— identical semantics by construction, no duplicated logic.- Registration in
backend/server/grpc_routes.gomirrorsChangelogService, four touchpoints: construct, Connect handler →connectHandlers, static reflector list, andv1pb.RegisterQueryHistoryServiceHandlerfor the gateway (sole server of the REST routes). The SQLService Connect handler continues to serve the alias method paths.
3. Frontend
queryHistoryServiceClientConnectadded infrontend/src/api/index.ts; the 3.21 bundle uses only the new service (aliases exist for older cached bundles, not for new code).- Call sites repointed:
modules/sql-editor/store/queryHistory.ts(search + get) andcomponents/WorkspaceSetupGuide.tsx(search). - Type imports repointed from
proto-es/v1/sql_service_pbtoproto-es/v1/query_history_service_pbacrossutils/v1/queryHistory.ts, the sql-editor store types/HistoryPane, and their tests.
4. Generated artifacts, MCP, and docs
buf generateregeneratesbackend/generated-go,frontend/src/types/proto-es,proto/gen/grpc-doc, andbackend/api/mcp/gen/openapi.yaml. The deprecated aliases carrydeprecated: truein generated specs;generate_openapi_index.jsalready skips deprecated operations generically (built for exactly this case during the changelog work), so agents only seeQueryHistoryService.- The agent
serviceDirectoryinfrontend/src/modules/agent/logic/prompt.tsgains a QueryHistoryService entry. - Resource-pattern table in
docs/plans/saas/07.api-resource-patterns.mdupdated: query histories move out of the "SQLService workspace-level utility" bucket (stale since #21064 anyway) into their own project-parented service entry.
Compatibility (3.21)
| Surface | Impact |
|---|---|
REST POST /v1/projects/*/queryHistories:search, GET .../queryHistories[/*] |
None — identical paths, payloads, auth; served by QueryHistoryService's gateway registration |
gRPC/Connect bytebase.v1.SQLService/SearchQueryHistories, ListQueryHistories, GetQueryHistory |
Kept — deprecated delegating proxies, wire-identical behavior; removal in a future release, date TBD |
| Cached pre-3.21 frontend bundles during rolling upgrade | Keep working via the aliases (the motivating case) |
| Terraform provider, bytebase-action | Unaffected (REST-only / no query history usage) |
IAM (bb.queryHistories.list), caller-scoping, resource names, page tokens |
Unchanged |
| Published OpenAPI operationIds | SQLService_* → QueryHistoryService_* for the REST operations — SDK regen concern only; paths unchanged |
| Audit log | No change — none of the three RPCs carry audit = true |
Not a breaking release: nothing is removed in 3.21. buf breaking (FILE
rules) still flags the message moves between files and the dropped HTTP
options on the aliases; no CI job enforces it, and the wire surface is
compatible. The breaking label belongs to the future alias-removal release.
Rollout
- 3.21: ship extraction + aliases; release notes announce the
deprecation and point gRPC/Connect callers at
bytebase.v1.QueryHistoryService(REST users need no changes). - Future release (TBD): remove the aliases with
--label breaking, mirroring the ChangelogService removal notes.
Testing
- E2E:
backend/tests/query_history_test.gomigrates to a newqueryHistoryServiceClientwired intests.go; it already covers all three RPCs, IAM gating, wildcard-parent behavior, and existence hiding. Added alias assertions pin the delegation: the deprecatedsqlServiceClient.SearchQueryHistories/GetQueryHistory/ListQueryHistoriesreturn the same results as the new client until the aliases are removed. - Frontend: sql-editor store tests mock the new client; full suite green.
- Standard gates:
buf format/lint,golangci-lint,go build, targeted e2e,pnpm fix/check/type-check/test.
Alternatives considered
- Clean cut, no aliases (the ChangelogService choice) — rejected here: unlike changelogs, query history has a hot browser-side Connect caller (the SQL Editor History pane), so removal without a transition window breaks cached bundles mid-upgrade. Decision 2026-07-29 (Danny).
- Aliases with duplicated HTTP bindings on both services — rejected: duplicate gateway routes make the serving handler registration-order dependent and double every REST operation in generated specs.
- Runtime route rewrite instead of proto aliases — rejected for the same reasons as in the changelog design: per-protocol plumbing, invisible in generated docs/SDKs, more code than the thing it replaces.
- Deprecated delegating proxies, REST on the new service only (chosen) — smallest transition shim, wire-identical by construction, visible as deprecated in every generated artifact, and removable in one future PR.