Repository: fedora-infra/bodhi

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.


Discussion:

Resolving patch:
diff --git a/bodhi/server/migrations/versions/22858ba91115_add_new_side_tag_update_states.py b/bodhi/server/migrations/versions/22858ba91115_add_new_side_tag_update_states.py
--- a/bodhi/server/migrations/versions/22858ba91115_add_new_side_tag_update_states.py
+++ b/bodhi/server/migrations/versions/22858ba91115_add_new_side_tag_update_states.py
@@ -19,7 +19,7 @@
 Add new side tag update states.
 
 Revision ID: 22858ba91115
-Revises: c21dd18b161a
+Revises: 59c0f5fbc1b2
 Create Date: 2018-04-10 21:49:26.209484
 """
 from alembic import op
@@ -28,7 +28,7 @@
 
 # revision identifiers, used by Alembic.
 revision = '22858ba91115'
-down_revision = 'c21dd18b161a'
+down_revision = '59c0f5fbc1b2'
 
 
 def upgrade():
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():


Test patch: