Skip to content

Commit

Permalink
EH-1757: remove duplicate palaute records from DB
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pkalliok committed Jan 9, 2025
1 parent 67e4492 commit 67fe34a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/db/migration/V1_1736423100280__palaute_duplicate_cleanup.sql
Original file line number Diff line number Diff line change
@@ -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
);

0 comments on commit 67fe34a

Please sign in to comment.