61ac23e35f86_fix_pr_project_from_key.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Fix pr project_from key
  2. Revision ID: 61ac23e35f86
  3. Revises: 47f5fab6f46a
  4. Create Date: 2017-12-05 16:59:17.117199
  5. """
  6. # revision identifiers, used by Alembic.
  7. revision = '61ac23e35f86'
  8. down_revision = '47f5fab6f46a'
  9. from alembic import op
  10. import sqlalchemy as sa
  11. def upgrade():
  12. """ Alter the pull_requests table to update the foreign key to set null
  13. on delete.
  14. """
  15. op.drop_constraint(
  16. 'pull_requests_project_id_from_fkey',
  17. 'pull_requests',
  18. type_='foreignkey')
  19. op.create_foreign_key(
  20. name='pull_requests_project_id_from_fkey',
  21. source_table='pull_requests',
  22. referent_table='projects',
  23. local_cols=['project_id_from'],
  24. remote_cols=['id'],
  25. onupdate='cascade',
  26. ondelete='set null',
  27. )
  28. def downgrade():
  29. """ Alter the pull_requests table to update the foreign key to cascade
  30. on delete.
  31. """
  32. op.drop_constraint(
  33. 'pull_requests_project_id_from_fkey',
  34. 'pull_requests',
  35. type_='foreignkey')
  36. op.create_foreign_key(
  37. name='pull_requests_project_id_from_fkey',
  38. source_table='pull_requests',
  39. referent_table='projects',
  40. local_cols=['project_id_from'],
  41. remote_cols=['id'],
  42. onupdate='cascade',
  43. ondelete='cascade',
  44. )