Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0ff7c2

Browse files
SasSwartEdwardAngert
authored andcommitted
fix: rewrite login type migrations (#16978)
When trying to add [systemusers](#16916), we discovered anissue in two migrations that added values to the login_type enum.After some[consideration](#16916 (comment)),we decided to retroactively correct them.
1 parent9d5f9ad commitd0ff7c2

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed
Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1-
ALTERTYPE login_type ADD VALUE IF NOT EXISTS'none';
1+
-- This migration has been modified after its initial commit.
2+
-- The new implementation makes the same changes as the original, but
3+
-- takes into account the message in create_migration.sh. This is done
4+
-- to allow the insertion of a user with the "none" login type in later migrations.
25

3-
COMMENT ON TYPE login_type IS'Specifies the method of authentication. "none" is a special case in which no authentication method is allowed.';
6+
CREATETYPEnew_logintypeAS ENUM (
7+
'password',
8+
'github',
9+
'oidc',
10+
'token',
11+
'none'
12+
);
13+
COMMENT ON TYPE new_logintype IS'Specifies the method of authentication. "none" is a special case in which no authentication method is allowed.';
14+
15+
ALTERTABLE users
16+
ALTER COLUMN login_type DROP DEFAULT,
17+
ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype),
18+
ALTER COLUMN login_typeSET DEFAULT'password'::new_logintype;
19+
20+
DROPINDEX IF EXISTS idx_api_key_name;
21+
ALTERTABLE api_keys
22+
ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype);
23+
CREATEUNIQUE INDEXidx_api_key_name
24+
ON api_keys (user_id, token_name)
25+
WHERE (login_type='token'::new_logintype);
26+
27+
ALTERTABLE user_links
28+
ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype);
29+
30+
DROPTYPE login_type;
31+
ALTERTYPE new_logintype RENAME TO login_type;

‎coderd/database/migrations/000195_oauth2_provider_codes.up.sql

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,33 @@ AFTER DELETE ON oauth2_provider_app_tokens
4343
FOR EACH ROW
4444
EXECUTE PROCEDURE delete_deleted_oauth2_provider_app_token_api_key();
4545

46-
ALTERTYPE login_type ADD VALUE IF NOT EXISTS'oauth2_provider_app';
46+
CREATETYPEnew_logintypeAS ENUM (
47+
'password',
48+
'github',
49+
'oidc',
50+
'token',
51+
'none',
52+
'oauth2_provider_app'
53+
);
54+
COMMENT ON TYPE new_logintype IS'Specifies the method of authentication. "none" is a special case in which no authentication method is allowed.';
55+
56+
ALTERTABLE users
57+
ALTER COLUMN login_type DROP DEFAULT,
58+
ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype),
59+
ALTER COLUMN login_typeSET DEFAULT'password'::new_logintype;
60+
61+
DROPINDEX IF EXISTS idx_api_key_name;
62+
ALTERTABLE api_keys
63+
ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype);
64+
CREATEUNIQUE INDEXidx_api_key_name
65+
ON api_keys (user_id, token_name)
66+
WHERE (login_type='token'::new_logintype);
67+
68+
ALTERTABLE user_links
69+
ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype);
70+
71+
DROPTYPE login_type;
72+
ALTERTYPE new_logintype RENAME TO login_type;
4773

4874
-- Switch to an ID we will prefix to the raw secret that we give to the user
4975
-- (instead of matching on the entire secret as the ID, since they will be

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp