feat: persist type requirement order
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
ALTER TABLE "type_machine_component_requirements"
|
||||
ADD COLUMN "orderIndex" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE "type_machine_piece_requirements"
|
||||
ADD COLUMN "orderIndex" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
WITH ordered_component_requirements AS (
|
||||
SELECT
|
||||
id,
|
||||
ROW_NUMBER() OVER (PARTITION BY "typeMachineId" ORDER BY "createdAt") - 1 AS idx
|
||||
FROM "type_machine_component_requirements"
|
||||
)
|
||||
UPDATE "type_machine_component_requirements" t
|
||||
SET "orderIndex" = ordered_component_requirements.idx
|
||||
FROM ordered_component_requirements
|
||||
WHERE ordered_component_requirements.id = t.id;
|
||||
|
||||
WITH ordered_piece_requirements AS (
|
||||
SELECT
|
||||
id,
|
||||
ROW_NUMBER() OVER (PARTITION BY "typeMachineId" ORDER BY "createdAt") - 1 AS idx
|
||||
FROM "type_machine_piece_requirements"
|
||||
)
|
||||
UPDATE "type_machine_piece_requirements" t
|
||||
SET "orderIndex" = ordered_piece_requirements.idx
|
||||
FROM ordered_piece_requirements
|
||||
WHERE ordered_piece_requirements.id = t.id;
|
||||
Reference in New Issue
Block a user