diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index f02a19c75e..148d9c8714 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -325,10 +325,15 @@ class NotesSemSet(db.Model): sem_id = db.Column(db.Integer, nullable=True, default=None) -# Association: +# Association: many to many notes_semset_formsemestre = db.Table( "notes_semset_formsemestre", db.Column("formsemestre_id", db.Integer, db.ForeignKey("notes_formsemestre.id")), - db.Column("semset_id", db.Integer, db.ForeignKey("notes_semset.id")), + db.Column( + "semset_id", + db.Integer, + db.ForeignKey("notes_semset.id", ondelete="CASCADE"), + nullable=False, + ), db.UniqueConstraint("formsemestre_id", "semset_id"), ) diff --git a/migrations/versions/a217bf588f4c_scodoc_9_0_13_essai_cascade.py b/migrations/versions/a217bf588f4c_scodoc_9_0_13_essai_cascade.py new file mode 100644 index 0000000000..3e0c53b5e3 --- /dev/null +++ b/migrations/versions/a217bf588f4c_scodoc_9_0_13_essai_cascade.py @@ -0,0 +1,36 @@ +"""ScoDoc 9.0.13: essai cascade + +Revision ID: a217bf588f4c +Revises: f73251d1d825 +Create Date: 2021-09-10 21:44:34.947317 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'a217bf588f4c' +down_revision = 'f73251d1d825' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('notes_semset_formsemestre', 'semset_id', + existing_type=sa.INTEGER(), + nullable=False) + op.drop_constraint('notes_semset_formsemestre_semset_id_fkey', 'notes_semset_formsemestre', type_='foreignkey') + op.create_foreign_key(None, 'notes_semset_formsemestre', 'notes_semset', ['semset_id'], ['id'], ondelete='CASCADE') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'notes_semset_formsemestre', type_='foreignkey') + op.create_foreign_key('notes_semset_formsemestre_semset_id_fkey', 'notes_semset_formsemestre', 'notes_semset', ['semset_id'], ['id']) + op.alter_column('notes_semset_formsemestre', 'semset_id', + existing_type=sa.INTEGER(), + nullable=True) + # ### end Alembic commands ###