Skip to content

fix: fix external_id length#1472

Merged
looplj merged 2 commits into
looplj:unstablefrom
LazuliKao:fix/external_id-length
Apr 24, 2026
Merged

fix: fix external_id length#1472
looplj merged 2 commits into
looplj:unstablefrom
LazuliKao:fix/external_id-length

Conversation

@LazuliKao

@LazuliKao LazuliKao commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Related issuse: #1471

修改MaxLength为512,对应MySQL中VARCHAR的长度

image

@LazuliKao LazuliKao marked this pull request as ready for review April 24, 2026 08:20
Copilot AI review requested due to automatic review settings April 24, 2026 08:20
@greptile-apps

greptile-apps Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a data truncation issue reported in #1471 by increasing the MaxLen of the external_id field from unset (which defaults to VARCHAR(191) on MySQL) to 512 on both the Request and RequestExecution ent schemas, then regenerates all downstream ent artifacts. The application uses ent's auto-migration on startup (client.Schema.Create), so the ALTER TABLE to widen the column will execute automatically when the service restarts.

Confidence Score: 5/5

Safe to merge — a targeted, correctly regenerated schema fix with no logic changes.

The change is minimal and consistent: both schema files and all generated ent artifacts are updated in lockstep. The app uses ent auto-migration on startup so the column resize will happen automatically. The runtime validator is derived from the schema descriptor, ensuring the new 512-char limit is enforced everywhere. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
internal/ent/schema/request.go Added .MaxLen(512) to the external_id field — the root schema change that drives this fix.
internal/ent/schema/request_execution.go Same MaxLen(512) fix applied to RequestExecution.external_id, keeping both tables consistent.
internal/ent/migrate/schema.go Generated file: external_id column now declares Size: 512 for both requests and request_executions tables.
internal/ent/runtime/runtime.go Generated file: ExternalIDValidator is derived dynamically from the schema descriptor, so it automatically enforces the new 512-char limit at runtime.
internal/ent/request_create.go Generated file: no logic changes; validation delegates to the updated ExternalIDValidator.
internal/ent/request_update.go Generated file: no logic changes; validation delegates to the updated ExternalIDValidator.
internal/ent/requestexecution_create.go Generated file: mirrors request_create.go changes for the RequestExecution entity.
internal/ent/requestexecution_update.go Generated file: mirrors request_update.go changes for the RequestExecution entity.
internal/ent/internal/schema.go Generated file: embedded schema snapshot updated to reflect the new MaxLen(512) constraints.
internal/ent/request/request.go Generated constants file, no logic change needed; ExternalIDValidator variable is populated at runtime.
internal/ent/requestexecution/requestexecution.go Generated constants file; same as request/request.go counterpart.

Sequence Diagram

sequenceDiagram
    participant Client
    participant RequestCreate/Update
    participant ExternalIDValidator
    participant MySQL DB

    Client->>RequestCreate/Update: SetExternalID(value)
    RequestCreate/Update->>ExternalIDValidator: ExternalIDValidator(value)
    Note over ExternalIDValidator: MaxLen check: len ≤ 512
    alt len > 512
        ExternalIDValidator-->>RequestCreate/Update: ValidationError
        RequestCreate/Update-->>Client: error
    else len ≤ 512
        ExternalIDValidator-->>RequestCreate/Update: nil
        RequestCreate/Update->>MySQL DB: INSERT/UPDATE external_id (VARCHAR 512)
        MySQL DB-->>Client: success
    end
Loading

Reviews (1): Last reviewed commit: "chore: generate schema" | Re-trigger Greptile

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a 512-character length constraint for the external_id field in both the Request and RequestExecution schemas, including the corresponding generated validation logic. Feedback suggests making this field immutable in both schemas to ensure data integrity and adding an index to the Request schema to optimize lookup performance.

Comment on lines +85 to +87
field.String("external_id").
Optional().
MaxLen(512),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since external_id is intended for tracking requests in external systems, it should ideally be immutable once set at creation time to maintain data integrity. Additionally, considering this field is used for tracking, it is highly recommended to add an index on it in the Indexes() function to ensure performant lookups as the table grows.

Suggested change
field.String("external_id").
Optional().
MaxLen(512),
field.String("external_id").
Optional().
MaxLen(512).
Immutable(),

Comment on lines +44 to +46
field.String("external_id").
Optional().
MaxLen(512),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the Request schema, the external_id in RequestExecution should likely be immutable to ensure consistency and prevent accidental modifications of tracking identifiers.

Suggested change
field.String("external_id").
Optional().
MaxLen(512),
field.String("external_id").
Optional().
MaxLen(512).
Immutable(),

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses MySQL Error 1406 (22001): Data too long for column 'external_id' by increasing the Ent schema limit for external_id to accommodate longer upstream IDs (e.g., from Responses API/Copilot providers).

Changes:

  • Increase external_id max length to 512 for both Request and RequestExecution entities.
  • Regenerate Ent artifacts so runtime validators and migration schema reflect the new field size.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/ent/schema/request.go Sets external_id to MaxLen(512) for Request.
internal/ent/schema/request_execution.go Sets external_id to MaxLen(512) for RequestExecution.
internal/ent/runtime/runtime.go Wires ExternalIDValidator from schema descriptors at runtime.
internal/ent/request_create.go Runs external_id validator during Request creation.
internal/ent/request_update.go Runs external_id validator during Request updates.
internal/ent/requestexecution_create.go Runs external_id validator during RequestExecution creation.
internal/ent/requestexecution_update.go Runs external_id validator during RequestExecution updates.
internal/ent/request/request.go Adds ExternalIDValidator variable for Request.
internal/ent/requestexecution/requestexecution.go Adds ExternalIDValidator variable for RequestExecution.
internal/ent/migrate/schema.go Updates external_id column size to 512 in migration schema.
internal/ent/internal/schema.go Updates schema snapshot JSON to reflect the new size/validator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@looplj looplj merged commit 60882db into looplj:unstable Apr 24, 2026
7 of 8 checks passed
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