-
-
Notifications
You must be signed in to change notification settings - Fork 129
fix(account): enforce unique GitHub links #2829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WcaleNieWolny
wants to merge
8
commits into
main
Choose a base branch
from
wolny/unique-github-account-link
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+305
−1
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e351158
test(account): cover unique GitHub links
WcaleNieWolny 4de93b1
fix(account): enforce unique GitHub links
WcaleNieWolny 746849e
fix(db): prebuild GitHub uniqueness index
WcaleNieWolny 1c177c8
fix(db): validate GitHub uniqueness index
WcaleNieWolny a6f5799
fix(db): recover invalid GitHub index builds
WcaleNieWolny 4c7d69b
fix(db): serialize GitHub index prebuild
WcaleNieWolny b82581e
fix(account): hide GitHub link ownership conflicts
WcaleNieWolny 9efa001
fix(db): sequence GitHub index migration
WcaleNieWolny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -- Required pre-deploy step: build the GitHub identity index without blocking writes. | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
| -- Run the SINGLE statement below alone in SQL Editor (or psql). Do not mix it | ||
| -- with other statements in one Editor run if the Editor wraps a transaction: | ||
| -- CREATE INDEX CONCURRENTLY cannot run in a transaction. | ||
| -- | ||
| -- Example (psql): | ||
| -- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f scripts/ops/users_github_id_unique_index.sql | ||
|
|
||
| CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS users_github_id_key | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| ON public.users (github_id); | ||
|
WcaleNieWolny marked this conversation as resolved.
|
||
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
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
34 changes: 34 additions & 0 deletions
34
supabase/migrations/20260802171300_enforce_unique_github_id.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| DO $$ | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| DECLARE | ||
| duplicate_github_id bigint; | ||
| duplicate_count bigint; | ||
| BEGIN | ||
| SELECT github_id, COUNT(*) | ||
| INTO duplicate_github_id, duplicate_count | ||
| FROM public.users | ||
| WHERE github_id IS NOT NULL | ||
| GROUP BY github_id | ||
| HAVING COUNT(*) > 1 | ||
| ORDER BY github_id | ||
| LIMIT 1; | ||
|
|
||
| IF duplicate_github_id IS NOT NULL THEN | ||
| RAISE EXCEPTION | ||
| 'Cannot enforce unique GitHub account links: github_id % is linked to % users', | ||
| duplicate_github_id, | ||
| duplicate_count; | ||
| END IF; | ||
| END | ||
| $$; | ||
|
|
||
| -- Production operators must prebuild this index concurrently with | ||
| -- scripts/ops/users_github_id_unique_index.sql before applying the migration. | ||
| -- The fallback keeps fresh local/test databases self-contained; on production | ||
| -- CREATE INDEX IF NOT EXISTS is a no-op, and the constraint attachment below | ||
| -- only holds the table lock briefly. | ||
| CREATE UNIQUE INDEX IF NOT EXISTS users_github_id_key | ||
| ON public.users (github_id); | ||
|
|
||
| ALTER TABLE public.users | ||
| ADD CONSTRAINT users_github_id_key | ||
| UNIQUE USING INDEX users_github_id_key; | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.