From 668210aaefa0e64b1ef248d9dd8a7ed5c1d633c3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 26 Oct 2021 10:22:55 +0200 Subject: [PATCH] Fix: suppression de modules avec tags (cascade manquante) --- app/models/formations.py | 10 ++++-- .../75cf18659984_cascade_tags_modules.py | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 migrations/versions/75cf18659984_cascade_tags_modules.py diff --git a/app/models/formations.py b/app/models/formations.py index bb8229115..c4f81e521 100644 --- a/app/models/formations.py +++ b/app/models/formations.py @@ -137,6 +137,12 @@ class NotesTag(db.Model): # Association tag <-> module notes_modules_tags = db.Table( "notes_modules_tags", - db.Column("tag_id", db.Integer, db.ForeignKey("notes_tags.id")), - db.Column("module_id", db.Integer, db.ForeignKey("notes_modules.id")), + db.Column( + "tag_id", + db.Integer, + db.ForeignKey("notes_tags.id", ondelete="CASCADE"), + ), + db.Column( + "module_id", db.Integer, db.ForeignKey("notes_modules.id", ondelete="CASCADE") + ), ) diff --git a/migrations/versions/75cf18659984_cascade_tags_modules.py b/migrations/versions/75cf18659984_cascade_tags_modules.py new file mode 100644 index 000000000..1a498b070 --- /dev/null +++ b/migrations/versions/75cf18659984_cascade_tags_modules.py @@ -0,0 +1,34 @@ +"""cascade tags modules + +Revision ID: 75cf18659984 +Revises: d74b4e16fb3c +Create Date: 2021-10-26 10:17:15.547905 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '75cf18659984' +down_revision = 'd74b4e16fb3c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint('notes_modules_tags_tag_id_fkey', 'notes_modules_tags', type_='foreignkey') + op.drop_constraint('notes_modules_tags_module_id_fkey', 'notes_modules_tags', type_='foreignkey') + op.create_foreign_key(None, 'notes_modules_tags', 'notes_tags', ['tag_id'], ['id'], ondelete='CASCADE') + op.create_foreign_key(None, 'notes_modules_tags', 'notes_modules', ['module_id'], ['id'], ondelete='CASCADE') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'notes_modules_tags', type_='foreignkey') + op.drop_constraint(None, 'notes_modules_tags', type_='foreignkey') + op.create_foreign_key('notes_modules_tags_module_id_fkey', 'notes_modules_tags', 'notes_modules', ['module_id'], ['id']) + op.create_foreign_key('notes_modules_tags_tag_id_fkey', 'notes_modules_tags', 'notes_tags', ['tag_id'], ['id']) + # ### end Alembic commands ###