Files
coder/coderd/database/migrations/000003_workspaces.up.sql
T

23 lines
779 B
SQL
Raw Normal View History

2022-03-17 18:10:46 -05:00
CREATE TABLE workspaces (
2022-04-01 14:42:36 -05:00
id uuid NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
2022-04-01 14:42:36 -05:00
-- Use ON DELETE RESTRICT so that we can cleanup external workspace
-- resources first.
owner_id uuid NOT NULL REFERENCES users (id) ON DELETE RESTRICT,
organization_id uuid NOT NULL REFERENCES organizations (id) ON DELETE RESTRICT,
2022-04-06 12:42:40 -05:00
template_id uuid NOT NULL REFERENCES templates (id) ON DELETE RESTRICT,
deleted boolean NOT NULL DEFAULT FALSE,
2022-04-01 14:42:36 -05:00
name varchar(64) NOT NULL,
PRIMARY KEY (id)
);
-- Enforces no active workspaces have the same name.
CREATE UNIQUE INDEX ON workspaces USING btree (owner_id, lower(name)) WHERE deleted = FALSE;
CREATE TYPE workspace_transition AS ENUM (
'start',
'stop',
'delete'
);