diff --git a/migrations/versions/829683efddc4_change_apcvalidationannee.py b/migrations/versions/829683efddc4_change_apcvalidationannee.py index a2353e69..79152d57 100644 --- a/migrations/versions/829683efddc4_change_apcvalidationannee.py +++ b/migrations/versions/829683efddc4_change_apcvalidationannee.py @@ -77,19 +77,17 @@ def upgrade(): ["id"], ) # Efface les validations d'année dupliquées - # (garde le premier code dans l'ordre alphabétique... mieux que rien) + # (garde la validation la plus récente) session.execute( sa.text( """ DELETE FROM apc_validation_annee t1 - WHERE EXISTS ( - SELECT 1 - FROM apc_validation_annee t2 - WHERE t1.etudid = t2.etudid + WHERE t1.id <> (SELECT max(t2.id) + FROM apc_validation_annee t2 + WHERE t1.etudid = t2.etudid AND t1.referentiel_competence_id = t2.referentiel_competence_id AND t1.ordre = t2.ordre - AND t1.code > t2.code - ); + ) """ ) )