From 1ccb387e5989ccc1e5b34252f1c33b602302f197 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 21 Sep 2022 13:16:31 +0200 Subject: [PATCH] =?UTF-8?q?Missing=20cascade:=20Suppression=20modimpls=20a?= =?UTF-8?q?vec=20enseignants=20associ=C3=A9s=20Fix=20#495?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/moduleimpls.py | 4 +- ..._cascades_sur_notes_modules_enseignants.py | 74 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 migrations/versions/6bc3f51154b4_cascades_sur_notes_modules_enseignants.py diff --git a/app/models/moduleimpls.py b/app/models/moduleimpls.py index a7aadcba..984f3a29 100644 --- a/app/models/moduleimpls.py +++ b/app/models/moduleimpls.py @@ -108,9 +108,9 @@ notes_modules_enseignants = db.Table( db.Column( "moduleimpl_id", db.Integer, - db.ForeignKey("notes_moduleimpl.id"), + db.ForeignKey("notes_moduleimpl.id", ondelete="CASCADE"), ), - db.Column("ens_id", db.Integer, db.ForeignKey("user.id")), + db.Column("ens_id", db.Integer, db.ForeignKey("user.id", ondelete="CASCADE")), # ? db.UniqueConstraint("moduleimpl_id", "ens_id"), ) # XXX il manque probablement une relation pour gérer cela diff --git a/migrations/versions/6bc3f51154b4_cascades_sur_notes_modules_enseignants.py b/migrations/versions/6bc3f51154b4_cascades_sur_notes_modules_enseignants.py new file mode 100644 index 00000000..0f6f65f8 --- /dev/null +++ b/migrations/versions/6bc3f51154b4_cascades_sur_notes_modules_enseignants.py @@ -0,0 +1,74 @@ +"""Cascades sur notes_modules_enseignants + +Revision ID: 6bc3f51154b4 +Revises: 814e8e37d082 +Create Date: 2022-09-21 13:12:47.850227 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "6bc3f51154b4" +down_revision = "814e8e37d082" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint( + "notes_modules_enseignants_moduleimpl_id_fkey", + "notes_modules_enseignants", + type_="foreignkey", + ) + op.drop_constraint( + "notes_modules_enseignants_ens_id_fkey", + "notes_modules_enseignants", + type_="foreignkey", + ) + op.create_foreign_key( + None, + "notes_modules_enseignants", + "user", + ["ens_id"], + ["id"], + ondelete="CASCADE", + ) + op.create_foreign_key( + None, + "notes_modules_enseignants", + "notes_moduleimpl", + ["moduleimpl_id"], + ["id"], + ondelete="CASCADE", + ) + op.alter_column("role", "name", existing_type=sa.VARCHAR(length=64), nullable=False) + op.drop_constraint("role_name_key", "role", type_="unique") + op.create_index(op.f("ix_role_name"), "role", ["name"], unique=True) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f("ix_role_name"), table_name="role") + op.create_unique_constraint("role_name_key", "role", ["name"]) + op.alter_column("role", "name", existing_type=sa.VARCHAR(length=64), nullable=True) + op.drop_constraint(None, "notes_modules_enseignants", type_="foreignkey") + op.drop_constraint(None, "notes_modules_enseignants", type_="foreignkey") + op.create_foreign_key( + "notes_modules_enseignants_ens_id_fkey", + "notes_modules_enseignants", + "user", + ["ens_id"], + ["id"], + ) + op.create_foreign_key( + "notes_modules_enseignants_moduleimpl_id_fkey", + "notes_modules_enseignants", + "notes_moduleimpl", + ["moduleimpl_id"], + ["id"], + ) + # ### end Alembic commands ###