1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/src/migrations/20230615122909-fix-env-sort-order.js
2023-06-15 13:27:15 +03:00

33 lines
805 B
JavaScript

'use strict';
exports.up = function (db, callback) {
db.runSql(
`
WITH sorted_environments AS (
SELECT
*,
ROW_NUMBER() OVER (
ORDER BY
sort_order,
created_at
) AS new_sort_order
FROM
environments
)
UPDATE
environments
SET
sort_order = sorted_environments.new_sort_order
FROM
sorted_environments
WHERE
environments.name = sorted_environments.name;
`,
callback,
);
};
exports.down = function (db, callback) {
db.runSql(``, callback);
};