You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sormas-backend/src/main/resources/sql/sormas_schema.sql
+62-3Lines changed: 62 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -16360,7 +16360,7 @@ BEGIN
16360
16360
WHERE quantitativetext IS NOT NULL AND quantitativetext <> ''
16361
16361
AND length(CASE WHEN testresulttext IS NULL OR testresulttext = '' THEN quantitativetext ELSE testresulttext || E'\n' || quantitativetext END) > 4096;
16362
16362
IF truncated_count > 0 THEN
16363
-
RAISE NOTICE 'Migration 640: % pathogentest row(s) had their preserved quantitativetext truncated to fit varchar(4096).', truncated_count;
16363
+
RAISE NOTICE 'Migration 639: % pathogentest row(s) had their preserved quantitativetext truncated to fit varchar(4096).', truncated_count;
16364
16364
END IF;
16365
16365
UPDATE pathogentest
16366
16366
SET testresulttext = LEFT(CASE
@@ -16374,7 +16374,7 @@ BEGIN
16374
16374
WHERE quantitativetext IS NOT NULL AND quantitativetext <> ''
16375
16375
AND length(CASE WHEN testresulttext IS NULL OR testresulttext = '' THEN quantitativetext ELSE testresulttext || E'\n' || quantitativetext END) > 4096;
16376
16376
IF truncated_count > 0 THEN
16377
-
RAISE NOTICE 'Migration 640: % pathogentest_history row(s) had their preserved quantitativetext truncated to fit varchar(4096).', truncated_count;
16377
+
RAISE NOTICE 'Migration 639: % pathogentest_history row(s) had their preserved quantitativetext truncated to fit varchar(4096).', truncated_count;
16378
16378
END IF;
16379
16379
UPDATE pathogentest_history
16380
16380
SET testresulttext = LEFT(CASE
@@ -16402,11 +16402,70 @@ ALTER TABLE testreport_history ADD COLUMN IF NOT EXISTS fourfoldincreaseantibody
16402
16402
INSERT INTO schema_version (version_number, comment) VALUES (641, 'Malaria and Dengue DD and Lab message processing fixes');
16403
16403
16404
16404
16405
-
-- 2025-06-36 Performed by reference laboratory missing for lab messages
16405
+
-- 2025-06-26 Performed by reference laboratory missing for lab messages
16406
16406
16407
16407
ALTER TABLE testreport ADD COLUMN IF NOT EXISTS performedbyreferencelaboratory boolean;
16408
16408
ALTER TABLE testreport_history ADD COLUMN IF NOT EXISTS performedbyreferencelaboratory boolean;
16409
16409
16410
16410
INSERT INTO schema_version (version_number, comment) VALUES (642, '#14058 - Performed by reference laboratory not toggled');
16411
16411
16412
+
-- 2026-06-29 Remove Malaria-specific "Result details" pathogen test field (issue #14016)
16413
+
-- The Malaria resultdetails field duplicated the generic "Test result details" (testresulttext) field on the
16414
+
-- pathogen test form. Drop it and fold any captured value into testresulttext so no free-text result is lost.
16415
+
-- Both pathogentest and pathogentest_history are migrated.
16416
+
--
16417
+
-- versioning_trigger on pathogentest mirrors every UPDATE into pathogentest_history & disable it for the
16418
+
-- migration window so the backfill does not inject phantom audit rows, and re-enable when done.
16419
+
--
16420
+
-- testresulttext is varchar(4096) while resultdetails is varchar(255): LEFT(..., 4096) guards against a
16421
+
-- near-full testresulttext overflowing the column once resultdetails is appended.
16422
+
ALTER TABLE pathogentest DISABLE TRIGGER versioning_trigger;
16423
+
DO $$
16424
+
DECLARE
16425
+
truncated_count integer;
16426
+
BEGIN
16427
+
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = 'pathogentest' AND column_name = 'resultdetails') THEN
16428
+
SELECT count(*) INTO truncated_count FROM pathogentest
16429
+
WHERE resultdetails IS NOT NULL AND resultdetails <> ''
16430
+
AND length(CASE
16431
+
WHEN testresulttext IS NULL OR testresulttext = '' THEN resultdetails
16432
+
WHEN testresulttext = resultdetails THEN testresulttext
16433
+
ELSE testresulttext || E'\n' || resultdetails
16434
+
END) > 4096;
16435
+
IF truncated_count > 0 THEN
16436
+
RAISE NOTICE 'Migration 642: % pathogentest row(s) had their preserved resultdetails truncated to fit varchar(4096).', truncated_count;
16437
+
END IF;
16438
+
UPDATE pathogentest
16439
+
SET testresulttext = LEFT(CASE
16440
+
WHEN testresulttext IS NULL OR testresulttext = '' THEN resultdetails
16441
+
WHEN testresulttext = resultdetails THEN testresulttext
16442
+
ELSE testresulttext || E'\n' || resultdetails
16443
+
END, 4096)
16444
+
WHERE resultdetails IS NOT NULL AND resultdetails <> '';
16445
+
END IF;
16446
+
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = 'pathogentest_history' AND column_name = 'resultdetails') THEN
16447
+
SELECT count(*) INTO truncated_count FROM pathogentest_history
16448
+
WHERE resultdetails IS NOT NULL AND resultdetails <> ''
16449
+
AND length(CASE
16450
+
WHEN testresulttext IS NULL OR testresulttext = '' THEN resultdetails
16451
+
WHEN testresulttext = resultdetails THEN testresulttext
16452
+
ELSE testresulttext || E'\n' || resultdetails
16453
+
END) > 4096;
16454
+
IF truncated_count > 0 THEN
16455
+
RAISE NOTICE 'Migration 642: % pathogentest_history row(s) had their preserved resultdetails truncated to fit varchar(4096).', truncated_count;
16456
+
END IF;
16457
+
UPDATE pathogentest_history
16458
+
SET testresulttext = LEFT(CASE
16459
+
WHEN testresulttext IS NULL OR testresulttext = '' THEN resultdetails
16460
+
WHEN testresulttext = resultdetails THEN testresulttext
16461
+
ELSE testresulttext || E'\n' || resultdetails
16462
+
END, 4096)
16463
+
WHERE resultdetails IS NOT NULL AND resultdetails <> '';
16464
+
END IF;
16465
+
END $$;
16466
+
ALTER TABLE pathogentest DROP COLUMN IF EXISTS resultdetails;
16467
+
ALTER TABLE pathogentest_history DROP COLUMN IF EXISTS resultdetails;
16468
+
ALTER TABLE pathogentest ENABLE TRIGGER versioning_trigger;
16469
+
INSERT INTO schema_version (version_number, comment) VALUES (643, 'Remove Malaria-specific result details pathogen test column, preserving values into testresulttext issue #14016');
16470
+
16412
16471
-- *** Insert new sql commands BEFORE this line. Remember to always consider _history tables. ***
0 commit comments