317a285e04a8_delete_hooks.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Delete hooks
  2. Revision ID: 317a285e04a8
  3. Revises: 2aa7b3958bc5
  4. Create Date: 2016-05-30 11:28:48.512577
  5. """
  6. # revision identifiers, used by Alembic.
  7. revision = '317a285e04a8'
  8. down_revision = '2aa7b3958bc5'
  9. from alembic import op
  10. import sqlalchemy as sa
  11. def upgrade():
  12. """ Alter the hooks table to update the foreign key to cascade on delete.
  13. """
  14. for table in [
  15. 'hook_fedmsg', 'hook_irc', 'hook_mail',
  16. 'hook_pagure_force_commit', 'hook_pagure', 'hook_pagure_requests',
  17. 'hook_pagure_tickets', 'hook_pagure_unsigned_commit', 'hook_rtd',
  18. ]:
  19. op.drop_constraint(
  20. '%s_project_id_fkey' % table,
  21. table,
  22. type_='foreignkey')
  23. op. create_foreign_key(
  24. name='%s_project_id_fkey' % table,
  25. source_table=table,
  26. referent_table='projects',
  27. local_cols=['project_id'],
  28. remote_cols=['id'],
  29. onupdate='cascade',
  30. ondelete='cascade',
  31. )
  32. op.drop_constraint(
  33. 'projects_groups_project_id_fkey',
  34. 'projects_groups',
  35. type_='foreignkey')
  36. op. create_foreign_key(
  37. name='projects_groups_project_id_fkey',
  38. source_table='projects_groups',
  39. referent_table='projects',
  40. local_cols=['project_id'],
  41. remote_cols=['id'],
  42. onupdate='cascade',
  43. ondelete='cascade',
  44. )
  45. def downgrade():
  46. """ Alter the hooks table to update the foreign key to undo the cascade
  47. on delete.
  48. """