From 07acadd5950f981b74908a488383275c6b3f6c61 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 28 Jun 2023 10:09:56 +0200 Subject: [PATCH] =?UTF-8?q?Modifie=20contrainte=20sur=20ApcValidationAnnee?= =?UTF-8?q?=20(une=20modif=20plus=20s=C3=A9rieuse=20est=20n=C3=A9cessaire)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/but/jury_but.py | 2 +- app/models/but_validations.py | 8 ++-- .../829683efddc4_change_apcvalidationannee.py | 44 +++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/829683efddc4_change_apcvalidationannee.py diff --git a/app/but/jury_but.py b/app/but/jury_but.py index 31367a98e..97ab95aca 100644 --- a/app/but/jury_but.py +++ b/app/but/jury_but.py @@ -695,7 +695,7 @@ class DecisionsProposeesAnnee(DecisionsProposees): code=code, ) else: # Update validation année BUT - self.validation.etud = self.etud + assert self.validation.etudid == self.etud.id self.validation.formsemestre = self.formsemestre_impair self.validation.formation_id = self.formsemestre.formation_id self.validation.ordre = self.annee_but diff --git a/app/models/but_validations.py b/app/models/but_validations.py index 00dc61952..997d1a46f 100644 --- a/app/models/but_validations.py +++ b/app/models/but_validations.py @@ -170,7 +170,9 @@ class ApcValidationAnnee(db.Model): __tablename__ = "apc_validation_annee" # Assure unicité de la décision: - __table_args__ = (db.UniqueConstraint("etudid", "annee_scolaire", "ordre"),) + __table_args__ = ( + db.UniqueConstraint("etudid", "ordre", "formation_id"), + ) # il aurait été plus intelligent de mettre ici le refcomp id = db.Column(db.Integer, primary_key=True) etudid = db.Column( db.Integer, @@ -183,8 +185,8 @@ class ApcValidationAnnee(db.Model): formsemestre_id = db.Column( db.Integer, db.ForeignKey("notes_formsemestre.id"), nullable=True ) - "le semestre origine, normalement l'IMPAIR (le 1er) de l'année" - formation_id = db.Column( + "le semestre IMPAIR (le 1er) de l'année" + formation_id = db.Column( # il aurait été plus intelligent de mettre ici le refcomp db.Integer, db.ForeignKey("notes_formations.id"), nullable=False, diff --git a/migrations/versions/829683efddc4_change_apcvalidationannee.py b/migrations/versions/829683efddc4_change_apcvalidationannee.py new file mode 100644 index 000000000..8955a1a3d --- /dev/null +++ b/migrations/versions/829683efddc4_change_apcvalidationannee.py @@ -0,0 +1,44 @@ +"""Change ApcValidationAnnee + +Revision ID: 829683efddc4 +Revises: c701224fa255 +Create Date: 2023-06-28 09:47:16.591028 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "829683efddc4" +down_revision = "c701224fa255" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("apc_validation_annee", schema=None) as batch_op: + batch_op.drop_constraint( + "apc_validation_annee_etudid_annee_scolaire_ordre_key", type_="unique" + ) + # batch_op.create_unique_constraint( + # "apc_validation_annee_etudid_formation_ordre_key", + # ["etudid", "ordre", "formation_id"], + # ) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("apc_validation_annee", schema=None) as batch_op: + # batch_op.drop_constraint( + # "apc_validation_annee_etudid_formation_ordre_key", type_="unique" + # ) + batch_op.create_unique_constraint( + "apc_validation_annee_etudid_annee_scolaire_ordre_key", + ["etudid", "annee_scolaire", "ordre"], + ) + + # ### end Alembic commands ###