Repository navigation
chore(database): finish sqlc removal and Ent test migration - #1218
Conversation
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
93b30ab to
0875a49
Compare
398574b to
4394d44
Compare
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
0875a49 to
d0503b2
Compare
4394d44 to
e418c9c
Compare
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
d0503b2 to
a8527e0
Compare
e418c9c to
8684336
Compare
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
a8527e0 to
09d8642
Compare
8684336 to
ab3d67e
Compare
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
09d8642 to
c6697fa
Compare
ab3d67e to
3d1c72f
Compare
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
c6697fa to
86956f6
Compare
3d1c72f to
83cf39d
Compare
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
86956f6 to
d6fd28a
Compare
83cf39d to
8e432aa
Compare
§12: the final cleanup. All production code already runs through
*database.Client + Ent (see prior commits in this stack); this commit
deletes the rest of the sqlc surface and finishes converting test
fixtures that still spoke the legacy Querier API.
Deletions:
- pkg/database/generated_*.go (sqlc-multi-db generated wrappers)
- pkg/database/{sqlitedb,postgresdb,mysqldb}/ (per-engine adapters)
- pkg/database/contract_test.go and ent_schema_parity_test.go
(obsolete contract suite that compared sqlc vs Ent shapes)
- pkg/database/schema_parity_test.go (rolled into migrations/)
- pkg/database/backends_test.go
Code changes:
- database.Open now returns *Client directly (no Querier).
- pkg/analytics, pkg/cache, pkg/ncps, pkg/server: all test fixtures
drop the Querier parameter and rely on dbClient.Ent() + dbClient.DB()
for the raw SQL escape hatch.
- testhelper/{sqlite,postgres,mysql}.go: helpers take *database.Client
and use Ent fluent API.
- *Cache.db field and its New() parameter removed (production code
has not touched it for several commits already).
- pkg/ncps/serve.go: createDatabaseQuerier now returns just
*database.Client; renamed locally to the legacy name to keep the
stack diff small but the signature is single-return.
- cache_internal_test.go: the testStoreInDatabaseTransactionSafety
scenario already uses dbClient.WithTransaction + Ent OnConflict.
Test fixtures still use dbClient.DB() for raw SQL where the test is
specifically exercising the schema (e.g. UPDATE nar_files SET
chunking_started_at = ?), which is appropriate -- they aren't
exercising Ent code paths.
Full -race sweep against SQLite + Postgres + MySQL + MinIO + Redis is
green across all 29 packages.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
The parent commit deletes the sqlc-generated query.<dialect>.sql.go trees, shrinking the limited (ncps) fileset's vendor down to the ent-only set. But the golangci-lint-check check that overrides ncps with `src = ../../.` still sees `cmd/generate-migrations`, which transitively pulls in modernc.org/sqlite — a dep the shrunken limited fileset no longer needs. The two derivations end up wanting different vendorHashes for the same attribute. Bring `cmd/` into the ncps limited fileset so both derivations share the same vendor and the single vendorHash satisfies both. The exclude in #1220's source-list cleanup becomes a no-op for cmd/ but still removes db/migrations and db/schema cleanly.
sqlc.yml still existed, causing CI to regenerate the deleted per-engine adapters (sqlitedb/, postgresdb/, mysqldb/) and generated_*.go wrappers and auto-commit them back onto every PR that touched pkg/database/**. - Delete sqlc.yml (no longer needed post-Ent migration) - Remove "Generate Database Code" (sqlc generate) step from generate job - Remove "Generate Go Code" (go generate ./pkg/database) step — no //go:generate directives remain in pkg/database/ - Remove "Format Code" + auto-commit steps that were gated on database filter - Remove the now-unused database filter output from the filter job Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/cache/cache.go (1)
572-589:⚠️ Potential issue | 🟠 Major | ⚡ Quick winReject a nil
dbClientinNew.After removing the legacy
dbparameter, this constructor has no database fallback. Passingnilhere will still build aCacheand then fail later in initialization or callbacks instead of returning a normal constructor error.Suggested fix
var ( // ErrHostnameRequired is returned if the given hostName to New is not given. ErrHostnameRequired = errors.New("hostName is required") + ErrDBClientRequired = errors.New("dbClient is required") @@ func New( ctx context.Context, hostName string, dbClient *database.Client, @@ ) (*Cache, error) { + if dbClient == nil { + return nil, ErrDBClientRequired + } + c := &Cache{🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/cache/cache.go` around lines 572 - 589, The constructor New accepts a nil dbClient which later causes runtime failures; add an explicit nil-check at the start of New and return a clear error if dbClient == nil instead of constructing a Cache. Place the guard before allocating the Cache struct (referencing the New function and the Cache type and dbClient parameter) and return an appropriate error value (e.g., fmt.Errorf or errors.New) so callers fail fast.
🧹 Nitpick comments (1)
pkg/cache/cache_test.go (1)
3640-3643: ⚡ Quick winClose the
database.Clienthere.This test now creates a
*database.Client, so tearing down onlydbClient.DB()bypasses the client-level close path and can drift from the rest of the suite's cleanup behavior.Suggested fix
-defer dbClient.DB().Close() +defer dbClient.Close()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/cache/cache_test.go` around lines 3640 - 3643, The test currently defers only dbClient.DB().Close(), which bypasses the database.Client-level shutdown; change the teardown to call the client Close method instead by replacing the defer dbClient.DB().Close() with defer dbClient.Close() so the database.Client (dbClient) is closed properly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/cache/cache_prefetch_test.go`:
- Around line 180-191: Replace the hard-coded NarFile ID used in the chunk query
(entnarfilechunk.NarFileIDEQ(1)) by first resolving the corresponding nar_files
row via the NarFile query (use dbClient.Ent().NarFile.Query().Where(...) with
the nar hash, compression and query values), require the returned nar file
exists, then use that nar file's ID when loading chunks with
dbClient.Ent().NarFileChunk.Query(); also assert that at least two chunks are
returned before deleting the second chunk so the test reliably exercises the
missing-chunk path.
- Around line 63-65: Replace the unsafe testing.T usage in
BenchmarkStreamCompleteChunks_WithPrefetch by changing setupSQLiteFactory to
accept testing.TB (or add a benchmark-specific helper) and pass b into
setupSQLiteFactory so Helper/failure/cleanup semantics work correctly instead of
constructing t := &testing.T{}; and in TestPrefetchErrorPropagation stop
assuming NarFile ID 1 — after creating the nar file for nu, query the nar_files
table (by its hash/compression or other unique fields) to obtain the actual ID
and use that value in the entnarfilechunk.NarFileIDEQ(...) filter rather than
hardcoding 1.
In `@pkg/cache/cdc_test.go`:
- Around line 247-253: The two db count operations currently ignore errors
(count1, _ := dbClient.Ent().Chunk.Query().Count(ctx) and count2, _ :=
dbClient.Ent().Chunk.Query().Count(ctx)), which can mask DB failures; replace
the ignored errors by checking them with require.NoError so the test fails
immediately on DB issues (e.g., assign the error returned from
Chunk.Query().Count(ctx) to a variable and call require.NoError(t, err) after
each call before using count1/count2).
In `@testhelper/sqlite.go`:
- Around line 113-123: The test currently passes the optional ni.FileSize into
getOrCreateNarFile which causes zero-size nar_files rows when Compression is
none; instead derive the effective size from the parsed nar URL and pass that to
getOrCreateNarFile (use the parsed narURL's size field, e.g. narURL.NarSize or
equivalent) after calling nar.ParseURL, so replace the ni.FileSize argument with
the parsed URL's effective size when calling getOrCreateNarFile.
---
Outside diff comments:
In `@pkg/cache/cache.go`:
- Around line 572-589: The constructor New accepts a nil dbClient which later
causes runtime failures; add an explicit nil-check at the start of New and
return a clear error if dbClient == nil instead of constructing a Cache. Place
the guard before allocating the Cache struct (referencing the New function and
the Cache type and dbClient parameter) and return an appropriate error value
(e.g., fmt.Errorf or errors.New) so callers fail fast.
---
Nitpick comments:
In `@pkg/cache/cache_test.go`:
- Around line 3640-3643: The test currently defers only dbClient.DB().Close(),
which bypasses the database.Client-level shutdown; change the teardown to call
the client Close method instead by replacing the defer dbClient.DB().Close()
with defer dbClient.Close() so the database.Client (dbClient) is closed
properly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5a084d34-d5a9-4ea2-ad94-cd1dfcb56f17
📒 Files selected for processing (39)
nix/packages/ncps/default.nixpkg/cache/cache.gopkg/cache/cache_distributed_test.gopkg/cache/cache_internal_test.gopkg/cache/cache_prefetch_test.gopkg/cache/cache_test.gopkg/cache/cdc_test.gopkg/cache/healthcheck/healthcheck_test.gopkg/cache/upload_only_test.gopkg/config/config_test.gopkg/database/backends_test.gopkg/database/contract_test.gopkg/database/database.gopkg/database/ent_errors.gopkg/database/ent_schema_parity_test.gopkg/database/errors.gopkg/database/generated_errors.gopkg/database/generated_models.gopkg/database/generated_querier.gopkg/database/generated_wrapper_mysql.gopkg/database/generated_wrapper_postgres.gopkg/database/generated_wrapper_sqlite.gopkg/database/mysqldb/adapter.gopkg/database/postgresdb/adapter.gopkg/database/schema_parity_test.gopkg/database/sqlitedb/adapter.gopkg/ncps/fsck.gopkg/ncps/fsck_test.gopkg/ncps/migrate_nar_to_chunks.gopkg/ncps/migrate_nar_to_chunks_test.gopkg/ncps/migrate_narinfo.gopkg/ncps/migrate_narinfo_test.gopkg/ncps/serve.gopkg/server/security_test.gopkg/server/server_internal_test.gopkg/server/server_test.gotesthelper/mysql.gotesthelper/postgres.gotesthelper/sqlite.go
💤 Files with no reviewable changes (13)
- pkg/database/sqlitedb/adapter.go
- pkg/database/ent_schema_parity_test.go
- pkg/database/generated_errors.go
- pkg/database/mysqldb/adapter.go
- pkg/database/schema_parity_test.go
- pkg/database/postgresdb/adapter.go
- pkg/database/generated_querier.go
- pkg/database/contract_test.go
- pkg/database/backends_test.go
- pkg/database/generated_wrapper_sqlite.go
- pkg/database/generated_wrapper_postgres.go
- pkg/database/generated_wrapper_mysql.go
- pkg/database/generated_models.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1218 +/- ##
========================================
- Coverage 5.68% 5.50% -0.19%
========================================
Files 6 6
Lines 387 400 +13
========================================
Hits 22 22
- Misses 361 374 +13
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
§12: the final cleanup. All production code already runs through
*database.Client + Ent (see prior commits in this stack); this commit
deletes the rest of the sqlc surface and finishes converting test
fixtures that still spoke the legacy Querier API.
Deletions:
(obsolete contract suite that compared sqlc vs Ent shapes)
Code changes:
drop the Querier parameter and rely on dbClient.Ent() + dbClient.DB()
for the raw SQL escape hatch.
and use Ent fluent API.
has not touched it for several commits already).
*database.Client; renamed locally to the legacy name to keep the
stack diff small but the signature is single-return.
scenario already uses dbClient.WithTransaction + Ent OnConflict.
Test fixtures still use dbClient.DB() for raw SQL where the test is
specifically exercising the schema (e.g. UPDATE nar_files SET
chunking_started_at = ?), which is appropriate -- they aren't
exercising Ent code paths.
Full -race sweep against SQLite + Postgres + MySQL + MinIO + Redis is
green across all 29 packages.
Co-Authored-By: Claude Opus 4.7 [email protected]