Contraint champs formsemestre non nulls

This commit is contained in:
Emmanuel Viennet 2023-01-09 08:12:31 -03:00
parent d0463fa146
commit 1f23ce68a4
2 changed files with 73 additions and 4 deletions

View File

@ -56,9 +56,9 @@ class FormSemestre(db.Model):
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True) dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True)
formation_id = db.Column(db.Integer, db.ForeignKey("notes_formations.id")) formation_id = db.Column(db.Integer, db.ForeignKey("notes_formations.id"))
semestre_id = db.Column(db.Integer, nullable=False, default=1, server_default="1") semestre_id = db.Column(db.Integer, nullable=False, default=1, server_default="1")
titre = db.Column(db.Text()) titre = db.Column(db.Text(), nullable=False)
date_debut = db.Column(db.Date()) date_debut = db.Column(db.Date(), nullable=False)
date_fin = db.Column(db.Date()) date_fin = db.Column(db.Date(), nullable=False)
etat = db.Column( etat = db.Column(
db.Boolean(), nullable=False, default=True, server_default="true" db.Boolean(), nullable=False, default=True, server_default="true"
) # False si verrouillé ) # False si verrouillé
@ -87,7 +87,10 @@ class FormSemestre(db.Model):
) )
# couleur fond bulletins HTML: # couleur fond bulletins HTML:
bul_bgcolor = db.Column( 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: # autorise resp. a modifier semestre:
resp_can_edit = db.Column( resp_can_edit = db.Column(

View File

@ -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 ###