Etat civil: modifie contraintes dans script migration

This commit is contained in:
Emmanuel Viennet 2023-05-11 15:34:39 +02:00
parent 590dd2e8b5
commit 153f4783c3
2 changed files with 24 additions and 11 deletions

View File

@ -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) # données d'état-civil. Si présent remplace les données d'usage dans les documents officiels (bulletins, PV)
# cf nomprenom_etat_civil() # cf nomprenom_etat_civil()
civilite_etat_civil = db.Column(db.String(1), nullable=False, server_default="X") 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) date_naissance = db.Column(db.Date)
lieu_naissance = db.Column(db.Text()) lieu_naissance = db.Column(db.Text())

View File

@ -17,17 +17,30 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - checked ### # ### commands auto generated by Alembic - please adjust! ###
op.add_column( with op.batch_alter_table("identite", schema=None) as batch_op:
"identite", batch_op.add_column(
sa.Column("civilite_etat_civil", sa.Text(), nullable=True, server_default="X"), sa.Column(
) "civilite_etat_civil",
op.add_column("identite", sa.Column("prenom_etat_civil", sa.Text(), nullable=True)) 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 ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - checked ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_column("identite", "prenom_etat_civil") with op.batch_alter_table("identite", schema=None) as batch_op:
op.drop_column("identite", "civilite_etat_civil") batch_op.drop_column("prenom_etat_civil")
# ### end Alembic commands ### batch_op.drop_column("civilite_etat_civil")