feat: Add parameter and jobs database schema (#81)

* feat: Add parameter and jobs database schema

This modifies a prior migration which is typically forbidden,
but because we're pre-production deployment I felt grouping
would be helpful to future contributors.

This adds database functions that are required for the provisioner
daemon and job queue logic.

* Add comment to acquire provisioner job query

* PostgreSQL hates running in parallel
This commit is contained in:
Kyle Carberry
2022-01-29 17:38:32 -06:00
committed by GitHub
parent 599ea2a331
commit b503c8b099
11 changed files with 1174 additions and 63 deletions
+10 -2
View File
@@ -48,6 +48,12 @@ CREATE TABLE project_history (
-- Types of parameters the automator supports.
CREATE TYPE parameter_type_system AS ENUM ('hcl');
-- Supported schemes for a parameter source.
CREATE TYPE parameter_source_scheme AS ENUM('data');
-- Supported schemes for a parameter destination.
CREATE TYPE parameter_destination_scheme AS ENUM('environment_variable', 'provisioner_variable');
-- Stores project version parameters parsed on import.
-- No secrets are stored here.
--
@@ -65,11 +71,13 @@ CREATE TABLE project_parameter (
-- 8KB limit
description varchar(8192) NOT NULL DEFAULT '',
-- eg. data://inlinevalue
default_source text,
default_source_scheme parameter_source_scheme,
default_source_value text,
-- Allows the user to override the source.
allow_override_source boolean NOT null,
-- eg. env://SOME_VARIABLE, tfvars://example
default_destination text,
default_destination_scheme parameter_destination_scheme,
default_destination_value text,
-- Allows the user to override the destination.
allow_override_destination boolean NOT null,
default_refresh text NOT NULL,
+53
View File
@@ -0,0 +1,53 @@
CREATE TABLE IF NOT EXISTS provisioner_daemon (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
updated_at timestamptz,
-- Name is generated for ease of differentiation.
-- eg. WowBananas16
name varchar(64) NOT NULL UNIQUE,
provisioners provisioner_type [ ] NOT NULL
);
CREATE TYPE provisioner_job_type AS ENUM (
'project_import',
'workspace_provision'
);
CREATE TABLE IF NOT EXISTS provisioner_job (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
started_at timestamptz,
cancelled_at timestamptz,
completed_at timestamptz,
error text,
initiator_id text NOT NULL,
provisioner provisioner_type NOT NULL,
type provisioner_job_type NOT NULL,
project_id uuid NOT NULL REFERENCES project(id) ON DELETE CASCADE,
input jsonb NOT NULL,
worker_id uuid
);
CREATE TYPE parameter_scope AS ENUM (
'organization',
'project',
'user',
'workspace'
);
-- Parameters are provided to jobs for provisioning and to workspaces.
CREATE TABLE parameter_value (
id uuid NOT NULL UNIQUE,
name varchar(64) NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
scope parameter_scope NOT NULL,
scope_id text NOT NULL,
source_scheme parameter_source_scheme NOT NULL,
source_value text NOT NULL,
destination_scheme parameter_destination_scheme NOT NULL,
destination_value text NOT NULL,
-- Prevents duplicates for parameters in the same scope.
UNIQUE(name, scope, scope_id)
);
+1 -1
View File
@@ -8,4 +8,4 @@ fi
migrate create -ext sql -dir . -seq $1
echo "After making adjustments, run \"make database/generate\" to generate models."
echo "Run \"make gen\" to generate models."