From 310593b20d0b0d65bac6b20fb28837c88d8f3d11 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 18 2017 16:33:19 +0000 Subject: Add an alembic revision dropping the pull_request_check constraints That constraints is making sure the pull-request is either coming from a fork or a remote git repository. Except that when we delete the fork, we still want to keep the pull-request records, so we can no longer enforce that constraint. Signed-off-by: Pierre-Yves Chibon --- diff --git a/alembic/versions/46df6466b8fa_drop_pull_request_check.py b/alembic/versions/46df6466b8fa_drop_pull_request_check.py new file mode 100644 index 0000000..95320dd --- /dev/null +++ b/alembic/versions/46df6466b8fa_drop_pull_request_check.py @@ -0,0 +1,36 @@ +"""drop pull_request_check + +Revision ID: 46df6466b8fa +Revises: 61ac23e35f86 +Create Date: 2017-12-18 12:37:44.833468 + +""" + +# revision identifiers, used by Alembic. +revision = '46df6466b8fa' +down_revision = '61ac23e35f86' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + """ Drop the pull_request_check constraint. """ + connection = op.get_bind() + connection.begin_nested() + try: + op.drop_constraint("pull_requests_check", "pull_requests") + except sa.exc.ProgrammingError: + connection.connection.connection.rollback() + print( + 'Ignoring the pull_requests_check ' + 'constraint if it does not exist') + + +def downgrade(): + """ Bring back the pull_request_check constraint. """ + op.create_check_constraint( + "pull_requests_check", + "pull_requests", + 'NOT(project_id_from IS NULL AND remote_git IS NULL)' + )