Files
coder/coderd/database/migrations/000002_templates.up.sql
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
2.3 KiB
SQL
Raw Normal View History

2022-04-06 12:42:40 -05:00
-- Store arbitrary data like template source code or avatars.
2022-03-17 18:10:46 -05:00
CREATE TABLE files (
2022-04-01 14:42:36 -05:00
hash varchar(64) NOT NULL,
created_at timestamptz NOT NULL,
2022-04-01 14:42:36 -05:00
-- foreign key?
created_by uuid NOT NULL,
mimetype varchar(64) NOT NULL,
2022-04-01 14:42:36 -05:00
data bytea NOT NULL,
PRIMARY KEY (hash)
);
2022-02-04 16:51:54 -06:00
CREATE TYPE provisioner_type AS ENUM ('echo', 'terraform');
2022-01-24 11:07:42 -06:00
2022-04-06 12:42:40 -05:00
-- Template defines infrastructure that your software template
2022-01-24 11:07:42 -06:00
-- requires for development.
2022-04-06 12:42:40 -05:00
CREATE TABLE templates (
2022-04-01 14:42:36 -05:00
id uuid NOT NULL,
2022-01-24 11:07:42 -06:00
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
2022-04-06 12:42:40 -05:00
-- Templates must be scoped to an organization.
2022-04-01 14:42:36 -05:00
organization_id uuid NOT NULL REFERENCES organizations (id) ON DELETE CASCADE,
deleted boolean NOT NULL DEFAULT FALSE,
2022-01-24 11:07:42 -06:00
name varchar(64) NOT NULL,
provisioner provisioner_type NOT NULL,
2022-04-06 12:42:40 -05:00
-- Target's a Template Version to use for Workspaces.
2022-01-24 11:07:42 -06:00
-- If a Workspace doesn't match this version, it will be prompted to rebuild.
active_version_id uuid NOT NULL,
2022-04-01 14:42:36 -05:00
PRIMARY KEY (id),
2022-04-06 12:42:40 -05:00
-- Disallow templates to have the same name under
2022-01-24 11:07:42 -06:00
-- the same organization.
UNIQUE(organization_id, name)
);
2022-04-06 12:42:40 -05:00
-- Enforces no active templates have the same name.
CREATE UNIQUE INDEX ON templates (organization_id, name) WHERE deleted = FALSE;
CREATE UNIQUE INDEX idx_templates_name_lower ON templates USING btree (lower(name));
2022-04-06 12:42:40 -05:00
-- Template Versions store historical template data. When a Template Version is imported,
-- an "import" job is queued to parse parameters. A Template Version
2022-01-24 11:07:42 -06:00
-- can only be used if the import job succeeds.
2022-04-06 12:42:40 -05:00
CREATE TABLE template_versions (
2022-04-01 14:42:36 -05:00
id uuid NOT NULL,
-- This should be indexed. It is intentionally nullable.
2022-04-06 12:42:40 -05:00
template_id uuid REFERENCES templates (id) ON DELETE CASCADE,
2022-04-01 14:42:36 -05:00
organization_id uuid NOT NULL REFERENCES organizations (id) ON DELETE CASCADE,
2022-01-24 11:07:42 -06:00
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
-- Name is generated for ease of differentiation.
-- eg. TheCozyRabbit16
name varchar(64) NOT NULL,
-- Extracted from a README.md on import.
-- Maximum of 1MB.
description varchar(1048576) NOT NULL,
2022-04-06 12:42:40 -05:00
-- The job ID for building the template version.
job_id uuid NOT NULL,
2022-04-01 14:42:36 -05:00
PRIMARY KEY (id),
2022-04-06 12:42:40 -05:00
-- Disallow templates to have the same build name
2022-01-24 11:07:42 -06:00
-- multiple times.
2022-04-06 12:42:40 -05:00
UNIQUE(template_id, name)
2022-01-24 11:07:42 -06:00
);