Skip to content

Conversation

@jakubno
Copy link
Member

@jakubno jakubno commented Nov 21, 2025

Note

Replaces Ent ORM with a new sqlc-based data layer and typed models, adds SQL query files and DB client, updates API/handlers and tests accordingly, and removes legacy generated code.

  • Migrate to sqlc-based data layer:
    • Replace Ent/entgo generated model code (packages/shared/pkg/models/*, migrate, predicate, runtime, etc.) with SQLC-backed queries and typed models.
    • Introduce packages/db/queries/* (e.g., create_template.sql, create_alias.sql, get_snapshot_builds.sql) and packages/db/types for typed enums/structs.
    • Add packages/shared/pkg/db/client.go and related DB error handling.
  • Update application code to new DB layer:
    • Modify API handlers (packages/api/internal/*) to use the new DB client/types.
    • Adjust integration tests (packages/db/tests/*, packages/api tests) and switch enum references (e.g., envbuild.Status*dbtypes.BuildStatus*).
  • Housekeeping:
    • Update go.mod/go.sum and Makefile for new dependencies.
    • Remove legacy Ent-generated files (envbuild_*, snapshot_*, team_*, user_*, predicate, runtime, etc.).

Written by Cursor Bugbot for commit e154e2c. This will update automatically on new commits. Configure here.

@linear
Copy link

linear bot commented Nov 21, 2025

ENG-2327 Migrate to sqlc

@jakubno jakubno changed the title Rewrite the rest queries to SQLC Rewrite the rest of queries to SQLC Nov 21, 2025
@jakubno jakubno force-pushed the migrate-to-sqlc-eng-2327 branch from 76fb851 to bf15979 Compare November 21, 2025 12:21
@chatgpt-codex-connector
Copy link

💡 Codex Review

aliasDB, err := client.CheckAliasExists(ctx, alias)
if err != nil {
if !dberrors.IsNotFoundError(err) {
telemetry.ReportCriticalError(ctx, "error when checking alias", err, attribute.String("alias", alias))

P1 Badge Treat pgx no-row result as not found

This branch assumes dberrors.IsNotFoundError(err) will fire when the alias is missing, but CheckAliasExists now uses pgx’ QueryRow and returns pgx.ErrNoRows, while dberrors.IsNotFoundError only matches database/sql.ErrNoRows (see packages/db/dberrors/dberrors.go:8-9). As a result, a build request with a new alias will hit this block and return a 500 instead of creating the alias, because the missing-alias case is treated as an unexpected error. Please update the not-found check to handle pgx’s error so alias creation continues to work.

ℹ️ 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".

@@ -0,0 +1,11 @@
-- name: CheckAliasConflictsWithTemplate :one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put it under templat-aliases or something? I think folder aliases can be confusing

jakubno and others added 4 commits November 21, 2025 14:54
# Conflicts:
#	packages/api/internal/handlers/deprecated_template_request_build.go
#	packages/api/internal/handlers/sandbox_kill.go
#	packages/api/internal/handlers/template_request_build_v3.go
#	packages/api/internal/orchestrator/pause_instance.go
#	packages/api/internal/template/register_build.go
#	packages/shared/pkg/models/envbuild.go
#	packages/shared/pkg/models/envbuild/where.go
#	packages/shared/pkg/models/envbuild_create.go
#	packages/shared/pkg/models/envbuild_update.go
#	packages/shared/pkg/models/migrate/schema.go
#	packages/shared/pkg/models/mutation.go
#	packages/shared/pkg/schema/build.go
Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
@jakubno jakubno force-pushed the migrate-to-sqlc-eng-2327 branch from 9107af9 to 2a19d71 Compare November 21, 2025 13:55
@jakubno jakubno requested a review from sitole November 21, 2025 15:01
@jakubno jakubno merged commit 747ed5d into main Nov 21, 2025
49 of 50 checks passed
@jakubno jakubno deleted the migrate-to-sqlc-eng-2327 branch November 21, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants