forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path000004_jobs.up.sql
More file actions
178 lines (163 loc) · 5.62 KB
/
Copy path000004_jobs.up.sql
File metadata and controls
178 lines (163 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
CREATE TABLE IF NOT EXISTS provisioner_daemons (
id uuid NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz,
organization_id uuid,
-- Name is generated for ease of differentiation.
-- eg. WowBananas16
name varchar(64) NOT NULL UNIQUE,
provisioners provisioner_type [ ] NOT NULL,
PRIMARY KEY (id)
);
CREATE TYPE provisioner_job_type AS ENUM (
'template_version_import',
'workspace_build'
);
CREATE TYPE provisioner_storage_method AS ENUM ('file');
CREATE TABLE IF NOT EXISTS provisioner_jobs (
id uuid NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
started_at timestamptz,
canceled_at timestamptz,
completed_at timestamptz,
error text,
organization_id uuid NOT NULL REFERENCES organizations (id) ON DELETE CASCADE,
-- foreign key?
initiator_id uuid NOT NULL,
provisioner provisioner_type NOT NULL,
storage_method provisioner_storage_method NOT NULL,
storage_source text NOT NULL,
type provisioner_job_type NOT NULL,
input jsonb NOT NULL,
worker_id uuid,
PRIMARY KEY (id)
);
CREATE TYPE log_level AS ENUM (
'trace',
'debug',
'info',
'warn',
'error'
);
CREATE TYPE log_source AS ENUM (
'provisioner_daemon',
'provisioner'
);
CREATE TABLE IF NOT EXISTS provisioner_job_logs (
id uuid NOT NULL,
job_id uuid NOT NULL REFERENCES provisioner_jobs (id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
source log_source NOT NULL,
level log_level NOT NULL,
stage varchar(128) NOT NULL,
output varchar(1024) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE workspace_resources (
id uuid NOT NULL,
created_at timestamptz NOT NULL,
job_id uuid NOT NULL REFERENCES provisioner_jobs (id) ON DELETE CASCADE,
transition workspace_transition NOT NULL,
type varchar(192) NOT NULL,
name varchar(64) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE workspace_agents (
id uuid NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
name varchar(64) NOT NULL,
first_connected_at timestamptz,
last_connected_at timestamptz,
disconnected_at timestamptz,
resource_id uuid NOT NULL REFERENCES workspace_resources (id) ON DELETE CASCADE,
auth_token uuid NOT NULL,
auth_instance_id varchar(64),
architecture varchar(64) NOT NULL,
environment_variables jsonb,
operating_system varchar(64) NOT NULL,
startup_script varchar(65534),
instance_metadata jsonb,
resource_metadata jsonb,
PRIMARY KEY (id)
);
CREATE TYPE parameter_scope AS ENUM (
'organization',
'template',
'import_job',
'user',
'workspace'
);
-- Types of parameters the automator supports.
CREATE TYPE parameter_type_system AS ENUM ('none', 'hcl');
-- Supported schemes for a parameter source.
CREATE TYPE parameter_source_scheme AS ENUM('none', 'data');
-- Supported schemes for a parameter destination.
CREATE TYPE parameter_destination_scheme AS ENUM('none', 'environment_variable', 'provisioner_variable');
-- Stores template version parameters parsed on import.
-- No secrets are stored here.
--
-- All parameter validation occurs server-side to process
-- complex validations.
--
-- Parameter types, description, and validation will produce
-- a UI for users to enter values.
-- Needs to be made consistent with the examples below.
CREATE TABLE parameter_schemas (
id uuid NOT NULL,
created_at timestamptz NOT NULL,
job_id uuid NOT NULL REFERENCES provisioner_jobs (id) ON DELETE CASCADE,
name varchar(64) NOT NULL,
description varchar(8192) NOT NULL DEFAULT '',
default_source_scheme parameter_source_scheme,
default_source_value text NOT NULL,
-- Allows the user to override the source.
allow_override_source boolean NOT null,
default_destination_scheme parameter_destination_scheme,
-- Allows the user to override the destination.
allow_override_destination boolean NOT null,
default_refresh text NOT NULL,
-- Whether the consumer can view the source and destinations.
redisplay_value boolean NOT null,
-- This error would appear in the UI if the condition is not met.
validation_error varchar(256) NOT NULL,
validation_condition varchar(512) NOT NULL,
validation_type_system parameter_type_system NOT NULL,
validation_value_type varchar(64) NOT NULL,
PRIMARY KEY (id),
UNIQUE(job_id, name)
);
-- Parameters are provided to jobs for provisioning and to workspaces.
CREATE TABLE parameter_values (
id uuid NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
scope parameter_scope NOT NULL,
scope_id uuid NOT NULL,
name varchar(64) NOT NULL,
source_scheme parameter_source_scheme NOT NULL,
source_value text NOT NULL,
destination_scheme parameter_destination_scheme NOT NULL,
PRIMARY KEY (id),
-- Prevents duplicates for parameters in the same scope.
UNIQUE(scope_id, name)
);
CREATE TABLE workspace_builds (
id uuid NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
workspace_id uuid NOT NULL REFERENCES workspaces (id) ON DELETE CASCADE,
template_version_id uuid NOT NULL REFERENCES template_versions (id) ON DELETE CASCADE,
name varchar(64) NOT NULL,
build_number integer NOT NULL,
transition workspace_transition NOT NULL,
initiator_id uuid NOT NULL,
-- State stored by the provisioner
provisioner_state bytea,
-- Job ID of the action
job_id uuid NOT NULL UNIQUE REFERENCES provisioner_jobs (id) ON DELETE CASCADE,
PRIMARY KEY (id),
UNIQUE(workspace_id, name),
UNIQUE(workspace_id, build_number)
);