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

Commit237ee70

Browse files
committed
perf: optimize migration 371 to run faster on large deployments
closes#20899This is in response to a migration in v2.27 that takes very long on deployments with large `api_key` tables.
1 parente340560 commit237ee70

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

‎coderd/database/migrations/000371_api_key_scopes_array_allow_list.up.sql‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,24 @@ ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'workspace_proxy:read';
141141
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'workspace_proxy:update';
142142
-- End enum extensions
143143

144+
-- Purge old API keys to speed up the migration for large deployments.
145+
-- Note: that problem should be solved in coderd once PR 20863 is released:
146+
-- https://github.com/coder/coder/blob/main/coderd/database/dbpurge/dbpurge.go#L85
147+
148+
DELETEFROM api_keysWHERE expires_at< NOW()- INTERVAL'7 days';
149+
144150
-- Add new columns without defaults; backfill; then enforce NOT NULL
145-
ALTERTABLE api_keys ADD COLUMN scopes api_key_scope[];
146-
ALTERTABLE api_keys ADD COLUMN allow_listtext[];
151+
ALTERTABLE api_keys
152+
ADD COLUMN scopes api_key_scope[],
153+
ADD COLUMN allow_listtext[];
147154

148155
-- Backfill existing rows for compatibility
149-
UPDATE api_keysSET scopes= ARRAY[scope::api_key_scope];
150-
UPDATE api_keysSET allow_list= ARRAY['*:*'];
151-
152-
-- Enforce NOT NULL
153-
ALTERTABLE api_keys ALTER COLUMN scopesSETNOT NULL;
154-
ALTERTABLE api_keys ALTER COLUMN allow_listSETNOT NULL;
156+
UPDATE api_keysSET
157+
scopes= ARRAY[scope::api_key_scope],
158+
allow_list= ARRAY['*:*'];
155159

156-
-- Drop legacy single-scope column
157-
ALTERTABLE api_keys DROP COLUMN scope;
160+
-- Enforce NOT NULL and drop legacy single-scope column
161+
ALTERTABLE api_keys
162+
ALTER COLUMN scopesSETNOT NULL,
163+
ALTER COLUMN allow_listSETNOT NULL,
164+
DROP COLUMN scope;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp