1
0

298891e63039_change_the_status_of_pull_requests.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """Change the status of pull_requests
  2. Revision ID: 298891e63039
  3. Revises: 3c25e14b855b
  4. Create Date: 2015-06-08 13:06:11.938966
  5. """
  6. # revision identifiers, used by Alembic.
  7. revision = '298891e63039'
  8. down_revision = '3c25e14b855b'
  9. from alembic import op
  10. import sqlalchemy as sa
  11. def upgrade():
  12. ''' Adjust the status column of the pull_requests table.
  13. '''
  14. op.add_column(
  15. 'pull_requests',
  16. sa.Column(
  17. '_status', sa.Text,
  18. sa.ForeignKey(
  19. 'status_pull_requests.status', onupdate='CASCADE'),
  20. default='Open',
  21. nullable=True)
  22. )
  23. op.execute('''UPDATE "pull_requests" '''
  24. '''SET _status='Open' WHERE status=TRUE;''')
  25. op.execute('''UPDATE "pull_requests" '''
  26. '''SET _status='Merged' WHERE status=FALSE;''')
  27. op.drop_column('pull_requests', 'status')
  28. op.alter_column(
  29. 'pull_requests',
  30. column_name='_status', new_column_name='status',
  31. nullable=False, existing_nullable=True)
  32. def downgrade():
  33. ''' Revert the status column of the pull_requests table.
  34. '''
  35. op.add_column(
  36. 'pull_requests',
  37. sa.Column(
  38. '_status', sa.Boolean, default=True, nullable=True)
  39. )
  40. op.execute('''UPDATE "pull_requests" '''
  41. '''SET _status=TRUE WHERE status='Open';''')
  42. op.execute('''UPDATE "pull_requests" '''
  43. '''SET _status=FALSE WHERE status!='Open';''')
  44. op.drop_column('pull_requests', 'status')
  45. op.alter_column(
  46. 'pull_requests',
  47. column_name='_status', new_column_name='status',
  48. nullable=False, existing_nullable=True)