From 41b41c6c556c57e7d0d2143befa061db981f5a89 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 15 Feb 2022 21:55:21 +0100 Subject: [PATCH] module_type non null --- app/models/modules.py | 2 +- .../b9aadc10227f_module_type_non_null.py | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/b9aadc10227f_module_type_non_null.py diff --git a/app/models/modules.py b/app/models/modules.py index 393cc8c0..5a5f4761 100644 --- a/app/models/modules.py +++ b/app/models/modules.py @@ -34,7 +34,7 @@ class Module(db.Model): # id de l'element pedagogique Apogee correspondant: code_apogee = db.Column(db.String(APO_CODE_STR_LEN)) # Type: ModuleType: DEFAULT, MALUS, RESSOURCE, MODULE_SAE (enum) - module_type = db.Column(db.Integer) + module_type = db.Column(db.Integer, nullable=False, default=0, server_default="0") # Relations: modimpls = db.relationship("ModuleImpl", backref="module", lazy="dynamic") ues_apc = db.relationship("UniteEns", secondary="module_ue_coef", viewonly=True) diff --git a/migrations/versions/b9aadc10227f_module_type_non_null.py b/migrations/versions/b9aadc10227f_module_type_non_null.py new file mode 100644 index 00000000..1758c3d2 --- /dev/null +++ b/migrations/versions/b9aadc10227f_module_type_non_null.py @@ -0,0 +1,41 @@ +"""module_type_non_null + +Revision ID: b9aadc10227f +Revises: bd2c1c3d866e +Create Date: 2022-02-15 21:47:29.212329 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql +from sqlalchemy.orm import sessionmaker # added by ev + +# revision identifiers, used by Alembic. +revision = "b9aadc10227f" +down_revision = "bd2c1c3d866e" +branch_labels = None +depends_on = None + +Session = sessionmaker() + + +def upgrade(): + # Added by ev: remove duplicates + bind = op.get_bind() + session = Session(bind=bind) + session.execute( + """UPDATE notes_modules SET module_type=0 WHERE module_type IS NULL;""" + ) + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "notes_modules", "module_type", existing_type=sa.INTEGER(), nullable=False + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "notes_modules", "module_type", existing_type=sa.INTEGER(), nullable=True + ) + # ### end Alembic commands ###