Skip to content

Commit 0778f3e

Browse files
authored
feat: Add v1 schema types (#17)
* feat: Add v1 schema types This adds compatibility for sharing data with Coder v1. Since the tables are the same, all CRUD operations should function as expected. * Add license table
1 parent ec3685b commit 0778f3e

File tree

4 files changed

+285
-1
lines changed

4 files changed

+285
-1
lines changed

database/dump.sql

+79
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,81 @@
11
-- Code generated by 'make database/generate'. DO NOT EDIT.
22

3+
CREATE TYPE login_type AS ENUM (
4+
'built-in',
5+
'saml',
6+
'oidc'
7+
);
8+
9+
CREATE TYPE userstatus AS ENUM (
10+
'active',
11+
'dormant',
12+
'decommissioned'
13+
);
14+
15+
CREATE TABLE api_keys (
16+
id text NOT NULL,
17+
hashed_secret bytea NOT NULL,
18+
user_id text NOT NULL,
19+
application boolean NOT NULL,
20+
name text NOT NULL,
21+
last_used timestamp with time zone NOT NULL,
22+
expires_at timestamp with time zone NOT NULL,
23+
created_at timestamp with time zone NOT NULL,
24+
updated_at timestamp with time zone NOT NULL,
25+
login_type login_type NOT NULL,
26+
oidc_access_token text DEFAULT ''::text NOT NULL,
27+
oidc_refresh_token text DEFAULT ''::text NOT NULL,
28+
oidc_id_token text DEFAULT ''::text NOT NULL,
29+
oidc_expiry timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL,
30+
devurl_token boolean DEFAULT false NOT NULL
31+
);
32+
33+
CREATE TABLE licenses (
34+
id integer NOT NULL,
35+
license jsonb NOT NULL,
36+
created_at timestamp with time zone NOT NULL
37+
);
38+
39+
CREATE TABLE organization_members (
40+
organization_id text NOT NULL,
41+
user_id text NOT NULL,
42+
created_at timestamp with time zone NOT NULL,
43+
updated_at timestamp with time zone NOT NULL,
44+
roles text[] DEFAULT '{organization-member}'::text[] NOT NULL
45+
);
46+
47+
CREATE TABLE organizations (
48+
id text NOT NULL,
49+
name text NOT NULL,
50+
description text NOT NULL,
51+
created_at timestamp with time zone NOT NULL,
52+
updated_at timestamp with time zone NOT NULL,
53+
"default" boolean DEFAULT false NOT NULL,
54+
auto_off_threshold bigint DEFAULT '28800000000000'::bigint NOT NULL,
55+
cpu_provisioning_rate real DEFAULT 4.0 NOT NULL,
56+
memory_provisioning_rate real DEFAULT 1.0 NOT NULL,
57+
workspace_auto_off boolean DEFAULT false NOT NULL
58+
);
59+
60+
CREATE TABLE users (
61+
id text NOT NULL,
62+
email text NOT NULL,
63+
name text NOT NULL,
64+
revoked boolean NOT NULL,
65+
login_type login_type NOT NULL,
66+
hashed_password bytea NOT NULL,
67+
created_at timestamp with time zone NOT NULL,
68+
updated_at timestamp with time zone NOT NULL,
69+
temporary_password boolean DEFAULT false NOT NULL,
70+
avatar_hash text DEFAULT ''::text NOT NULL,
71+
ssh_key_regenerated_at timestamp with time zone DEFAULT now() NOT NULL,
72+
username text DEFAULT ''::text NOT NULL,
73+
dotfiles_git_uri text DEFAULT ''::text NOT NULL,
74+
roles text[] DEFAULT '{site-member}'::text[] NOT NULL,
75+
status userstatus DEFAULT 'active'::public.userstatus NOT NULL,
76+
relatime timestamp with time zone DEFAULT now() NOT NULL,
77+
gpg_key_regenerated_at timestamp with time zone DEFAULT now() NOT NULL,
78+
_decomissioned boolean DEFAULT false NOT NULL,
79+
shell text DEFAULT ''::text NOT NULL
80+
);
81+
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
-- This migration creates tables and types for v1 if they do not exist.
2+
-- This allows v2 to operate independently of v1, but share data if it exists.
3+
--
4+
-- All tables and types are stolen from:
5+
-- https://github.com/coder/m/blob/47b6fc383347b9f9fab424d829c482defd3e1fe2/product/coder/pkg/database/dump.sql
6+
7+
DO $$ BEGIN
8+
CREATE TYPE login_type AS ENUM (
9+
'built-in',
10+
'saml',
11+
'oidc'
12+
);
13+
EXCEPTION
14+
WHEN duplicate_object THEN null;
15+
END $$;
16+
17+
DO $$ BEGIN
18+
CREATE TYPE userstatus AS ENUM (
19+
'active',
20+
'dormant',
21+
'decommissioned'
22+
);
23+
EXCEPTION
24+
WHEN duplicate_object THEN null;
25+
END $$;
26+
27+
CREATE TABLE IF NOT EXISTS users (
28+
id text NOT NULL,
29+
email text NOT NULL,
30+
name text NOT NULL,
31+
revoked boolean NOT NULL,
32+
login_type login_type NOT NULL,
33+
hashed_password bytea NOT NULL,
34+
created_at timestamp with time zone NOT NULL,
35+
updated_at timestamp with time zone NOT NULL,
36+
temporary_password boolean DEFAULT false NOT NULL,
37+
avatar_hash text DEFAULT '' :: text NOT NULL,
38+
ssh_key_regenerated_at timestamp with time zone DEFAULT now() NOT NULL,
39+
username text DEFAULT '' :: text NOT NULL,
40+
dotfiles_git_uri text DEFAULT '' :: text NOT NULL,
41+
roles text [] DEFAULT '{site-member}' :: text [] NOT NULL,
42+
status userstatus DEFAULT 'active' :: public.userstatus NOT NULL,
43+
relatime timestamp with time zone DEFAULT now() NOT NULL,
44+
gpg_key_regenerated_at timestamp with time zone DEFAULT now() NOT NULL,
45+
_decomissioned boolean DEFAULT false NOT NULL,
46+
shell text DEFAULT '' :: text NOT NULL
47+
);
48+
49+
CREATE TABLE IF NOT EXISTS organizations (
50+
id text NOT NULL,
51+
name text NOT NULL,
52+
description text NOT NULL,
53+
created_at timestamp with time zone NOT NULL,
54+
updated_at timestamp with time zone NOT NULL,
55+
"default" boolean DEFAULT false NOT NULL,
56+
auto_off_threshold bigint DEFAULT '28800000000000' :: bigint NOT NULL,
57+
cpu_provisioning_rate real DEFAULT 4.0 NOT NULL,
58+
memory_provisioning_rate real DEFAULT 1.0 NOT NULL,
59+
workspace_auto_off boolean DEFAULT false NOT NULL
60+
);
61+
62+
CREATE TABLE IF NOT EXISTS organization_members (
63+
organization_id text NOT NULL,
64+
user_id text NOT NULL,
65+
created_at timestamp with time zone NOT NULL,
66+
updated_at timestamp with time zone NOT NULL,
67+
roles text [] DEFAULT '{organization-member}' :: text [] NOT NULL
68+
);
69+
70+
CREATE TABLE IF NOT EXISTS api_keys (
71+
id text NOT NULL,
72+
hashed_secret bytea NOT NULL,
73+
user_id text NOT NULL,
74+
application boolean NOT NULL,
75+
name text NOT NULL,
76+
last_used timestamp with time zone NOT NULL,
77+
expires_at timestamp with time zone NOT NULL,
78+
created_at timestamp with time zone NOT NULL,
79+
updated_at timestamp with time zone NOT NULL,
80+
login_type login_type NOT NULL,
81+
oidc_access_token text DEFAULT ''::text NOT NULL,
82+
oidc_refresh_token text DEFAULT ''::text NOT NULL,
83+
oidc_id_token text DEFAULT ''::text NOT NULL,
84+
oidc_expiry timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL,
85+
devurl_token boolean DEFAULT false NOT NULL
86+
);
87+
88+
CREATE TABLE licenses (
89+
id integer NOT NULL,
90+
license jsonb NOT NULL,
91+
created_at timestamp with time zone NOT NULL
92+
);

database/models.go

+112-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/sqlc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ packages:
1818
overrides:
1919
- db_type: citext
2020
go_type: string
21+
rename:
22+
userstatus: UserStatus

0 commit comments

Comments
 (0)