1
0
forked from ScoDoc/ScoDoc

Fix: suppression de modules avec tags (cascade manquante)

This commit is contained in:
Emmanuel Viennet 2021-10-26 10:22:55 +02:00
parent 0da60384a1
commit 668210aaef
2 changed files with 42 additions and 2 deletions

View File

@ -137,6 +137,12 @@ class NotesTag(db.Model):
# Association tag <-> module # Association tag <-> module
notes_modules_tags = db.Table( notes_modules_tags = db.Table(
"notes_modules_tags", "notes_modules_tags",
db.Column("tag_id", db.Integer, db.ForeignKey("notes_tags.id")), db.Column(
db.Column("module_id", db.Integer, db.ForeignKey("notes_modules.id")), "tag_id",
db.Integer,
db.ForeignKey("notes_tags.id", ondelete="CASCADE"),
),
db.Column(
"module_id", db.Integer, db.ForeignKey("notes_modules.id", ondelete="CASCADE")
),
) )

View File

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