improvement: new prosthesis type data structure implemented and finally working!

This commit is contained in:
2026-09-01 21:03:04 +03:30
parent dc71c73ced
commit a3c14a18c1
51 changed files with 3306 additions and 1117 deletions

View File

@@ -0,0 +1,26 @@
-- Prosthesis type tree fields + multiple work items per tooth.
ALTER TABLE "prosthesis_types"
ADD COLUMN IF NOT EXISTS "category" TEXT NOT NULL DEFAULT 'crown',
ADD COLUMN IF NOT EXISTS "subcategory" TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS "chartRegion" TEXT NOT NULL DEFAULT 'crown',
ADD COLUMN IF NOT EXISTS "stackGroup" TEXT NOT NULL DEFAULT 'restoration',
ADD COLUMN IF NOT EXISTS "addonKind" TEXT NOT NULL DEFAULT '';
ALTER TABLE "lab_case_tooth_prosthesis"
DROP CONSTRAINT IF EXISTS "lab_case_tooth_prosthesis_labCaseId_sourceKey_tooth_key";
DROP INDEX IF EXISTS "lab_case_tooth_prosthesis_labCaseId_sourceKey_tooth_key";
-- Deduplicate stacked rows that would collide after adding prosthesisTypeCode to the unique key
-- (legacy unique already forbade two types per tooth, so this is a no-op for current data).
DELETE FROM "lab_case_tooth_prosthesis" AS a
USING "lab_case_tooth_prosthesis" AS b
WHERE a."id" > b."id"
AND a."labCaseId" = b."labCaseId"
AND a."sourceKey" = b."sourceKey"
AND a."tooth" = b."tooth"
AND a."prosthesisTypeCode" = b."prosthesisTypeCode";
CREATE UNIQUE INDEX IF NOT EXISTS "lab_case_tooth_prosthesis_case_source_tooth_type_key"
ON "lab_case_tooth_prosthesis"("labCaseId", "sourceKey", "tooth", "prosthesisTypeCode");

View File

@@ -0,0 +1,12 @@
-- One LabCaseTask pipeline per tooth: unique must include tooth.
ALTER TABLE "lab_case_tasks" ADD COLUMN IF NOT EXISTS "tooth" TEXT NOT NULL DEFAULT '';
UPDATE "lab_case_tasks"
SET "tooth" = COALESCE("teeth"->>0, '')
WHERE "tooth" = '';
ALTER TABLE "lab_case_tasks" DROP CONSTRAINT IF EXISTS "lab_case_tasks_case_source_prosthesis_step_key";
DROP INDEX IF EXISTS "lab_case_tasks_case_source_prosthesis_step_key";
CREATE UNIQUE INDEX IF NOT EXISTS "lab_case_tasks_case_source_tooth_prosthesis_step_key"
ON "lab_case_tasks"("labCaseId", "sourceKey", "tooth", "prosthesisTypeCode", "stepOrder");