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)
# 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())

View File

@ -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")