Add cascading delete constraint to DynamicChallenge

1386-proper-deletion-constraint-for-dynamics
Kevin Chung 2020-05-06 12:46:51 -04:00
parent 818a4568a3
commit 364273f1f1
2 changed files with 32 additions and 1 deletions

View File

@ -239,7 +239,9 @@ class DynamicValueChallenge(BaseChallenge):
class DynamicChallenge(Challenges):
__mapper_args__ = {"polymorphic_identity": "dynamic"}
id = db.Column(None, db.ForeignKey("challenges.id"), primary_key=True)
id = db.Column(
None, db.ForeignKey("challenges.id", ondelete="CASCADE"), primary_key=True
)
initial = db.Column(db.Integer, default=0)
minimum = db.Column(db.Integer, default=0)
decay = db.Column(db.Integer, default=0)

View File

@ -0,0 +1,29 @@
"""Add cascading delete to dynamic challenges
Revision ID: b37fb68807ea
Revises: 1093835a1051
Create Date: 2020-05-06 12:21:39.373983
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = 'b37fb68807ea'
down_revision = '1093835a1051'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'dynamic_challenge', type_='foreignkey')
op.create_foreign_key(None, 'dynamic_challenge', 'challenges', ['id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'dynamic_challenge', type_='foreignkey')
op.create_foreign_key(None, 'dynamic_challenge', 'challenges', ['id'], ['id'])
# ### end Alembic commands ###