feat: persist type requirement order

This commit is contained in:
Matthieu
2025-10-23 09:36:39 +02:00
parent 582a6fd7e1
commit 16a703a4c3
5 changed files with 52 additions and 4 deletions

View File

@@ -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;

View File

@@ -296,6 +296,7 @@ model TypeMachineComponentRequirement {
maxCount Int?
required Boolean @default(true)
allowNewModels Boolean @default(true)
orderIndex Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -317,6 +318,7 @@ model TypeMachinePieceRequirement {
maxCount Int?
required Boolean @default(false)
allowNewModels Boolean @default(true)
orderIndex Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt