Make Slack IDs unique but Slack usernames nonunique#202
Merged
Conversation
Collaborator
MMK21Hub
commented
May 7, 2026
- Slack usernames are no longer unique
- Only affects legacy DBs
- Fixes Some users' threads get ignored (UniqueViolationError) #199
- Ensure Slack IDs are unique
- Only affects new DBs since legacy ones already have a unique index
- Database migrations, yippee
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Slack user identity constraints to prevent UniqueViolationError during user upserts by making Slack IDs unique while allowing Slack usernames to be non-unique (to support legacy Prisma DB edge-cases like username “swaps”).
Changes:
- Remove legacy uniqueness on
User.username(via migration) and write the internal SlacknameintoUser.username. - Enforce uniqueness on
User.slackId(schema + migration). - Add a small raw-migration helper to reduce boilerplate for SQL-only migrations.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
nephthys/utils/slack_user.py |
Adds username() accessor and changes display-name fallback behavior. |
nephthys/events/message_creation.py |
Stores Slack internal username (not display name) into User.username on upsert. |
nephthys/database/tables.py |
Marks User.slack_id as unique at the Piccolo schema level. |
nephthys/database/raw_migration.py |
Adds a helper to build raw SQL migrations consistently. |
nephthys/piccolo_migrations/nephthys_2026_05_07t10_40_49_usernames_not_unique.py |
Drops the legacy unique index on User.username. |
nephthys/piccolo_migrations/nephthys_2026_05_07t11_04_02_unique_slack_id.py |
Adds a unique index on User.slackId. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This ensures compat with how Prisma did 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.