Skip to content

Commit 2ca981a

Browse files
committed
add migration
1 parent 6401205 commit 2ca981a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

coderd/database/migrations/000262_site_to_crypto_key.down.sql

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- Create a new enum type with the desired values
2+
CREATE TYPE new_crypto_key_feature AS ENUM (
3+
'workspace_apps_token',
4+
'workspace_apps_api_key',
5+
'oidc_convert',
6+
'tailnet_resume'
7+
);
8+
9+
-- Drop the old type and rename the new one
10+
ALTER TABLE crypto_keys
11+
ALTER COLUMN feature TYPE new_crypto_key_feature
12+
USING (feature::text::new_crypto_key_feature);
13+
14+
DROP TYPE crypto_key_feature;
15+
16+
ALTER TYPE new_crypto_key_feature RENAME TO crypto_key_feature;
17+
18+
-- Extract and decode the app_signing_key, then insert the first 64 bytes for workspace_apps_token
19+
INSERT INTO crypto_keys (feature, sequence, secret, secret_key_id, starts_at, deletes_at)
20+
SELECT
21+
'workspace_apps_token'::crypto_key_feature,
22+
1,
23+
encode(substring(decode(value, 'hex') from 1 for 64), 'base64'),
24+
NULL,
25+
'1970-01-01 00:00:00 UTC'::timestamptz,
26+
NULL
27+
FROM site_configs
28+
WHERE key = 'app_signing_key';
29+
30+
-- Extract and decode the app_signing_key, then insert the last 32 bytes for workspace_apps_api_key
31+
INSERT INTO crypto_keys (feature, sequence, secret, secret_key_id, starts_at, deletes_at)
32+
SELECT
33+
'workspace_apps_api_key'::crypto_key_feature,
34+
1,
35+
encode(substring(decode(value, 'hex') from -32), 'base64'),
36+
NULL,
37+
'1970-01-01 00:00:00 UTC'::timestamptz,
38+
NULL
39+
FROM site_configs
40+
WHERE key = 'app_signing_key';
41+
42+
-- Extract and decode the coordinator_resume_token_signing_key, then insert it for tailnet_resume feature
43+
INSERT INTO crypto_keys (feature, sequence, secret, secret_key_id, starts_at, deletes_at)
44+
SELECT
45+
'tailnet_resume'::crypto_key_feature,
46+
1,
47+
encode(decode(value, 'hex'), 'base64'),
48+
NULL,
49+
'1970-01-01 00:00:00 UTC'::timestamptz,
50+
NULL
51+
FROM site_configs
52+
WHERE key = 'coordinator_resume_token_signing_key';

0 commit comments

Comments
 (0)