- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
305f696
b4ab301
dd2df9c
0356f46
6b1b900
8f63d5c
de7db33
5fdf899
3a4d049
4108ece
14b5382
8553501
f748d3d
c1b9871
e41c103
bb9b777
d940dae
c97d572
10bfe77
28a37f1
c889bf0
0196a49
b5dc95b
f2f76e9
940ced4
eb266db
4671bf6
c41f4e6
f3d8392
cc8400b
5c7cbae
083d256
92c185d
05595d8
aa90148
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- 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; | ||
ALTER TABLE users DROP COLUMN login_type; | ||
COMMIT; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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, | ||
PRIMARY KEY(user_id, login_type), | ||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | ||
); | ||
-- 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 last_used DESC) AS x, | ||
api_keys.* FROM api_keys | ||
) as keys | ||
WHERE x=1 AND keys.login_type != 'password'; | ||
-- 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; | ||
ALTER TABLE users ADD COLUMN login_type login_type NOT NULL DEFAULT 'password'; | ||
UPDATE | ||
users | ||
SET | ||
login_type = ( | ||
SELECT | ||
login_type | ||
FROM | ||
user_links | ||
WHERE | ||
user_links.user_id = users.id | ||
ORDER BY oauth_expiry DESC | ||
LIMIT 1 | ||
) | ||
FROM | ||
user_links | ||
WHERE | ||
user_links.user_id = users.id; | ||
COMMIT; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.