feat(store): migrate messages + topics + delivery to sqlc (T4) - #795
Open
rigel-mintaka wants to merge 2 commits into
Open
feat(store): migrate messages + topics + delivery to sqlc (T4)#795rigel-mintaka wants to merge 2 commits into
rigel-mintaka wants to merge 2 commits into
Conversation
Migrate the channels, channel_pins, and coordination store domains from
inline pgx SQL to sqlc-generated typed queries (RIG-3034, design record
sqlc-adoption T3), following the T2 recipe exactly. Pool-scoped calls go
through s.q; tx-scoped through s.q.WithTx(tx) / db.New(tx). Every migrated
statement is semantically identical to the inline SQL it replaced (same
columns, WHERE, JOINs, ORDER BY, null-handling); the CTE-based channel and
group visibility reads move into queries/channels.sql with their predicates
inlined per query (sqlc has no fragment composition), textually identical so
the stream-edge single-id checks cannot drift from the list reads.
The DELETE-and-check-rows-affected member removal uses the :execrows kind so
removeMember/SetCoordinationMembersTx keep their RowsAffected semantics. The
coordination per-owner advisory lock pg_advisory_xact_lock(hashtext('coordination:' || $1))
is now a tx-bound LockOwnerCoordination call inside its transaction; the
suffix-search channel-provision loop, the WithTx seam, error wrapping,
domain-type mapping, and the FOR UPDATE lock / cap-check control flow all
stay hand-written. Regenerated internal/store/db (drift-clean) and dropped
the three migrated inline-sql-gate allowlist entries (24 -> 21).
Co-authored-by: Matt Wilkinson <matt@rigel.build>
|
Compass engineering docs preview: https://compass-repo-rig-3034-sqlc-t-qu7x.compass-eng-docs.pages.dev Deployed from |
Migrate the message, topic, and delivery-consumer store domains from inline pgx SQL to sqlc-generated queries (RIG-3034 T4, design record §T4). The hand-written Store methods keep their exact exported signatures and wrap the generated calls; error wrapping, domain-type mapping, tx orchestration, the D9 not-found/forbidden merge, and the D2 seed self-guard all stay hand-written. Files migrated (queries/*.sql compiled into internal/store/db/): - messages.go (16 sites): post-policy read, insert (:one, ON CONFLICT dedup signalled via errMessageInsertConflict), topic get-or-create, list/search (:many), ask-containment find (FOR UPDATE), authored update (:one RETURNING), block update (:execrows), dedup read. - topics.go (9 sites): list, resolve-for-update, rename/merge resolution loop, archive, get. - delivery_cursors.go (15 sites): seed (per-agent + per-channel), owed-mention record/read/clear (:execrows)/count, mention-routed mark + recovery scan, AckDelivery resolve/load(FOR UPDATE)/self-authored/advance, undelivered sweep, in-sweep-set. - delivery_reads.go (7 sites): subscribed agents, channel agent members, is-agent, message-by-id, message-channel, topic/channel names, sweep channels. - presence_reads.go (2 sites): open-ask JSONB path probe, shared-channel EXISTS. Const-hoisted, never in the gate allowlist — no entry to remove. Each migrated statement is semantically identical to the inline SQL it replaces; RowsAffected-branching sites use :execrows. scanMessages/scanTopics/ scanMessagesByChannel and the now-dead execer interface are removed in favor of generated-row mappers (messageFromParts, topicFromRow); the fail-loud decode error on a malformed block set is preserved. inline-sql-gate allowlist: 21 -> 17 (drop messages.go, topics.go, delivery_cursors.go, delivery_reads.go). Verified: go build ./... clean; go test ./internal/store/ ok; full pgtest lane (podman postgres:16) ok; golangci-lint 0 issues; sqlc generate drift-clean; GATE_ROOT=. bun tools/inline-sql-gate/index.ts exits 0 (allowlist 17). Co-authored-by: Matt Wilkinson <matt@rigel.build>
rigel-mintaka
force-pushed
the
compass-repo/rig-3034-sqlc-t4-messages
branch
from
August 31, 2026 16:52
e49ae3f to
8c39f8b
Compare
Base automatically changed from
compass-repo/rig-3034-sqlc-t3-channels
to
main
August 31, 2026 17:25
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.
Migrate the message, topic, and delivery-consumer store domains from inline
pgx SQL to sqlc-generated queries (RIG-3034 T4, design record §T4). The
hand-written Store methods keep their exact exported signatures and wrap the
generated calls; error wrapping, domain-type mapping, tx orchestration, the
D9 not-found/forbidden merge, and the D2 seed self-guard all stay
hand-written.
Files migrated (queries/*.sql compiled into internal/store/db/):
signalled via errMessageInsertConflict), topic get-or-create, list/search
(:many), ask-containment find (FOR UPDATE), authored update (:one RETURNING),
block update (:execrows), dedup read.
archive, get.
record/read/clear (:execrows)/count, mention-routed mark + recovery scan,
AckDelivery resolve/load(FOR UPDATE)/self-authored/advance, undelivered
sweep, in-sweep-set.
is-agent, message-by-id, message-channel, topic/channel names, sweep
channels.
EXISTS. Const-hoisted, never in the gate allowlist — no entry to remove.
Each migrated statement is semantically identical to the inline SQL it
replaces; RowsAffected-branching sites use :execrows. scanMessages/scanTopics/
scanMessagesByChannel and the now-dead execer interface are removed in favor of
generated-row mappers (messageFromParts, topicFromRow); the fail-loud decode
error on a malformed block set is preserved.
inline-sql-gate allowlist: 21 -> 17 (drop messages.go, topics.go,
delivery_cursors.go, delivery_reads.go).
Verified: go build ./... clean; go test ./internal/store/ ok; full pgtest lane
(podman postgres:16) ok; golangci-lint 0 issues; sqlc generate drift-clean;
GATE_ROOT=. bun tools/inline-sql-gate/index.ts exits 0 (allowlist 17).
Co-authored-by: Matt Wilkinson matt@rigel.build