Skip to content

Commit

Permalink
Merge pull request #665 from Opetushallitus/pkalliok-EH-1757-cleanup-…
Browse files Browse the repository at this point in the history
…migration

EH-1757: remove duplicate palaute records from DB
  • Loading branch information
pkalliok authored Jan 9, 2025
2 parents 67e4492 + 67fe34a commit 2b4756d
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 2b4756d

Please sign in to comment.