317a285e04a8_delete_hooks.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. """