fix: fix migration & tests
This commit is contained in:
parent
d2478a3657
commit
e05ea8ea8c
@ -524,21 +524,31 @@ customMigrations = Map.fromListWith (>>)
|
||||
runConduit $ getExamEntries .| C.mapM_ renameExamParts
|
||||
)
|
||||
, ( AppliedMigrationKey [migrationVersion|21.0.0|] [version|22.0.0|]
|
||||
, whenM (tableExists "exam") $
|
||||
[executeQQ|
|
||||
ALTER TABLE "exam" DROP COLUMN IF EXISTS "grading_key";
|
||||
ALTER TABLE "exam" ADD COLUMN IF NOT EXISTS "grading_rule" jsonb;
|
||||
, whenM (tableExists "exam") $ do
|
||||
oldVersion <- columnExists "exam" "grading_key"
|
||||
if
|
||||
| oldVersion -> do
|
||||
-- Major changes happend to the structure of exams without appropriate
|
||||
-- migration, try to remedy that here
|
||||
tableDropEmpty "exam_part_corrector"
|
||||
tableDropEmpty "exam_corrector"
|
||||
tableDropEmpty "exam_result"
|
||||
tableDropEmpty "exam_registration"
|
||||
tableDropEmpty "exam_occurrence"
|
||||
tableDropEmpty "exam_part"
|
||||
tableDropEmpty "exam"
|
||||
| otherwise ->
|
||||
[executeQQ|
|
||||
ALTER TABLE "exam" ALTER COLUMN "grading_rule" DROP NOT NULL;
|
||||
ALTER TABLE "exam" ALTER COLUMN "bonus_rule" DROP NOT NULL;
|
||||
ALTER TABLE "exam" ALTER COLUMN "occurrence_rule" DROP NOT NULL;
|
||||
|
||||
ALTER TABLE "exam" ALTER COLUMN "grading_rule" DROP NOT NULL;
|
||||
ALTER TABLE "exam" ALTER COLUMN "bonus_rule" DROP NOT NULL;
|
||||
ALTER TABLE "exam" ALTER COLUMN "occurrence_rule" DROP NOT NULL;
|
||||
UPDATE "exam" SET "grading_rule" = NULL WHERE "grading_rule" = '{ "rule": "manual" }';
|
||||
UPDATE "exam" SET "bonus_rule" = NULL WHERE "bonus_rule" = '{ "rule": "no-bonus"}';
|
||||
UPDATE "exam" SET "occurrence_rule" = NULL WHERE "occurrence_rule" = '"manual"';
|
||||
|
||||
UPDATE "exam" SET "grading_rule" = NULL WHERE "grading_rule" = '{ "rule": "manual" }';
|
||||
UPDATE "exam" SET "bonus_rule" = NULL WHERE "bonus_rule" = '{ "rule": "no-bonus"}';
|
||||
UPDATE "exam" SET "occurrence_rule" = NULL WHERE "occurrence_rule" = '"manual"';
|
||||
|
||||
UPDATE "exam" SET "occurrence_rule" = json_build_object('rule', "occurrence_rule");
|
||||
|]
|
||||
UPDATE "exam" SET "occurrence_rule" = json_build_object('rule', "occurrence_rule");
|
||||
|]
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
@ -979,5 +979,5 @@ clampMin, clampMax :: Ord a
|
||||
=> a -- ^ Boundary
|
||||
-> a -- ^ Value
|
||||
-> a -- ^ Clamped Value
|
||||
clampMin minVal = max minVal
|
||||
clampMax maxVal = min maxVal
|
||||
clampMin = max
|
||||
clampMax = min
|
||||
|
||||
@ -240,8 +240,7 @@ instance Arbitrary ExamGrade where
|
||||
|
||||
instance Arbitrary ExamGradingRule where
|
||||
arbitrary = oneof
|
||||
[ pure ExamGradingManual
|
||||
, ExamGradingKey . reverse . fromOffsets . map getNonNegative <$> replicateM 11 arbitrary
|
||||
[ ExamGradingKey . reverse . fromOffsets . map getNonNegative <$> replicateM 10 arbitrary
|
||||
]
|
||||
where
|
||||
fromOffsets [] = []
|
||||
|
||||
Loading…
Reference in New Issue
Block a user