fix(db): correct channel contact merged_id foreign key#1290
Merged
clark-cant merged 1 commit intoJun 27, 2026
Merged
Conversation
clark-cant
approved these changes
Jun 27, 2026
clark-cant
left a comment
Contributor
There was a problem hiding this comment.
🦸♂️ Approved — Clean FK fix.
Summary: Corrects channel_contacts.merged_id FK to reference tenant_users(id) instead of the erroneous self-reference from migration 000083. Matches actual application data model (MergeContacts writes tenantUserID into merged_id).
Review:
- Migration up/down: ✅ correct — drops old constraint, adds proper FK with
ON DELETE SET NULL - Schema version bump: ✅ 85 → 86
- Audit SQL: ✅ updated to check against
tenant_users+ added tenant drift check - CI: ✅ go, web, release-versioning all green
- Scope: ✅ small, focused (34+/5−, 4 files)
- Testing: ✅ author verified with pre-fix DB dump
Ship it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
channel_contacts.merged_idFK to referencetenant_users(id).merged_idis written byMergeContacts(... tenantUserID)and resolved viachannel_contacts.merged_id = tenant_users.id.Surface parity
Tests
ENABLE_EMBEDUI=false./usr/local/go/bin/go test ./internal/store/... ./internal/upgrade/.../usr/local/go/bin/go build -tags sqliteonly ./.../usr/local/go/bin/go vet ./...merged_idFK fromchannel_contacts(id)totenant_users(id).