From 51a84e9ac6d4b20a429613cf6576791e575bce37 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 12 Jan 2023 08:52:32 -0300 Subject: [PATCH] Fix: cascades sur modimpls --- app/models/formsemestre.py | 1 + app/models/moduleimpls.py | 6 +-- app/models/modules.py | 4 +- .../versions/7e5b519a27e1_cascade_modimpls.py | 43 +++++++++++++++++++ sco_version.py | 2 +- 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 migrations/versions/7e5b519a27e1_cascade_modimpls.py diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index c19e48a2..e985a153 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -117,6 +117,7 @@ class FormSemestre(db.Model): "ModuleImpl", backref="formsemestre", lazy="dynamic", + cascade="all, delete-orphan", ) etuds = db.relationship( "Identite", diff --git a/app/models/moduleimpls.py b/app/models/moduleimpls.py index 5b81fa1b..930909d3 100644 --- a/app/models/moduleimpls.py +++ b/app/models/moduleimpls.py @@ -20,14 +20,12 @@ class ModuleImpl(db.Model): id = db.Column(db.Integer, primary_key=True) moduleimpl_id = db.synonym("id") - module_id = db.Column( - db.Integer, - db.ForeignKey("notes_modules.id"), - ) + module_id = db.Column(db.Integer, db.ForeignKey("notes_modules.id"), nullable=False) formsemestre_id = db.Column( db.Integer, db.ForeignKey("notes_formsemestre.id"), index=True, + nullable=False, ) responsable_id = db.Column("responsable_id", db.Integer, db.ForeignKey("user.id")) # formule de calcul moyenne: diff --git a/app/models/modules.py b/app/models/modules.py index 77c06274..d4c70c03 100644 --- a/app/models/modules.py +++ b/app/models/modules.py @@ -37,7 +37,9 @@ class Module(db.Model): # Type: ModuleType.STANDARD, MALUS, RESSOURCE, SAE (enum) module_type = db.Column(db.Integer, nullable=False, default=0, server_default="0") # Relations: - modimpls = db.relationship("ModuleImpl", backref="module", lazy="dynamic") + modimpls = db.relationship( + "ModuleImpl", backref="module", lazy="dynamic", cascade="all, delete-orphan" + ) ues_apc = db.relationship("UniteEns", secondary="module_ue_coef", viewonly=True) tags = db.relationship( "NotesTag", diff --git a/migrations/versions/7e5b519a27e1_cascade_modimpls.py b/migrations/versions/7e5b519a27e1_cascade_modimpls.py new file mode 100644 index 00000000..42870d01 --- /dev/null +++ b/migrations/versions/7e5b519a27e1_cascade_modimpls.py @@ -0,0 +1,43 @@ +"""cascade_modimpls + +Revision ID: 7e5b519a27e1 +Revises: 554c13cea377 +Create Date: 2023-01-12 08:49:01.744120 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "7e5b519a27e1" +down_revision = "554c13cea377" +branch_labels = None +depends_on = None + + +def upgrade(): + # + op.execute("DELETE FROM notes_moduleimpl WHERE module_id is NULL;") + op.alter_column( + "notes_moduleimpl", "module_id", existing_type=sa.INTEGER(), nullable=False + ) + op.execute("DELETE FROM notes_moduleimpl WHERE formsemestre_id is NULL;") + op.alter_column( + "notes_moduleimpl", + "formsemestre_id", + existing_type=sa.INTEGER(), + nullable=False, + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "notes_moduleimpl", "formsemestre_id", existing_type=sa.INTEGER(), nullable=True + ) + op.alter_column( + "notes_moduleimpl", "module_id", existing_type=sa.INTEGER(), nullable=True + ) + # ### end Alembic commands ### diff --git a/sco_version.py b/sco_version.py index 0a6f9c9a..96130c74 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.4.25" +SCOVERSION = "9.4.26" SCONAME = "ScoDoc"