diff --git a/app/models/etudiants.py b/app/models/etudiants.py index fb98e98b1c..61f34296b1 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 8b13136ad3..e0b4ce154f 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")