mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: Allow provisioner jobs to be disconnected from projects (#194)
* Nest jobs under an organization * Rename project parameter to parameter schema * Update references when computing project parameters * Add files endpoint * Allow one-off project import jobs * Allow variables to be injected that are not defined by the schema * Update API to use jobs first * Fix CLI tests * Fix linting * Fix hex length for files table * Reduce memory allocation for windows
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
-- Store arbitrary data like project source code or avatars.
|
||||
CREATE TABLE file (
|
||||
hash varchar(32) NOT NULL UNIQUE,
|
||||
hash varchar(64) NOT NULL UNIQUE,
|
||||
created_at timestamptz NOT NULL,
|
||||
created_by text NOT NULL,
|
||||
mimetype varchar(64) NOT NULL,
|
||||
data bytea NOT NULL
|
||||
);
|
||||
@@ -20,14 +21,12 @@ CREATE TABLE project (
|
||||
provisioner provisioner_type NOT NULL,
|
||||
-- Target's a Project Version to use for Workspaces.
|
||||
-- If a Workspace doesn't match this version, it will be prompted to rebuild.
|
||||
active_version_id uuid,
|
||||
active_version_id uuid NOT NULL,
|
||||
-- Disallow projects to have the same name under
|
||||
-- the same organization.
|
||||
UNIQUE(organization_id, name)
|
||||
);
|
||||
|
||||
CREATE TYPE project_storage_method AS ENUM ('inline-archive');
|
||||
|
||||
-- Project Versions store historical project data. When a Project Version is imported,
|
||||
-- an "import" job is queued to parse parameters. A Project Version
|
||||
-- can only be used if the import job succeeds.
|
||||
@@ -43,8 +42,6 @@ CREATE TABLE project_version (
|
||||
-- Extracted from a README.md on import.
|
||||
-- Maximum of 1MB.
|
||||
description varchar(1048576) NOT NULL,
|
||||
storage_method project_storage_method NOT NULL,
|
||||
storage_source bytea NOT NULL,
|
||||
-- The import job for a Project Version. This is used
|
||||
-- to detect if an import was successful.
|
||||
import_job_id uuid NOT NULL,
|
||||
@@ -52,49 +49,3 @@ CREATE TABLE project_version (
|
||||
-- multiple times.
|
||||
UNIQUE(project_id, name)
|
||||
);
|
||||
|
||||
-- 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 project 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 project_version_parameter (
|
||||
id uuid NOT NULL UNIQUE,
|
||||
created_at timestamptz NOT NULL,
|
||||
project_version_id uuid NOT NULL REFERENCES project_version(id) ON DELETE CASCADE,
|
||||
name varchar(64) NOT NULL,
|
||||
-- 8KB limit
|
||||
description varchar(8192) NOT NULL DEFAULT '',
|
||||
-- eg. data://inlinevalue
|
||||
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_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,
|
||||
-- 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,
|
||||
UNIQUE(project_version_id, name)
|
||||
);
|
||||
|
||||
@@ -9,10 +9,12 @@ CREATE TABLE IF NOT EXISTS provisioner_daemon (
|
||||
);
|
||||
|
||||
CREATE TYPE provisioner_job_type AS ENUM (
|
||||
'project_import',
|
||||
'project_version_import',
|
||||
'workspace_provision'
|
||||
);
|
||||
|
||||
CREATE TYPE provisioner_storage_method AS ENUM ('file');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS provisioner_job (
|
||||
id uuid NOT NULL UNIQUE,
|
||||
created_at timestamptz NOT NULL,
|
||||
@@ -21,8 +23,11 @@ CREATE TABLE IF NOT EXISTS provisioner_job (
|
||||
cancelled_at timestamptz,
|
||||
completed_at timestamptz,
|
||||
error text,
|
||||
organization_id text NOT NULL,
|
||||
initiator_id text 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
|
||||
@@ -57,6 +62,15 @@ CREATE TYPE parameter_scope AS ENUM (
|
||||
'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');
|
||||
|
||||
-- Parameters are provided to jobs for provisioning and to workspaces.
|
||||
CREATE TABLE parameter_value (
|
||||
id uuid NOT NULL UNIQUE,
|
||||
@@ -71,4 +85,39 @@ CREATE TABLE parameter_value (
|
||||
destination_value text NOT NULL,
|
||||
-- Prevents duplicates for parameters in the same scope.
|
||||
UNIQUE(name, scope, scope_id)
|
||||
);
|
||||
);
|
||||
|
||||
-- Stores project 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_schema (
|
||||
id uuid NOT NULL UNIQUE,
|
||||
created_at timestamptz NOT NULL,
|
||||
job_id uuid NOT NULL REFERENCES provisioner_job(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,
|
||||
-- Allows the user to override the source.
|
||||
allow_override_source boolean NOT null,
|
||||
-- eg. env://SOME_VARIABLE, tfvars://example
|
||||
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,
|
||||
-- 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,
|
||||
UNIQUE(job_id, name)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user