~edwargix/git.sr.ht

1048906cf1ba1d00b42207930f71b6f33c0a55ba — Drew DeVault 6 years ago 61fb547
Fix repo deletion with active webhooks
A gitsrht/alembic/versions/ddca72f1b7e2_fix_cascades_on_webhook_tables.py => gitsrht/alembic/versions/ddca72f1b7e2_fix_cascades_on_webhook_tables.py +61 -0
@@ 0,0 1,61 @@
"""Fix cascades on webhook tables

Revision ID: ddca72f1b7e2
Revises: 61b01f874da8
Create Date: 2019-07-29 11:57:14.486544

"""

# revision identifiers, used by Alembic.
revision = 'ddca72f1b7e2'
down_revision = '61b01f874da8'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.drop_constraint(
            constraint_name="repo_webhook_delivery_subscription_id_fkey",
            table_name="repo_webhook_delivery",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="repo_webhook_delivery_subscription_id_fkey",
            source_table="repo_webhook_delivery",
            referent_table="repo_webhook_subscription",
            local_cols=["subscription_id"],
            remote_cols=["id"],
            ondelete="CASCADE")
    op.drop_constraint(
            constraint_name="user_webhook_delivery_subscription_id_fkey",
            table_name="user_webhook_delivery",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="user_webhook_delivery_subscription_id_fkey",
            source_table="user_webhook_delivery",
            referent_table="user_webhook_subscription",
            local_cols=["subscription_id"],
            remote_cols=["id"],
            ondelete="CASCADE")

def downgrade():
    op.drop_constraint(
            constraint_name="repo_webhook_delivery_subscription_id_fkey",
            table_name="repo_webhook_delivery",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="repo_webhook_delivery_subscription_id_fkey",
            source_table="repo_webhook_delivery",
            referent_table="repo_webhook_subscription",
            local_cols=["subscription_id"],
            remote_cols=["id"])
    op.drop_constraint(
            constraint_name="user_webhook_delivery_subscription_id_fkey",
            table_name="user_webhook_delivery",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="user_webhook_delivery_subscription_id_fkey",
            source_table="user_webhook_delivery",
            referent_table="user_webhook_subscription",
            local_cols=["subscription_id"],
            remote_cols=["id"])

M gitsrht/repos.py => gitsrht/repos.py +6 -0
@@ 28,3 28,9 @@ class GitRepoApi(SimpleRepoApi):
                post_update,
                os.path.join(repo.path, "hooks", "post-update")
            ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

    def do_delete_repo(self, repo):
        from gitsrht.webhooks import RepoWebhook
        RepoWebhook.Subscription.query.filter(
                RepoWebhook.Subscription.repo_id == repo.id).delete()
        super().do_delete_repo(repo)