Fix: cascades sur modimpls

This commit is contained in:
Emmanuel Viennet 2023-01-12 08:52:32 -03:00
parent 61575c43ac
commit 51a84e9ac6
5 changed files with 50 additions and 6 deletions

View File

@ -117,6 +117,7 @@ class FormSemestre(db.Model):
"ModuleImpl",
backref="formsemestre",
lazy="dynamic",
cascade="all, delete-orphan",
)
etuds = db.relationship(
"Identite",

View File

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

View File

@ -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",

View File

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

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.4.25"
SCOVERSION = "9.4.26"
SCONAME = "ScoDoc"