mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
Review notes and test fixing
This commit is contained in:
@ -1,4 +1,8 @@
|
||||
-- Recreate the view to exclude the new column.
|
||||
-- DROP the workspace_build_with_user view so that we can recreate without
|
||||
-- workspace_builds.template_version_preset_id below. We need to drop the view
|
||||
-- before dropping workspace_builds.template_version_preset_id because the view
|
||||
-- references it. We can only recreate the view after dropping the column,
|
||||
-- because the view needs to be created without the column.
|
||||
DROP VIEW workspace_build_with_user;
|
||||
|
||||
ALTER TABLE workspace_builds
|
||||
|
@ -2,16 +2,9 @@ CREATE TABLE template_version_presets
|
||||
(
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
template_version_id UUID NOT NULL,
|
||||
-- TODO (sasswart): TEXT vs VARCHAR? Check with Mr Kopping.
|
||||
-- TODO (sasswart): A comment on the presets RFC mentioned that we may need to
|
||||
-- aggregate presets by name because we want statistics for related presets across
|
||||
-- template versions. This makes me uncomfortable. It couples constraints to a user
|
||||
-- facing field that could be avoided.
|
||||
name TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
-- TODO (sasswart): What do we need updated_at for? Is it worth it to have a history table?
|
||||
-- TODO (sasswart): Will auditing have any relevance to presets?
|
||||
updated_at TIMESTAMP WITH TIME ZONE,
|
||||
FOREIGN KEY (template_version_id) REFERENCES template_versions (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
@ -30,6 +23,15 @@ CREATE TABLE template_version_preset_parameters
|
||||
ALTER TABLE workspace_builds
|
||||
ADD COLUMN template_version_preset_id UUID NULL;
|
||||
|
||||
ALTER TABLE workspace_builds
|
||||
ADD CONSTRAINT workspace_builds_template_version_preset_id_fkey
|
||||
FOREIGN KEY (template_version_preset_id)
|
||||
REFERENCES template_version_presets (id)
|
||||
-- TODO (sasswart): SET NULL might not be the best choice here. The rest of the hierarchy has ON DELETE CASCADE.
|
||||
-- We don't want CASCADE here, because we don't want to delete the workspace build if the preset is deleted.
|
||||
-- However, do we want to lose record of the preset id for a workspace build?
|
||||
ON DELETE SET NULL;
|
||||
|
||||
-- Recreate the view to include the new column.
|
||||
DROP VIEW workspace_build_with_user;
|
||||
CREATE VIEW
|
||||
|
@ -6,28 +6,29 @@ VALUES ('d3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', 'Test Org', 'Test Organization',
|
||||
INSERT INTO users (id, email, username, created_at, updated_at, status, rbac_roles, login_type, hashed_password)
|
||||
VALUES ('1f573504-f7a0-4498-8b81-2e1939f3c4a2', 'test@coder.com', 'testuser', now(), now(), 'active', '{}', 'password', 'password');
|
||||
|
||||
-- Template
|
||||
INSERT INTO templates (id, created_by, organization_id, created_at, updated_at, deleted, name, provisioner, active_version_id, description)
|
||||
VALUES ('0bd0713b-176a-4864-a58b-546a1b021025', '1f573504-f7a0-4498-8b81-2e1939f3c4a2', 'd3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', now(), now(), false, 'test-template', 'terraform', null, 'Test template');
|
||||
-- Provisioner Job
|
||||
INSERT INTO provisioner_jobs (id, organization_id, created_at, updated_at, initiator_id, provisioner, storage_method, type, input, file_id)
|
||||
VALUES ('50ebe702-82e5-4053-859d-c24a3b742b57', 'd3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', now(), now(), '1f573504-f7a0-4498-8b81-2e1939f3c4a2', 'echo', 'file', 'template_version_import', '{}', '00000000-82e5-4053-859d-c24a3b742b57');
|
||||
|
||||
-- Template Version
|
||||
INSERT INTO template_versions (id, template_id, organization_id, created_by, created_at, updated_at, name, job_id, readme, message)
|
||||
VALUES ('f1276e15-01cd-406d-8ea5-64f113a79601', '0bd0713b-176a-4864-a58b-546a1b021025', 'd3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', '1f573504-f7a0-4498-8b81-2e1939f3c4a2', now(), now(), 'test-version', null, '', '');
|
||||
INSERT INTO template_versions (id, organization_id, created_by, created_at, updated_at, name, job_id, readme, message)
|
||||
VALUES ('f1276e15-01cd-406d-8ea5-64f113a79601', 'd3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', '1f573504-f7a0-4498-8b81-2e1939f3c4a2', now(), now(), 'test-version', '50ebe702-82e5-4053-859d-c24a3b742b57', '', '');
|
||||
|
||||
-- Template
|
||||
INSERT INTO templates (id, created_by, organization_id, created_at, updated_at, deleted, name, provisioner, active_version_id, description)
|
||||
VALUES ('0bd0713b-176a-4864-a58b-546a1b021025', '1f573504-f7a0-4498-8b81-2e1939f3c4a2', 'd3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', now(), now(), false, 'test-template', 'terraform', 'f1276e15-01cd-406d-8ea5-64f113a79601', 'Test template');
|
||||
|
||||
UPDATE templates SET active_version_id = 'f1276e15-01cd-406d-8ea5-64f113a79601' WHERE id = '0bd0713b-176a-4864-a58b-546a1b021025';
|
||||
-- Workspace
|
||||
INSERT INTO workspaces (id, organization_id, owner_id, template_id, created_at, updated_at, name, deleted, automatic_updates)
|
||||
VALUES ('8cb0b7c4-47b5-4bfc-ad92-88ccc61f3c12', 'd3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', '1f573504-f7a0-4498-8b81-2e1939f3c4a2', '0bd0713b-176a-4864-a58b-546a1b021025', now(), now(), 'test-workspace', false, 'never');
|
||||
|
||||
-- Provisioner Job
|
||||
INSERT INTO provisioner_jobs (id, organization_id, created_at, updated_at, status, worker_id, error, started_at)
|
||||
VALUES ('50ebe702-82e5-4053-859d-c24a3b742b57', 'd3fd38d2-ffc3-4ec2-8cfc-9c8dab6d9a74', now(), now(), 'pending', null, null, null);
|
||||
|
||||
-- Workspace Build
|
||||
INSERT INTO workspace_builds (id, workspace_id, template_version_id, initiator_id, job_id, created_at, updated_at, transition, reason)
|
||||
VALUES ('83b28647-743c-4649-b226-f2be697ca06c', '8cb0b7c4-47b5-4bfc-ad92-88ccc61f3c12', 'f1276e15-01cd-406d-8ea5-64f113a79601', '1f573504-f7a0-4498-8b81-2e1939f3c4a2', '50ebe702-82e5-4053-859d-c24a3b742b57', now(), now(), 'start', 'initiator');
|
||||
INSERT INTO workspace_builds (id, workspace_id, template_version_id, initiator_id, job_id, created_at, updated_at, transition, reason, build_number)
|
||||
VALUES ('83b28647-743c-4649-b226-f2be697ca06c', '8cb0b7c4-47b5-4bfc-ad92-88ccc61f3c12', 'f1276e15-01cd-406d-8ea5-64f113a79601', '1f573504-f7a0-4498-8b81-2e1939f3c4a2', '50ebe702-82e5-4053-859d-c24a3b742b57', now(), now(), 'start', 'initiator', 45);
|
||||
|
||||
-- Template Version Presets
|
||||
INSERT INTO template_version_presets (id, template_version_id, name, created_at, updated_at, description)
|
||||
INSERT INTO template_version_presets (id, template_version_id, name, created_at)
|
||||
VALUES
|
||||
('575a0fbb-cc3e-4709-ae9f-d1a3f365909c', 'f1276e15-01cd-406d-8ea5-64f113a79601', 'test', now(), now(), 'Test preset'),
|
||||
('2c76596d-436d-42eb-a38c-8d5a70497030', 'f1276e15-01cd-406d-8ea5-64f113a79601', 'test', now(), now(), 'Test preset');
|
||||
('575a0fbb-cc3e-4709-ae9f-d1a3f365909c', 'f1276e15-01cd-406d-8ea5-64f113a79601', 'test', now()),
|
||||
('2c76596d-436d-42eb-a38c-8d5a70497030', 'f1276e15-01cd-406d-8ea5-64f113a79601', 'test', now());
|
||||
|
Reference in New Issue
Block a user