Repository navigation
feat: add forkdb for fork-only queries and the chat_subagents node - #25
Conversation
Add package forkdb, which runs fork-only queries generated by sqlc on the connection or transaction of a database.Store and behind the dbauthz, dbmetrics and dbcrypt wrappers. Add the first fork node, chat_subagents, with one query, since sqlc refuses to generate with zero queries. Add a fork-ci job that fails when forkdb generation drifts.
… in the chat_subagents node
InTx had no test on this branch: PR #2's TestInTx needs plugin queries. TestInTx checks that the fork queries run in the transaction of the upstream queries and roll back with it.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99317f60ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Part of #5
Adds
coderd/database/forkdb, the package for fork-only sqlc queries, so fork features can add tables and queries without touchingdump.sql,queries.sql.go,querier.goordbmock. The package, file names and APIs match draft PR #2, minus every plugin table, query, scope and route.sqlc will not generate a package with zero queries, so this PR also adds the first fork table and one read query:
01a1bd31-6117-7cbd-bb14-1a8ca7a596b3_chat_subagentscreateschat_subagents(one row per tracked subagent chat; DDL from the plan, shared.1).GetChatSubagentByChatIDreads it. dbauthz authorizes it through the owning chat (ActionReadon the chat); dbmetrics times it; dbcrypt passes it through.forkdb.From(db)unwraps the dbauthz, dbmetrics and dbcrypt wrappers to the raw store and wraps the fork querier back in the same order.forkdb.InTxruns fork and upstream queries in one transaction through the newForkDBTXaccessor.CI: a new
forkdbjob infork-cifails whengenerate.shoutput drifts from the committed code, andchat-testsnow also runs./enterprise/dbcrypt/....No user-visible behavior changes: nothing calls the new query yet.
Size: 822 added lines, about 666 hand-written
Generated:
chat_subagents.sql.go,db.go,models.go,querier.go,forkdbmock/forkdbmock.go(156 lines). Of the rest, about 334 lines are tests. The wrappers,Fromand the tests that prove each wrapper unwraps only work together, so this stays one PR.Validation
go build,go veton the touched packages.chatdmig checklistschat_subagentsafter the adopt node;chatdmigtests pass on Postgres.generate.shtwice: no drift.git diff origin/main -- coderd/database/dump.sql coderd/database/queries.sql.go coderd/database/querier.go coderd/database/dbmockis empty.go test ./coderd/database/ ./coderd/database/forkdb/... ./coderd/database/dbauthz/ ./coderd/database/dbmetrics/ ./enterprise/dbcrypt/on Postgres 17. Each new test fails when the behavior it covers is broken.maindatabase): PASS onc4802d3262. The node applies once on upgrade, restarts apply nothing, user rows are unchanged, the table constraints behave as written, and/agentsrenders the same as on forkmain. Later commits change tests only.