prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Cannot run database migrations on the 3.7 branch
  I built a beta out of the ```HEAD``` of the ```3.7``` branch, and the migrations fail to run:
  
  ```
  [root@bodhi-backend01 bowlofeggs][STG]# /usr/bin/alembic -c /etc/bodhi/alembic.ini upgrade head
  INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
  INFO  [alembic.runtime.migration] Will assume transactional DDL.
  INFO  [alembic.env] Emitting SQL to allow for global DDL locking with BDR
  /usr/lib/python2.7/site-packages/alembic/util/messaging.py:69: UserWarning: Revision be25565a1211 referenced from be25565a1211 -> 59c0f5fbc1b2 (head), Add a greenwave_unsatisfied_requirements column to the updates table. is not present
    warnings.warn(msg)
  Traceback (most recent call last):
    File "/usr/bin/alembic", line 12, in <module>
      sys.exit(load_entry_point('alembic', 'console_scripts', 'alembic')())
    File "/usr/lib/python2.7/site-packages/alembic/config.py", line 479, in main
      CommandLine(prog=prog).main(argv=argv)
    File "/usr/lib/python2.7/site-packages/alembic/config.py", line 473, in main
      self.run_cmd(cfg, options)
    File "/usr/lib/python2.7/site-packages/alembic/config.py", line 456, in run_cmd
      **dict((k, getattr(options, k, None)) for k in kwarg)
    File "/usr/lib/python2.7/site-packages/alembic/command.py", line 254, in upgrade
      script.run_env()
    File "/usr/lib/python2.7/site-packages/alembic/script/base.py", line 425, in run_env
      util.load_python_file(self.dir, 'env.py')
    File "/usr/lib/python2.7/site-packages/alembic/util/pyfiles.py", line 81, in load_python_file
      module = load_module_py(module_id, path)
    File "/usr/lib/python2.7/site-packages/alembic/util/compat.py", line 141, in load_module_py
      mod = imp.load_source(module_id, path, fp)
    File "/usr/lib/python2.7/site-packages/bodhi/server/migrations/env.py", line 112, in <module>
      run_migrations_online()
    File "/usr/lib/python2.7/site-packages/bodhi/server/migrations/env.py", line 104, in run_migrations_online
      context.run_migrations()
    File "<string>", line 8, in run_migrations
    File "/usr/lib/python2.7/site-packages/alembic/runtime/environment.py", line 836, in run_migrations
      self.get_context().run_migrations(**kw)
    File "/usr/lib/python2.7/site-packages/alembic/runtime/migration.py", line 321, in run_migrations
      for step in self._migrations_fn(heads, self):
    File "/usr/lib/python2.7/site-packages/alembic/command.py", line 243, in upgrade
      return script._upgrade_revs(revision, rev)
    File "/usr/lib/python2.7/site-packages/alembic/script/base.py", line 334, in _upgrade_revs
      revs = list(revs)
    File "/usr/lib/python2.7/site-packages/alembic/script/revision.py", line 645, in _iterate_revisions
      requested_lowers = self.get_revisions(lower)
    File "/usr/lib/python2.7/site-packages/alembic/script/revision.py", line 299, in get_revisions
      return sum([self.get_revisions(id_elem) for id_elem in id_], ())
    File "/usr/lib/python2.7/site-packages/alembic/script/revision.py", line 301, in get_revisions
      resolved_id, branch_label = self._resolve_revision_number(id_)
    File "/usr/lib/python2.7/site-packages/alembic/script/revision.py", line 437, in _resolve_revision_number
      self._revision_map
    File "/usr/lib/python2.7/site-packages/alembic/util/langhelpers.py", line 239, in __get__
      obj.__dict__[self.__name__] = result = self.fget(obj)
    File "/usr/lib/python2.7/site-packages/alembic/script/revision.py", line 152, in _revision_map
      down_revision = map_[downrev]
  KeyError: 'be25565a1211'
  ```
  
  It sounds like there's a migration on ```develop``` that is not on the ```3.7``` branch, and when I cherry-picked the migration back to ```3.7``` it now references a migration that does not exist. To fix this, I'll need to shuffle the order of the migrations.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py`
  Content:
  ```
  1 # Copyright (c) 2018 Red Hat, Inc.
  2 #
  3 # This file is part of Bodhi.
  4 #
  5 # This program is free software; you can redistribute it and/or
  6 # modify it under the terms of the GNU General Public License
  7 # as published by the Free Software Foundation; either version 2
  8 # of the License, or (at your option) any later version.
  9 #
  10 # This program is distributed in the hope that it will be useful,
  11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13 # GNU General Public License for more details.
  14 #
  15 # You should have received a copy of the GNU General Public License
  16 # along with this program; if not, write to the Free Software
  17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18 """
  19 Add a greenwave_unsatisfied_requirements column to the updates table.
  20 
  21 Revision ID: 59c0f5fbc1b2
  22 Revises: be25565a1211
  23 Create Date: 2018-05-01 15:37:07.346034
  24 """
  25 from alembic import op
  26 import sqlalchemy as sa
  27 
  28 
  29 # revision identifiers, used by Alembic.
  30 revision = '59c0f5fbc1b2'
  31 down_revision = 'be25565a1211'
  32 
  33 
  34 def upgrade():
  35     """Add a greenwave_unsatisfied_requirements to the updates table."""
  36     op.add_column('updates',
  37                   sa.Column('greenwave_unsatisfied_requirements', sa.UnicodeText(), nullable=True))
  38 
  39 
  40 def downgrade():
  41     """Drop the greenwave_unsatisfied_requirements from the updates table."""
  42     op.drop_column('updates', 'greenwave_unsatisfied_requirements')
  43
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py b/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py
  --- a/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py
  +++ b/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py
  @@ -19,7 +19,7 @@
   Add a greenwave_unsatisfied_requirements column to the updates table.
   
   Revision ID: 59c0f5fbc1b2
  -Revises: be25565a1211
  +Revises: c21dd18b161a
   Create Date: 2018-05-01 15:37:07.346034
   """
   from alembic import op
  @@ -28,7 +28,7 @@
   
   # revision identifiers, used by Alembic.
   revision = '59c0f5fbc1b2'
  -down_revision = 'be25565a1211'
  +down_revision = 'c21dd18b161a'
   
   
   def upgrade():
  
verification_info: {"golden_diff": "diff --git a/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py b/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py\n--- a/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py\n+++ b/bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py\n@@ -19,7 +19,7 @@\n Add a greenwave_unsatisfied_requirements column to the updates table.\n \n Revision ID: 59c0f5fbc1b2\n-Revises: be25565a1211\n+Revises: c21dd18b161a\n Create Date: 2018-05-01 15:37:07.346034\n \"\"\"\n from alembic import op\n@@ -28,7 +28,7 @@\n \n # revision identifiers, used by Alembic.\n revision = '59c0f5fbc1b2'\n-down_revision = 'be25565a1211'\n+down_revision = 'c21dd18b161a'\n \n \n def upgrade():\n", "issue": "Cannot run database migrations on the 3.7 branch\nI built a beta out of the ```HEAD``` of the ```3.7``` branch, and the migrations fail to run:\r\n\r\n```\r\n[root@bodhi-backend01 bowlofeggs][STG]# /usr/bin/alembic -c /etc/bodhi/alembic.ini upgrade head\r\nINFO  [alembic.runtime.migration] Context impl PostgresqlImpl.\r\nINFO  [alembic.runtime.migration] Will assume transactional DDL.\r\nINFO  [alembic.env] Emitting SQL to allow for global DDL locking with BDR\r\n/usr/lib/python2.7/site-packages/alembic/util/messaging.py:69: UserWarning: Revision be25565a1211 referenced from be25565a1211 -> 59c0f5fbc1b2 (head), Add a greenwave_unsatisfied_requirements column to the updates table. is not present\r\n  warnings.warn(msg)\r\nTraceback (most recent call last):\r\n  File \"/usr/bin/alembic\", line 12, in <module>\r\n    sys.exit(load_entry_point('alembic', 'console_scripts', 'alembic')())\r\n  File \"/usr/lib/python2.7/site-packages/alembic/config.py\", line 479, in main\r\n    CommandLine(prog=prog).main(argv=argv)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/config.py\", line 473, in main\r\n    self.run_cmd(cfg, options)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/config.py\", line 456, in run_cmd\r\n    **dict((k, getattr(options, k, None)) for k in kwarg)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/command.py\", line 254, in upgrade\r\n    script.run_env()\r\n  File \"/usr/lib/python2.7/site-packages/alembic/script/base.py\", line 425, in run_env\r\n    util.load_python_file(self.dir, 'env.py')\r\n  File \"/usr/lib/python2.7/site-packages/alembic/util/pyfiles.py\", line 81, in load_python_file\r\n    module = load_module_py(module_id, path)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/util/compat.py\", line 141, in load_module_py\r\n    mod = imp.load_source(module_id, path, fp)\r\n  File \"/usr/lib/python2.7/site-packages/bodhi/server/migrations/env.py\", line 112, in <module>\r\n    run_migrations_online()\r\n  File \"/usr/lib/python2.7/site-packages/bodhi/server/migrations/env.py\", line 104, in run_migrations_online\r\n    context.run_migrations()\r\n  File \"<string>\", line 8, in run_migrations\r\n  File \"/usr/lib/python2.7/site-packages/alembic/runtime/environment.py\", line 836, in run_migrations\r\n    self.get_context().run_migrations(**kw)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/runtime/migration.py\", line 321, in run_migrations\r\n    for step in self._migrations_fn(heads, self):\r\n  File \"/usr/lib/python2.7/site-packages/alembic/command.py\", line 243, in upgrade\r\n    return script._upgrade_revs(revision, rev)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/script/base.py\", line 334, in _upgrade_revs\r\n    revs = list(revs)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/script/revision.py\", line 645, in _iterate_revisions\r\n    requested_lowers = self.get_revisions(lower)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/script/revision.py\", line 299, in get_revisions\r\n    return sum([self.get_revisions(id_elem) for id_elem in id_], ())\r\n  File \"/usr/lib/python2.7/site-packages/alembic/script/revision.py\", line 301, in get_revisions\r\n    resolved_id, branch_label = self._resolve_revision_number(id_)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/script/revision.py\", line 437, in _resolve_revision_number\r\n    self._revision_map\r\n  File \"/usr/lib/python2.7/site-packages/alembic/util/langhelpers.py\", line 239, in __get__\r\n    obj.__dict__[self.__name__] = result = self.fget(obj)\r\n  File \"/usr/lib/python2.7/site-packages/alembic/script/revision.py\", line 152, in _revision_map\r\n    down_revision = map_[downrev]\r\nKeyError: 'be25565a1211'\r\n```\r\n\r\nIt sounds like there's a migration on ```develop``` that is not on the ```3.7``` branch, and when I cherry-picked the migration back to ```3.7``` it now references a migration that does not exist. To fix this, I'll need to shuffle the order of the migrations.\n", "before_files": [{"content": "# Copyright (c) 2018 Red Hat, Inc.\n#\n# This file is part of Bodhi.\n#\n# This program is free software; you can redistribute it and/or\n# modify it under the terms of the GNU General Public License\n# as published by the Free Software Foundation; either version 2\n# of the License, or (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n\"\"\"\nAdd a greenwave_unsatisfied_requirements column to the updates table.\n\nRevision ID: 59c0f5fbc1b2\nRevises: be25565a1211\nCreate Date: 2018-05-01 15:37:07.346034\n\"\"\"\nfrom alembic import op\nimport sqlalchemy as sa\n\n\n# revision identifiers, used by Alembic.\nrevision = '59c0f5fbc1b2'\ndown_revision = 'be25565a1211'\n\n\ndef upgrade():\n    \"\"\"Add a greenwave_unsatisfied_requirements to the updates table.\"\"\"\n    op.add_column('updates',\n                  sa.Column('greenwave_unsatisfied_requirements', sa.UnicodeText(), nullable=True))\n\n\ndef downgrade():\n    \"\"\"Drop the greenwave_unsatisfied_requirements from the updates table.\"\"\"\n    op.drop_column('updates', 'greenwave_unsatisfied_requirements')\n", "path": "bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py"}], "after_files": [{"content": "# Copyright (c) 2018 Red Hat, Inc.\n#\n# This file is part of Bodhi.\n#\n# This program is free software; you can redistribute it and/or\n# modify it under the terms of the GNU General Public License\n# as published by the Free Software Foundation; either version 2\n# of the License, or (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n\"\"\"\nAdd a greenwave_unsatisfied_requirements column to the updates table.\n\nRevision ID: 59c0f5fbc1b2\nRevises: c21dd18b161a\nCreate Date: 2018-05-01 15:37:07.346034\n\"\"\"\nfrom alembic import op\nimport sqlalchemy as sa\n\n\n# revision identifiers, used by Alembic.\nrevision = '59c0f5fbc1b2'\ndown_revision = 'c21dd18b161a'\n\n\ndef upgrade():\n    \"\"\"Add a greenwave_unsatisfied_requirements to the updates table.\"\"\"\n    op.add_column('updates',\n                  sa.Column('greenwave_unsatisfied_requirements', sa.UnicodeText(), nullable=True))\n\n\ndef downgrade():\n    \"\"\"Drop the greenwave_unsatisfied_requirements from the updates table.\"\"\"\n    op.drop_column('updates', 'greenwave_unsatisfied_requirements')\n", "path": "bodhi/server/migrations/versions/59c0f5fbc1b2_add_a_greenwave_unsatisfied_.py"}]}