Skip to content

Adopt sqlc for static-query repositories after the 1.0 schema baseline #906

Open

Description

@Quick104

Proposal

Adopt sqlc for the static-query repositories after the 1.0 schema baseline lands (schema workstream #888, Phase 6 of the API v2 program #135). Raised by a senior reviewer while the v2/Huma work was starting: the schema hygiene PRs already touch the table definitions, indexes, and column types sqlc would generate against, so the question was whether to fold the data-layer migration into the same program.

Decision for now: out of the API v2 program, sequenced behind it. Rationale below so the sequencing is not relitigated later.

What sqlc would touch (today's tree)

Count
Non-test Go files using pgx 235
Repository / store types 316
Raw SQL string literals (SELECT/INSERT/UPDATE/DELETE/WITH) 872
Files building SQL dynamically (Sprintf/strings.Builder), by package internal/catalog 30, notifications 8, scanner 5, metadata 5, jellycompat 5, api/handlers 5, userstore/pgstore 4, userdb 3, sections 3, opslog 3

Driver: github.com/jackc/pgx/v5, which sqlc supports natively (sql_package: pgx/v5).

sqlc generates typed Go from static SQL. The dynamically composed queries (catalog search and filters, section fetchers, settings resolution, jellycompat browse) stay hand-written or need a builder beside sqlc; they are explicitly out of scope for the first pass.

Why after the baseline, not inside the v2 program

Scope when it starts

  1. Pin sqlc (exact version) and add sqlc.yaml reading the 1.0 baseline migration (or sqlc vet against a migrated scratch database); generate into per-domain packages that mirror the existing repository ownership.
  2. Convert repositories package by package, static queries only; one package per PR; each PR runs the tier-1 scenario catalogs (make verify-scenario-catalogs plus the DB-gated executor) as its regression gate.
  3. CI: sqlc diff (or generate-and-byte-compare, matching the route-inventory / OpenAPI gate pattern) so generated code cannot drift from the queries.
  4. Leave the dynamic-query packages listed above on hand-written pgx unless a builder is adopted separately; record that boundary in docs/architecture/.

Dependencies

Related issue: #135 (program), #888 (schema workstream).

AI disclosure: drafted by Claude Code (claude-fable-5) orchestrating the #135 program, from a maintainer instruction; figures are grep counts over the current tree and are approximate.

Activity

  1. added
    schema-1.0
    on Sep 2, 2026
  2. added
    triaged
    and removed
    triaged
    on Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    schema-1.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions