mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
Depends on https://github.com/coder/coder/pull/16916 _(change base to `main` once it is merged)_ Closes https://github.com/coder/internal/issues/514 _This is one of several PRs to decompose the `dk/prebuilds` feature branch into separate PRs to merge into `main`._ --------- Signed-off-by: Danny Kopping <dannykopping@gmail.com> Co-authored-by: Danny Kopping <dannykopping@gmail.com> Co-authored-by: evgeniy-scherbina <evgeniy.shcherbina.es@gmail.com>
20 lines
887 B
SQL
20 lines
887 B
SQL
ALTER TABLE template_version_presets
|
|
ADD COLUMN desired_instances INT NULL,
|
|
ADD COLUMN invalidate_after_secs INT NULL DEFAULT 0;
|
|
|
|
-- Ensure that the idx_unique_preset_name index creation won't fail.
|
|
-- This is necessary because presets were released before the index was introduced,
|
|
-- so existing data might violate the uniqueness constraint.
|
|
WITH ranked AS (
|
|
SELECT id, name, template_version_id,
|
|
ROW_NUMBER() OVER (PARTITION BY name, template_version_id ORDER BY id) AS row_num
|
|
FROM template_version_presets
|
|
)
|
|
UPDATE template_version_presets
|
|
SET name = ranked.name || '_auto_' || row_num
|
|
FROM ranked
|
|
WHERE template_version_presets.id = ranked.id AND row_num > 1;
|
|
|
|
-- We should not be able to have presets with the same name for a particular template version.
|
|
CREATE UNIQUE INDEX idx_unique_preset_name ON template_version_presets (name, template_version_id);
|