Skip to content

Use UUID instead of INT for schema ID by default in addmodel - #8

Merged
itsharrykim merged 10 commits into
mainfrom
copilot/use-uuid-for-schema-id
Oct 26, 2025
Merged

Use UUID instead of INT for schema ID by default in addmodel#8
itsharrykim merged 10 commits into
mainfrom
copilot/use-uuid-for-schema-id

Conversation

Copilot AI commented Oct 26, 2025

Copy link
Copy Markdown
Contributor

The cmd/addmodel generator was using auto-incrementing integers for primary keys. This changes the default to UUID v4 for better distributed system compatibility.

Changes

Schema generation

  • Add field.UUID("id", uuid.UUID{}).Default(uuid.New) as first field in generated schemas
  • Import github.com/google/uuid in schema files

Handler generation

  • Replace strconv.Atoi(chi.URLParam(r, "id")) with uuid.Parse(idStr) for ID parsing
  • Add error handling for invalid UUID format
  • Conditionally import strconv only when int/float fields present

Example generated schema:

func (Product) Fields() []ent.Field {
    return []ent.Field{
        field.UUID("id", uuid.UUID{}).
            Default(uuid.New),
        
        field.String("name").
            NotEmpty(),
        // ... other fields
    }
}

Example generated handler:

func (h *ProductHandler) Edit(w http.ResponseWriter, r *http.Request) {
    idStr := chi.URLParam(r, "id")
    id, err := uuid.Parse(idStr)
    if err != nil {
        h.Renderer.RenderError(w, r, http.StatusBadRequest, "Invalid ID")
        return
    }
    
    product, err := h.Client.Product.Get(r.Context(), id)
    // ...
}

Only affects newly generated models. Existing schemas remain unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>Use UUID instead of INT for schema id by default</issue_title>
<issue_description>Use UUID instead of INT for schema id by default for cmd/addmodel program</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits October 26, 2025 14:54
Co-authored-by: itsharrykim <141856312+itsharrykim@users.noreply.github.com>
Co-authored-by: itsharrykim <141856312+itsharrykim@users.noreply.github.com>
Co-authored-by: itsharrykim <141856312+itsharrykim@users.noreply.github.com>
Co-authored-by: itsharrykim <141856312+itsharrykim@users.noreply.github.com>
Copilot AI changed the title [WIP] Use UUID instead of INT for schema id by default Use UUID instead of INT for schema ID by default in addmodel Oct 26, 2025
Copilot AI requested a review from itsharrykim October 26, 2025 15:05
@itsharrykim itsharrykim added the enhancement New feature or request label Oct 26, 2025
@itsharrykim

Copy link
Copy Markdown
Collaborator

Manually edited and fixed all other issues after Copilot's first draft

  • all handler, middleware, renderer files needed to be edited to accept UUID instead of INT for ID.

@itsharrykim
itsharrykim marked this pull request as ready for review October 26, 2025 16:15
@itsharrykim
itsharrykim merged commit 0c548a2 into main Oct 26, 2025
1 check passed
@itsharrykim
itsharrykim deleted the copilot/use-uuid-for-schema-id branch October 26, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use UUID instead of INT for schema id by default

2 participants