Skip to content

Commit b770762

Browse files
committed
Refactor crypto_key_feature migration logic
This change enhances the crypto_keys table by updating enum handling for features. It introduces distinct roles for key storage, aiding in better distinction and maintenance of key features.
1 parent 08570b7 commit b770762

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Step 1: Remove the new entries from crypto_keys table
2+
DELETE FROM crypto_keys
3+
WHERE feature IN ('workspace_apps_token', 'workspace_apps_api_key');
4+
5+
CREATE TYPE old_crypto_key_feature AS ENUM (
6+
'workspace_apps',
7+
'oidc_convert',
8+
'tailnet_resume'
9+
);
10+
11+
ALTER TABLE crypto_keys
12+
ALTER COLUMN feature TYPE old_crypto_key_feature
13+
USING (feature::text::old_crypto_key_feature);
14+
15+
DROP TYPE crypto_key_feature;
16+
17+
ALTER TYPE old_crypto_key_feature RENAME TO crypto_key_feature;
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
DELETE FROM crypto_keys WHERE feature = 'workspace_apps';
10+
11+
-- Drop the old type and rename the new one
12+
ALTER TABLE crypto_keys
13+
ALTER COLUMN feature TYPE new_crypto_key_feature
14+
USING (feature::text::new_crypto_key_feature);
15+
16+
DROP TYPE crypto_key_feature;
17+
18+
ALTER TYPE new_crypto_key_feature RENAME TO crypto_key_feature;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
INSERT INTO crypto_keys (feature, sequence, secret, secret_key_id, starts_at, deletes_at)
2+
VALUES (
3+
'workspace_apps_token',
4+
1,
5+
'abc',
6+
NULL,
7+
'1970-01-01 00:00:00 UTC'::timestamptz,
8+
'2100-01-01 00:00:00 UTC'::timestamptz
9+
);
10+
11+
INSERT INTO crypto_keys (feature, sequence, secret, secret_key_id, starts_at, deletes_at)
12+
VALUES (
13+
'workspace_apps_api_key',
14+
1,
15+
'def',
16+
NULL,
17+
'1970-01-01 00:00:00 UTC'::timestamptz,
18+
'2100-01-01 00:00:00 UTC'::timestamptz
19+
);
20+
21+
INSERT INTO crypto_keys (feature, sequence, secret, secret_key_id, starts_at, deletes_at)
22+
VALUES (
23+
'oidc_convert',
24+
2,
25+
'ghi',
26+
NULL,
27+
'1970-01-01 00:00:00 UTC'::timestamptz,
28+
'2100-01-01 00:00:00 UTC'::timestamptz
29+
);
30+
31+
INSERT INTO crypto_keys (feature, sequence, secret, secret_key_id, starts_at, deletes_at)
32+
VALUES (
33+
'tailnet_resume',
34+
2,
35+
'jkl',
36+
NULL,
37+
'1970-01-01 00:00:00 UTC'::timestamptz,
38+
'2100-01-01 00:00:00 UTC'::timestamptz
39+
);
40+

0 commit comments

Comments
 (0)