Files
coder/coderd/database/migrations/000029_variable_order.up.sql
David Wahler b5f5e909bd Return template parameters in consistent order (#2975)
* return parameters from Terraform provisioner in sorted order

* persist parameter indices in database and return them in correct order from API

* don't re-sort parameters by name when creating templates
2022-07-13 15:29:34 -05:00

16 lines
461 B
SQL

-- temporarily create index column as nullable
ALTER TABLE parameter_schemas ADD COLUMN index integer;
-- initialize ordering for existing parameters
WITH tmp AS (
SELECT id, row_number() OVER (PARTITION BY job_id ORDER BY name) AS index
FROM parameter_schemas
)
UPDATE parameter_schemas
SET index = tmp.index
FROM tmp
WHERE parameter_schemas.id = tmp.id;
-- all rows should now be initialized
ALTER TABLE parameter_schemas ALTER COLUMN index SET NOT NULL;