Files
coder/database/migrations/000003_workspaces.up.sql
T
Kyle Carberry ed705f6af2 refactor: Generalize log ownership to allow for scratch jobs (#182)
* refactor: Generalize log ownership to allow for scratch jobs

Importing may fail when creating a project. We don't want to lose this output,
but we don't want to allow users to create a failing project.

This generalizes logs to soon enable one-off situations where a user can upload
their archive, create a project, and watch the output parse to completion.

* Improve file table schema by using hash

* Fix racey test by allowing logs before

* Add debug logging for PostgreSQL insert
2022-02-07 15:32:37 -06:00

67 lines
2.1 KiB
SQL

CREATE TABLE workspace (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
owner_id text NOT NULL,
project_id uuid NOT NULL REFERENCES project (id),
name varchar(64) NOT NULL,
UNIQUE(owner_id, name)
);
CREATE TYPE workspace_transition AS ENUM (
'create',
'start',
'stop',
'delete'
);
-- Workspace transition represents a change in workspace state.
CREATE TABLE workspace_history (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
workspace_id uuid NOT NULL REFERENCES workspace (id) ON DELETE CASCADE,
project_version_id uuid NOT NULL REFERENCES project_version (id) ON DELETE CASCADE,
name varchar(64) NOT NULL,
before_id uuid,
after_id uuid,
transition workspace_transition NOT NULL,
initiator varchar(255) NOT NULL,
-- State stored by the provisioner
provisioner_state bytea,
-- Job ID of the action
provision_job_id uuid NOT NULL,
UNIQUE(workspace_id, name)
);
-- Cloud resources produced by a provision job.
CREATE TABLE workspace_resource (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
workspace_history_id uuid NOT NULL REFERENCES workspace_history (id) ON DELETE CASCADE,
-- Resource type produced by a provisioner.
-- eg. "google_compute_instance"
type varchar(256) NOT NULL,
-- Name of the resource.
-- eg. "kyle-dev-instance"
name varchar(64) NOT NULL,
-- Token for an agent to connect.
workspace_agent_token varchar(128) NOT NULL UNIQUE,
-- If an agent has been conencted for this resource,
-- the agent table is not null.
workspace_agent_id uuid,
UNIQUE(workspace_history_id, name)
);
CREATE TABLE workspace_agent (
id uuid NOT NULL UNIQUE,
workspace_resource_id uuid NOT NULL REFERENCES workspace_resource (id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
-- Identifies instance architecture, cloud, etc.
instance_metadata jsonb NOT NULL,
-- Identifies resources.
resource_metadata jsonb NOT NULL
);