Skip to content

fix: reorder migration 151 to delete duplicates before update#687

Merged
bokelley merged 1 commit into
mainfrom
bokelley/fix-workos-webhooks
Jan 9, 2026
Merged

fix: reorder migration 151 to delete duplicates before update#687
bokelley merged 1 commit into
mainfrom
bokelley/fix-workos-webhooks

Conversation

@bokelley

@bokelley bokelley commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix migration 151 that was blocking deployments due to unique constraint violation
  • Reorder SQL operations to delete duplicate records before updating Slack IDs to WorkOS IDs

Problem

Migration 151 (consolidate_slack_workos_ids.sql) was failing with:

duplicate key value violates unique constraint "idx_wg_membership_unique"
Key (working_group_id, workos_user_id)=(29c61a7a-..., user_01KEF3D9...) already exists.

The migration tried to UPDATE Slack IDs to WorkOS IDs before deleting duplicates, causing the unique constraint to fail when both records already existed.

Solution

Reordered operations to:

  1. DELETE Slack-ID-based records where a WorkOS-ID-based record already exists
  2. UPDATE remaining Slack IDs to WorkOS IDs (now safe - no duplicates possible)
  3. Same pattern for working_group_leaders table

Test plan

  • All tests pass
  • Migration logic reviewed for data integrity
  • Migration runner wraps each migration in a transaction (rollback on failure)

🤖 Generated with Claude Code

The migration was failing because updating Slack IDs to WorkOS IDs
would violate the unique constraint when both records already exist.

Fix: Delete duplicate Slack-based records first (where a WorkOS-based
record already exists), then safely update the remaining records.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bokelley bokelley merged commit cdcd70f into main Jan 9, 2026
6 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