Skip to content

Make Slack IDs unique but Slack usernames nonunique#202

Merged
MMK21Hub merged 7 commits into
hackclub:mainfrom
MMK21Hub:fix-nonunique-usernames
May 7, 2026
Merged

Make Slack IDs unique but Slack usernames nonunique#202
MMK21Hub merged 7 commits into
hackclub:mainfrom
MMK21Hub:fix-nonunique-usernames

Conversation

@MMK21Hub
Copy link
Copy Markdown
Collaborator

@MMK21Hub MMK21Hub commented May 7, 2026

Copilot AI review requested due to automatic review settings May 7, 2026 10:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Slack name into User.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.

Comment thread nephthys/utils/slack_user.py
Comment thread nephthys/utils/slack_user.py
Comment thread nephthys/piccolo_migrations/nephthys_2026_05_07t10_40_49_usernames_not_unique.py Outdated
Comment thread nephthys/piccolo_migrations/nephthys_2026_05_07t11_04_02_unique_slack_id.py Outdated
@MMK21Hub MMK21Hub changed the title Make Slack IDs unique but Slack usernames unique Make Slack IDs unique but Slack usernames nonunique May 7, 2026
This ensures compat with how Prisma did it
@MMK21Hub MMK21Hub enabled auto-merge May 7, 2026 11:45
@MMK21Hub MMK21Hub added this pull request to the merge queue May 7, 2026
Merged via the queue into hackclub:main with commit 877f8cf May 7, 2026
4 checks passed
@MMK21Hub MMK21Hub deleted the fix-nonunique-usernames branch May 7, 2026 11:47
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.

Some users' threads get ignored (UniqueViolationError)

2 participants