Skip to content

Commit f7222c6

Browse files
committed
feat: Add project models
1 parent 8be2456 commit f7222c6

File tree

5 files changed

+257
-0
lines changed

5 files changed

+257
-0
lines changed

database/dump.sql

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ CREATE TYPE login_type AS ENUM (
66
'oidc'
77
);
88

9+
CREATE TYPE parameter_type_system AS ENUM (
10+
'hcl'
11+
);
12+
13+
CREATE TYPE project_storage_method AS ENUM (
14+
'inline-archive'
15+
);
16+
17+
CREATE TYPE provisioner_type AS ENUM (
18+
'terraform',
19+
'cdr-basic'
20+
);
21+
922
CREATE TYPE userstatus AS ENUM (
1023
'active',
1124
'dormant',
@@ -57,6 +70,45 @@ CREATE TABLE organizations (
5770
workspace_auto_off boolean DEFAULT false NOT NULL
5871
);
5972

73+
CREATE TABLE project (
74+
id uuid NOT NULL,
75+
created timestamp with time zone NOT NULL,
76+
updated timestamp with time zone NOT NULL,
77+
organization_id text NOT NULL,
78+
name character varying(64) NOT NULL,
79+
provisioner provisioner_type NOT NULL,
80+
active_version_id uuid
81+
);
82+
83+
CREATE TABLE project_history (
84+
id uuid NOT NULL,
85+
project_id uuid NOT NULL,
86+
created timestamp with time zone NOT NULL,
87+
updated timestamp with time zone NOT NULL,
88+
name character varying(64) NOT NULL,
89+
description character varying(1048576) NOT NULL,
90+
storage_method project_storage_method NOT NULL,
91+
storage_source bytea NOT NULL,
92+
import_job_id uuid NOT NULL
93+
);
94+
95+
CREATE TABLE project_parameter (
96+
id uuid NOT NULL,
97+
project_history_id uuid NOT NULL,
98+
name character varying(64) NOT NULL,
99+
description character varying(8192) DEFAULT ''::character varying NOT NULL,
100+
default_source text,
101+
allow_override_source boolean NOT NULL,
102+
default_destination text,
103+
allow_override_destination boolean NOT NULL,
104+
default_refresh text NOT NULL,
105+
redisplay_value boolean NOT NULL,
106+
validation_error character varying(256) NOT NULL,
107+
validation_condition character varying(512) NOT NULL,
108+
validation_type_system parameter_type_system NOT NULL,
109+
validation_value_type character varying(64) NOT NULL
110+
);
111+
60112
CREATE TABLE users (
61113
id text NOT NULL,
62114
email text NOT NULL,
@@ -79,3 +131,27 @@ CREATE TABLE users (
79131
shell text DEFAULT ''::text NOT NULL
80132
);
81133

134+
ALTER TABLE ONLY project_history
135+
ADD CONSTRAINT project_history_id_key UNIQUE (id);
136+
137+
ALTER TABLE ONLY project_history
138+
ADD CONSTRAINT project_history_project_id_name_key UNIQUE (project_id, name);
139+
140+
ALTER TABLE ONLY project
141+
ADD CONSTRAINT project_id_key UNIQUE (id);
142+
143+
ALTER TABLE ONLY project
144+
ADD CONSTRAINT project_organization_id_name_key UNIQUE (organization_id, name);
145+
146+
ALTER TABLE ONLY project_parameter
147+
ADD CONSTRAINT project_parameter_id_key UNIQUE (id);
148+
149+
ALTER TABLE ONLY project_parameter
150+
ADD CONSTRAINT project_parameter_project_history_id_name_key UNIQUE (project_history_id, name);
151+
152+
ALTER TABLE ONLY project_history
153+
ADD CONSTRAINT project_history_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id);
154+
155+
ALTER TABLE ONLY project_parameter
156+
ADD CONSTRAINT project_parameter_project_history_id_fkey FOREIGN KEY (project_history_id) REFERENCES project_history(id) ON DELETE CASCADE;
157+

database/migrations/000002_projects.down.sql

Whitespace-only changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
CREATE TYPE provisioner_type AS ENUM ('terraform', 'cdr-basic');
2+
3+
-- Project defines infrastructure that your software project
4+
-- requires for development.
5+
CREATE TABLE project (
6+
id uuid NOT NULL UNIQUE,
7+
created timestamptz NOT NULL,
8+
updated timestamptz NOT NULL,
9+
-- Projects must be scoped to an organization.
10+
organization_id text NOT NULL,
11+
name varchar(64) NOT NULL,
12+
provisioner provisioner_type NOT NULL,
13+
-- Target's a Project Version to use for Workspaces.
14+
-- If a Workspace doesn't match this version, it will be prompted to rebuild.
15+
active_version_id uuid,
16+
-- Disallow projects to have the same name under
17+
-- the same organization.
18+
UNIQUE(organization_id, name)
19+
);
20+
21+
CREATE TYPE project_storage_method AS ENUM ('inline-archive');
22+
23+
-- Project Versions store Project history. When a Project Version is imported,
24+
-- an "import" job is queued to parse parameters. A Project Version
25+
-- can only be used if the import job succeeds.
26+
CREATE TABLE project_history (
27+
id uuid NOT NULL UNIQUE,
28+
-- This should be indexed.
29+
project_id uuid NOT NULL REFERENCES project (id),
30+
created timestamptz NOT NULL,
31+
updated timestamptz NOT NULL,
32+
-- Name is generated for ease of differentiation.
33+
-- eg. TheCozyRabbit16
34+
name varchar(64) NOT NULL,
35+
-- Extracted from a README.md on import.
36+
-- Maximum of 1MB.
37+
description varchar(1048576) NOT NULL,
38+
storage_method project_storage_method NOT NULL,
39+
storage_source bytea NOT NULL,
40+
-- The import job for a Project Version. This is used
41+
-- to detect if an import was successful.
42+
import_job_id uuid NOT NULL,
43+
-- Disallow projects to have the same build name
44+
-- multiple times.
45+
UNIQUE(project_id, name)
46+
);
47+
48+
-- Types of parameters the automator supports.
49+
CREATE TYPE parameter_type_system AS ENUM ('hcl');
50+
51+
-- Stores project version parameters parsed on import.
52+
-- No secrets are stored here.
53+
--
54+
-- All parameter validation occurs server-side to process
55+
-- complex validations.
56+
--
57+
-- Parameter types, description, and validation will produce
58+
-- a UI for users to enter values.
59+
-- Needs to be made consistent with the examples below.
60+
CREATE TABLE project_parameter (
61+
id uuid NOT NULL UNIQUE,
62+
project_history_id uuid NOT NULL REFERENCES project_history(id) ON DELETE CASCADE,
63+
name varchar(64) NOT NULL,
64+
-- 8KB limit
65+
description varchar(8192) NOT NULL DEFAULT '',
66+
-- eg. data://inlinevalue
67+
default_source text,
68+
-- Allows the user to override the source.
69+
allow_override_source boolean NOT null,
70+
-- eg. env://SOME_VARIABLE, tfvars://example
71+
default_destination text,
72+
-- Allows the user to override the destination.
73+
allow_override_destination boolean NOT null,
74+
default_refresh text NOT NULL,
75+
-- Whether the consumer can view the source and destinations.
76+
redisplay_value boolean NOT null,
77+
-- This error would appear in the UI if the condition is not met.
78+
validation_error varchar(256) NOT NULL,
79+
validation_condition varchar(512) NOT NULL,
80+
validation_type_system parameter_type_system NOT NULL,
81+
validation_value_type varchar(64) NOT NULL,
82+
UNIQUE(project_history_id, name)
83+
);

database/models.go

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/sqlc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ rename:
2525
oidc_expiry: OIDCExpiry
2626
oidc_id_token: OIDCIDToken
2727
oidc_refresh_token: OIDCRefreshToken
28+
parameter_type_system_hcl: ParameterTypeSystemHCL
2829
userstatus: UserStatus

0 commit comments

Comments
 (0)