mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
Preset tables, latest workspace view, state logic improved
Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
-- Revert prebuild views
|
||||
DROP VIEW IF EXISTS workspace_prebuild_builds;
|
||||
DROP VIEW IF EXISTS workspace_prebuilds;
|
||||
DROP VIEW IF EXISTS workspace_latest_build;
|
||||
|
||||
-- Revert user operations
|
||||
DELETE FROM user_status_changes WHERE user_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0';
|
||||
|
@ -12,3 +12,17 @@ CREATE VIEW workspace_prebuild_builds AS
|
||||
SELECT workspace_id
|
||||
FROM workspace_builds
|
||||
WHERE initiator_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0';
|
||||
|
||||
CREATE VIEW workspace_latest_build AS
|
||||
SELECT wb.*
|
||||
FROM (SELECT tv.template_id,
|
||||
wbmax.workspace_id,
|
||||
MAX(wbmax.build_number) as max_build_number
|
||||
FROM workspace_builds wbmax
|
||||
JOIN template_versions tv ON (tv.id = wbmax.template_version_id)
|
||||
GROUP BY tv.template_id, wbmax.workspace_id) wbmax
|
||||
JOIN workspace_builds wb ON (
|
||||
wb.workspace_id = wbmax.workspace_id
|
||||
AND wb.build_number = wbmax.max_build_number
|
||||
);
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
DROP TABLE IF EXISTS template_version_preset_prebuild_schedules;
|
||||
DROP TABLE IF EXISTS template_version_preset_prebuilds;
|
||||
|
||||
|
@ -1 +1,21 @@
|
||||
CREATE TABLE
|
||||
CREATE TABLE template_version_preset_prebuilds
|
||||
(
|
||||
id UUID PRIMARY KEY,
|
||||
preset_id UUID NOT NULL,
|
||||
desired_instances INT NOT NULL,
|
||||
invalidate_after_secs INT NULL DEFAULT 0,
|
||||
|
||||
-- Deletion should never occur, but if we allow it we should check no prebuilds exist attached to this preset first.
|
||||
FOREIGN KEY (preset_id) REFERENCES template_version_presets (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE template_version_preset_prebuild_schedules
|
||||
(
|
||||
id UUID PRIMARY KEY,
|
||||
preset_prebuild_id UUID NOT NULL,
|
||||
timezone TEXT NOT NULL,
|
||||
cron_schedule TEXT NOT NULL,
|
||||
desired_instances INT NOT NULL,
|
||||
|
||||
FOREIGN KEY (preset_prebuild_id) REFERENCES template_version_preset_prebuilds (id) ON DELETE CASCADE
|
||||
);
|
||||
|
Reference in New Issue
Block a user