From 153f4783c388e88af3a89fd6db2d00995f76b969 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 11 May 2023 15:34:39 +0200 Subject: [PATCH] Etat civil: modifie contraintes dans script migration --- app/models/etudiants.py | 2 +- ...ca6f6_ajout_prenom_civilite__etat_civil.py | 33 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/models/etudiants.py b/app/models/etudiants.py index fb98e98b..61f34296 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -46,7 +46,7 @@ class Identite(db.Model): # données d'état-civil. Si présent remplace les données d'usage dans les documents officiels (bulletins, PV) # cf nomprenom_etat_civil() civilite_etat_civil = db.Column(db.String(1), nullable=False, server_default="X") - prenom_etat_civil = db.Column(db.Text(), nullable=True) + prenom_etat_civil = db.Column(db.Text(), nullable=False, server_default="") date_naissance = db.Column(db.Date) lieu_naissance = db.Column(db.Text()) diff --git a/migrations/versions/cf29790ca6f6_ajout_prenom_civilite__etat_civil.py b/migrations/versions/cf29790ca6f6_ajout_prenom_civilite__etat_civil.py index 8b13136a..e0b4ce15 100644 --- a/migrations/versions/cf29790ca6f6_ajout_prenom_civilite__etat_civil.py +++ b/migrations/versions/cf29790ca6f6_ajout_prenom_civilite__etat_civil.py @@ -17,17 +17,30 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - checked ### - op.add_column( - "identite", - sa.Column("civilite_etat_civil", sa.Text(), nullable=True, server_default="X"), - ) - op.add_column("identite", sa.Column("prenom_etat_civil", sa.Text(), nullable=True)) + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("identite", schema=None) as batch_op: + batch_op.add_column( + sa.Column( + "civilite_etat_civil", + sa.String(length=1), + server_default="X", + nullable=False, + ) + ) + batch_op.add_column( + sa.Column("prenom_etat_civil", sa.Text(), server_default="", nullable=False) + ) + + batch_op.create_check_constraint( + "identite_civ_etat_civ_check", + "civilite_etat_civil IN ('M', 'F', 'X')", + ) + # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - checked ### - op.drop_column("identite", "prenom_etat_civil") - op.drop_column("identite", "civilite_etat_civil") - # ### end Alembic commands ### + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("identite", schema=None) as batch_op: + batch_op.drop_column("prenom_etat_civil") + batch_op.drop_column("civilite_etat_civil")