Skip to content

fix: expand token column size and fix composite index exceeding MySQL limit - #21

Merged
johnnyluo merged 4 commits into
mainfrom
fix/device-token-index
Apr 4, 2026
Merged

fix: expand token column size and fix composite index exceeding MySQL limit#21
johnnyluo merged 4 commits into
mainfrom
fix/device-token-index

Conversation

@johnnyluo

@johnnyluo johnnyluo commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Increase Token field from varchar(255) to varchar(512) to accommodate longer FCM/APNs/web push tokens
  • Remove Token from the idx_vault_party composite unique index — the combined (vault_id[255], party_name[255], token[512]) with utf8mb4 encoding totals 4088 bytes, exceeding MySQL InnoDB's 3072-byte index limit
  • Unique constraint is now (vault_id, party_name) with a separate regular index idx_token on the token column
  • Update RegisterDevice upsert to conflict on (vault_id, party_name) and include token in DoUpdates, so re-registration with a new push token updates the existing record

Test plan

  • Register a device with a token longer than 255 characters — should succeed
  • Re-register the same vault+party with a new token — should update the token in place
  • Verify AutoMigrate runs without error (the existing DROP INDEX idx_vault_party call handles the transition)
  • Verify FindDeviceByToken and unregister operations still work correctly

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized database column size constraints for improved storage efficiency.

… limit

- Increase Token from varchar(255) to varchar(512) to accommodate longer push tokens
- Remove Token from idx_vault_party unique index; composite (vault_id, party_name, token) with utf8mb4 exceeded MySQL's 3072-byte InnoDB index limit
- Unique constraint is now (vault_id, party_name) with a separate regular index on token
- Update RegisterDevice upsert to conflict on (vault_id, party_name) and update token on re-registration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 4, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 675eb6b9-3078-4160-9d54-fd4a2f6c31f9

📥 Commits

Reviewing files that changed from the base of the PR and between ce9bf68 and 8c38e10.

📒 Files selected for processing (1)
  • models/device.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • models/device.go

Walkthrough

Adjusted GORM column type constraints in models.Device: reduced VaultId and DeviceType to varchar(64), reduced PartyName to varchar(128), and increased Token to varchar(512). All other field properties and constraints remain unchanged.

Changes

Cohort / File(s) Summary
GORM Column Type Constraints
models/device.go
Adjusted varchar constraints: VaultId and DeviceType reduced to varchar(64), PartyName reduced to varchar(128), Token increased to varchar(512). Other field properties including not null, index associations, and validation tags unchanged.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: expanding the token column size and fixing a composite index that exceeded MySQL limits.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/device-token-index

Comment @coderabbitai help to get the list of available commands and usage tips.

johnnyluo and others added 3 commits April 5, 2026 09:32
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- PartyName: varchar(255) -> varchar(128)
- Token: restored to uniqueIndex:idx_vault_party (removed separate idx_token)
- DeviceType: varchar(255) -> varchar(64)
- Combined index (64+128+512)*4 = 2816 bytes, within MySQL's 3072-byte limit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@johnnyluo
johnnyluo merged commit 3fe92d5 into main Apr 4, 2026
2 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.

1 participant