fix: fix external_id length#1472
Conversation
Greptile SummaryThis PR fixes a data truncation issue reported in #1471 by increasing the Confidence Score: 5/5Safe 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
Sequence DiagramsequenceDiagram
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
Reviews (1): Last reviewed commit: "chore: generate schema" | Re-trigger Greptile |
There was a problem hiding this comment.
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.
| field.String("external_id"). | ||
| Optional(). | ||
| MaxLen(512), |
There was a problem hiding this comment.
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.
| field.String("external_id"). | |
| Optional(). | |
| MaxLen(512), | |
| field.String("external_id"). | |
| Optional(). | |
| MaxLen(512). | |
| Immutable(), |
| field.String("external_id"). | ||
| Optional(). | ||
| MaxLen(512), |
There was a problem hiding this comment.
Similar to the Request schema, the external_id in RequestExecution should likely be immutable to ensure consistency and prevent accidental modifications of tracking identifiers.
| field.String("external_id"). | |
| Optional(). | |
| MaxLen(512), | |
| field.String("external_id"). | |
| Optional(). | |
| MaxLen(512). | |
| Immutable(), |
There was a problem hiding this comment.
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_idmax length to 512 for bothRequestandRequestExecutionentities. - 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.
Related issuse: #1471
修改MaxLength为512,对应MySQL中VARCHAR的长度