-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: use unique ID for linked accounts #3441
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
305f696
fix: use unique ID for linked accounts
sreya b4ab301
fixup a bunch of stuff
sreya dd2df9c
gofmt
sreya 0356f46
make fake db happy
sreya 6b1b900
make audit happy
sreya 8f63d5c
fix some tests
sreya de7db33
make gen
sreya 5fdf899
fix tests
sreya 3a4d049
fmt
sreya 4108ece
begin refactoring PR
sreya 14b5382
finish migration
sreya 8553501
use main sql.dump
sreya f748d3d
lift error
sreya c1b9871
new migration
sreya e41c103
more rewriting
sreya bb9b777
even more rewriting
sreya d940dae
finish up some test fixing
sreya c97d572
typos
sreya 10bfe77
Merge branch 'main' into jon/userauth
sreya 28a37f1
fix some remaining tests
sreya c889bf0
fix a gnarly bug
sreya 0196a49
add a down migration
sreya b5dc95b
add fkey on user_links, fix tests, add comments
sreya f2f76e9
add login_type to users table
sreya 940ced4
Merge branch 'main' into jon/userauth
sreya eb266db
fix login_type query
sreya 4671bf6
fix tests
sreya c41f4e6
fix audit
sreya f3d8392
fix down
sreya cc8400b
fix one more test
sreya 5c7cbae
Merge branch 'main' into jon/userauth
sreya 083d256
pr comments
sreya 92c185d
fix conflicting migration file
sreya 05595d8
generate.sh
sreya aa90148
butcher the english language to appease colin
sreya 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") | |
| ( | ||
| cd "$SCRIPT_DIR" | ||
|
|
||
| # Dump the updated schema. | ||
| go run dump/main.go | ||
| # The logic below depends on the exact version being correct :( | ||
| go run github.com/kyleconroy/sqlc/cmd/[email protected] generate | ||
|
|
||
|
|
||
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,22 @@ | ||
| -- This migration makes no attempt to try to populate | ||
| -- the oauth_access_token, oauth_refresh_token, and oauth_expiry | ||
| -- columns of api_key rows with the values from the dropped user_links | ||
| -- table. | ||
| BEGIN; | ||
|
|
||
| DROP TABLE IF EXISTS user_links; | ||
|
|
||
| ALTER TABLE | ||
| api_keys | ||
| ADD COLUMN oauth_access_token text DEFAULT ''::text NOT NULL; | ||
|
|
||
| ALTER TABLE | ||
| api_keys | ||
| ADD COLUMN oauth_refresh_token text DEFAULT ''::text NOT NULL; | ||
|
|
||
| ALTER TABLE | ||
| api_keys | ||
| ADD COLUMN oauth_expiry timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL; | ||
|
|
||
|
|
||
| COMMIT; |
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,53 @@ | ||
| BEGIN; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS user_links ( | ||
| user_id uuid NOT NULL, | ||
| login_type login_type NOT NULL, | ||
| linked_id text DEFAULT ''::text NOT NULL, | ||
| oauth_access_token text DEFAULT ''::text NOT NULL, | ||
| oauth_refresh_token text DEFAULT ''::text NOT NULL, | ||
| oauth_expiry timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL, | ||
| UNIQUE(user_id, login_type) | ||
| ); | ||
|
|
||
| -- This migrates columns on api_keys to the new user_links table. | ||
| -- It does this by finding all the API keys for each user, choosing | ||
| -- the most recently updated for each one and then assigning its relevant | ||
| -- values to the user_links table. | ||
| -- A user should at most have a row for an OIDC account and a Github account. | ||
| -- 'password' login types are ignored. | ||
|
|
||
| INSERT INTO user_links | ||
| ( | ||
| user_id, | ||
| login_type, | ||
| linked_id, | ||
| oauth_access_token, | ||
| oauth_refresh_token, | ||
| oauth_expiry | ||
| ) | ||
| SELECT | ||
| keys.user_id, | ||
| keys.login_type, | ||
| '', | ||
| keys.oauth_access_token, | ||
| keys.oauth_refresh_token, | ||
| keys.oauth_expiry | ||
| FROM | ||
| ( | ||
| SELECT | ||
| row_number() OVER (partition by user_id, login_type ORDER BY updated_at DESC) AS x, | ||
| api_keys.* FROM api_keys | ||
| ) as keys | ||
| WHERE x=1 AND keys.login_type != 'password'; | ||
sreya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| -- Drop columns that have been migrated to user_links. | ||
| -- It appears the 'oauth_id_token' was unused and so it has | ||
| -- been dropped here as well to avoid future confusion. | ||
| ALTER TABLE api_keys | ||
| DROP COLUMN oauth_access_token, | ||
| DROP COLUMN oauth_refresh_token, | ||
| DROP COLUMN oauth_id_token, | ||
| DROP COLUMN oauth_expiry; | ||
|
|
||
| COMMIT; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.