From 67fe34a9f1f89bd79a97313f33c7015fb22c7f89 Mon Sep 17 00:00:00 2001 From: Panu Kalliokoski Date: Thu, 9 Jan 2025 13:55:42 +0200 Subject: [PATCH] EH-1757: remove duplicate palaute records from DB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These records have been accumulating because of mistakes in palaute logic, but they really shouldn't be there. Every HOKS should have one or zero aloituskysely, one or zero päättökysely (either valmistuneet or osia_suorittaneet) and one or zero työelämäkysely for each of its työpaikkajaksot. --- ...36423100280__palaute_duplicate_cleanup.sql | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/db/migration/V1_1736423100280__palaute_duplicate_cleanup.sql diff --git a/src/db/migration/V1_1736423100280__palaute_duplicate_cleanup.sql b/src/db/migration/V1_1736423100280__palaute_duplicate_cleanup.sql new file mode 100644 index 000000000..448d4ff2d --- /dev/null +++ b/src/db/migration/V1_1736423100280__palaute_duplicate_cleanup.sql @@ -0,0 +1,22 @@ + +DELETE FROM palautteet p1 +WHERE p1.jakson_yksiloiva_tunniste IS NULL +AND EXISTS ( + SELECT 1 FROM palautteet p2 + WHERE p1.hoks_id = p2.hoks_id + AND p1.kyselytyyppi = p2.kyselytyyppi + AND p2.jakson_yksiloiva_tunniste IS NULL + -- here we should also have a condition of having the same + -- rahoituskausi, but it's not needed yet because these have + -- accumulated only on RK 2024-2025 + AND p1.created_at < p2.created_at +); + +DELETE FROM palautteet p1 +WHERE EXISTS ( + SELECT 1 FROM palautteet p2 + WHERE p1.hoks_id = p2.hoks_id + AND p1.jakson_yksiloiva_tunniste = p2.jakson_yksiloiva_tunniste + AND p1.created_at < p2.created_at +); +