From 1f23ce68a43378727e8212a64b64e54fe9d02e27 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 9 Jan 2023 08:12:31 -0300 Subject: [PATCH] Contraint champs formsemestre non nulls --- app/models/formsemestre.py | 11 ++-- .../554c13cea377_formsemestre_not_nulls.py | 66 +++++++++++++++++++ 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/554c13cea377_formsemestre_not_nulls.py diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index a7f816ae88..c19e48a2b0 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -56,9 +56,9 @@ class FormSemestre(db.Model): dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True) formation_id = db.Column(db.Integer, db.ForeignKey("notes_formations.id")) semestre_id = db.Column(db.Integer, nullable=False, default=1, server_default="1") - titre = db.Column(db.Text()) - date_debut = db.Column(db.Date()) - date_fin = db.Column(db.Date()) + titre = db.Column(db.Text(), nullable=False) + date_debut = db.Column(db.Date(), nullable=False) + date_fin = db.Column(db.Date(), nullable=False) etat = db.Column( db.Boolean(), nullable=False, default=True, server_default="true" ) # False si verrouillé @@ -87,7 +87,10 @@ class FormSemestre(db.Model): ) # couleur fond bulletins HTML: bul_bgcolor = db.Column( - db.String(SHORT_STR_LEN), default="white", server_default="white" + db.String(SHORT_STR_LEN), + default="white", + server_default="white", + nullable=False, ) # autorise resp. a modifier semestre: resp_can_edit = db.Column( diff --git a/migrations/versions/554c13cea377_formsemestre_not_nulls.py b/migrations/versions/554c13cea377_formsemestre_not_nulls.py new file mode 100644 index 0000000000..a7cdc9e58b --- /dev/null +++ b/migrations/versions/554c13cea377_formsemestre_not_nulls.py @@ -0,0 +1,66 @@ +"""formsemestre_not_nulls + +Revision ID: 554c13cea377 +Revises: 3c12f5850cff +Create Date: 2023-01-09 08:02:53.637488 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "554c13cea377" +down_revision = "3c12f5850cff" +branch_labels = None +depends_on = None + + +def upgrade(): + # + op.execute("UPDATE notes_formsemestre SET titre = '' WHERE titre is NULL;") + op.alter_column( + "notes_formsemestre", "titre", existing_type=sa.TEXT(), nullable=False + ) + op.execute( + "UPDATE notes_formsemestre SET date_debut = now() WHERE date_debut is NULL;" + ) + op.alter_column( + "notes_formsemestre", "date_debut", existing_type=sa.DATE(), nullable=False + ) + op.execute("UPDATE notes_formsemestre SET date_fin = now() WHERE date_fin is NULL;") + op.alter_column( + "notes_formsemestre", "date_fin", existing_type=sa.DATE(), nullable=False + ) + op.execute( + "UPDATE notes_formsemestre SET bul_bgcolor = 'white' WHERE bul_bgcolor is NULL;" + ) + op.alter_column( + "notes_formsemestre", + "bul_bgcolor", + existing_type=sa.VARCHAR(length=32), + nullable=False, + existing_server_default=sa.text("'white'::character varying"), + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "notes_formsemestre", + "bul_bgcolor", + existing_type=sa.VARCHAR(length=32), + nullable=True, + existing_server_default=sa.text("'white'::character varying"), + ) + op.alter_column( + "notes_formsemestre", "date_fin", existing_type=sa.DATE(), nullable=True + ) + op.alter_column( + "notes_formsemestre", "date_debut", existing_type=sa.DATE(), nullable=True + ) + op.alter_column( + "notes_formsemestre", "titre", existing_type=sa.TEXT(), nullable=True + ) + # ### end Alembic commands ###