File tree 2 files changed +57
-3
lines changed
coderd/database/migrations
2 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 1
- ALTER TYPE 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.
2
5
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
+ CREATE TYPE new_logintype AS 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
+ ALTER TABLE 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_type SET DEFAULT ' password' ::new_logintype;
19
+
20
+ DROP INDEX IF EXISTS idx_api_key_name;
21
+ ALTER TABLE api_keys
22
+ ALTER COLUMN login_type TYPE new_logintype USING (login_type::text ::new_logintype);
23
+ CREATE UNIQUE INDEX idx_api_key_name
24
+ ON api_keys (user_id, token_name)
25
+ WHERE (login_type = ' token' ::new_logintype);
26
+
27
+ ALTER TABLE user_links
28
+ ALTER COLUMN login_type TYPE new_logintype USING (login_type::text ::new_logintype);
29
+
30
+ DROP TYPE login_type;
31
+ ALTER TYPE new_logintype RENAME TO login_type;
Original file line number Diff line number Diff line change @@ -43,7 +43,33 @@ AFTER DELETE ON oauth2_provider_app_tokens
43
43
FOR EACH ROW
44
44
EXECUTE PROCEDURE delete_deleted_oauth2_provider_app_token_api_key();
45
45
46
- ALTER TYPE login_type ADD VALUE IF NOT EXISTS ' oauth2_provider_app' ;
46
+ CREATE TYPE new_logintype AS 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
+ ALTER TABLE 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_type SET DEFAULT ' password' ::new_logintype;
60
+
61
+ DROP INDEX IF EXISTS idx_api_key_name;
62
+ ALTER TABLE api_keys
63
+ ALTER COLUMN login_type TYPE new_logintype USING (login_type::text ::new_logintype);
64
+ CREATE UNIQUE INDEX idx_api_key_name
65
+ ON api_keys (user_id, token_name)
66
+ WHERE (login_type = ' token' ::new_logintype);
67
+
68
+ ALTER TABLE user_links
69
+ ALTER COLUMN login_type TYPE new_logintype USING (login_type::text ::new_logintype);
70
+
71
+ DROP TYPE login_type;
72
+ ALTER TYPE new_logintype RENAME TO login_type;
47
73
48
74
-- Switch to an ID we will prefix to the raw secret that we give to the user
49
75
-- (instead of matching on the entire secret as the ID, since they will be
You can’t perform that action at this time.
0 commit comments