From 9f45f1ee719c8d51f3d2fe89e982b3b5e36625b4 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 15 Mar 2023 19:13:45 +0100 Subject: [PATCH] Fix cascade sur modimpl/abs --- app/models/absences.py | 4 +- .../6520faf67508_fix_cascade_abs_mod.py | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 migrations/versions/6520faf67508_fix_cascade_abs_mod.py diff --git a/app/models/absences.py b/app/models/absences.py index e4bbd823..d31d9e27 100644 --- a/app/models/absences.py +++ b/app/models/absences.py @@ -24,10 +24,8 @@ class Absence(db.Model): # moduleimpid concerne (optionnel): moduleimpl_id = db.Column( db.Integer, - db.ForeignKey("notes_moduleimpl.id"), + db.ForeignKey("notes_moduleimpl.id", ondelete="SET NULL"), ) - # XXX TODO: contrainte ajoutée: vérifier suppression du module - # (mettre à NULL sans supprimer) def to_dict(self): data = { diff --git a/migrations/versions/6520faf67508_fix_cascade_abs_mod.py b/migrations/versions/6520faf67508_fix_cascade_abs_mod.py new file mode 100644 index 00000000..9611eb76 --- /dev/null +++ b/migrations/versions/6520faf67508_fix_cascade_abs_mod.py @@ -0,0 +1,43 @@ +"""fix_cascade_abs_mod + +Revision ID: 6520faf67508 +Revises: 19a608ebc9b7 +Create Date: 2023-03-15 19:07:15.152610 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "6520faf67508" +down_revision = "19a608ebc9b7" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint("absences_moduleimpl_id_fkey", "absences", type_="foreignkey") + op.create_foreign_key( + "absences_moduleimpl_id_fkey", + "absences", + "notes_moduleimpl", + ["moduleimpl_id"], + ["id"], + ondelete="SET NULL", + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint("absences_moduleimpl_id_fkey", "absences", type_="foreignkey") + op.create_foreign_key( + "absences_moduleimpl_id_fkey", + "absences", + "notes_moduleimpl", + ["moduleimpl_id"], + ["id"], + ) + # ### end Alembic commands ###