module_type non null

This commit is contained in:
Emmanuel Viennet 2022-02-15 21:55:21 +01:00
parent a8e15c839e
commit 41b41c6c55
2 changed files with 42 additions and 1 deletions

View File

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

View File

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