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
This commit is contained in:
Kyle Carberry
2022-02-07 15:32:37 -06:00
committed by GitHub
parent bde732f2ef
commit ed705f6af2
26 changed files with 892 additions and 935 deletions
+8 -22
View File
@@ -1,3 +1,11 @@
-- Store arbitrary data like project source code or avatars.
CREATE TABLE file (
hash varchar(32) NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
mimetype varchar(64) NOT NULL,
data bytea NOT NULL
);
CREATE TYPE provisioner_type AS ENUM ('echo', 'terraform');
-- Project defines infrastructure that your software project
@@ -90,25 +98,3 @@ CREATE TABLE project_parameter (
validation_value_type varchar(64) NOT NULL,
UNIQUE(project_version_id, name)
);
CREATE TYPE log_level AS ENUM (
'trace',
'debug',
'info',
'warn',
'error'
);
CREATE TYPE log_source AS ENUM (
'provisioner_daemon',
'provisioner'
);
CREATE TABLE project_version_log (
id uuid NOT NULL UNIQUE,
project_version_id uuid NOT NULL REFERENCES project_version (id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
source log_source NOT NULL,
level log_level NOT NULL,
output varchar(1024) NOT NULL
);
@@ -64,12 +64,3 @@ CREATE TABLE workspace_agent (
-- Identifies resources.
resource_metadata jsonb NOT NULL
);
CREATE TABLE workspace_history_log (
id uuid NOT NULL UNIQUE,
workspace_history_id uuid NOT NULL REFERENCES workspace_history (id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
source log_source NOT NULL,
level log_level NOT NULL,
output varchar(1024) NOT NULL
);
+22 -1
View File
@@ -24,11 +24,32 @@ CREATE TABLE IF NOT EXISTS provisioner_job (
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 log_level AS ENUM (
'trace',
'debug',
'info',
'warn',
'error'
);
CREATE TYPE log_source AS ENUM (
'provisioner_daemon',
'provisioner'
);
CREATE TABLE IF NOT EXISTS provisioner_job_log (
id uuid NOT NULL UNIQUE,
job_id uuid NOT NULL REFERENCES provisioner_job (id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
source log_source NOT NULL,
level log_level NOT NULL,
output varchar(1024) NOT NULL
);
CREATE TYPE parameter_scope AS ENUM (
'organization',
'project',