1616
1717import os
1818
19- from oslo_db .sqlalchemy .migration_cli import manager
19+ from alembic import command as alembic_command
20+ from alembic import config as alembic_config
21+ from alembic import migration as alembic_migration
22+ from oslo_db .sqlalchemy import enginefacade
2023
21- import magnum .conf
2224
23- CONF = magnum .conf .CONF
24- _MANAGER = None
25-
26-
27- def get_manager ():
28- global _MANAGER
29- if not _MANAGER :
30- alembic_path = os .path .abspath (
31- os .path .join (os .path .dirname (__file__ ), 'alembic.ini' ))
32- migrate_path = os .path .abspath (
33- os .path .join (os .path .dirname (__file__ ), 'alembic' ))
34- migration_config = {'alembic_ini_path' : alembic_path ,
35- 'alembic_repo_path' : migrate_path ,
36- 'db_url' : CONF .database .connection }
37- _MANAGER = manager .MigrationManager (migration_config )
38-
39- return _MANAGER
25+ def _get_alembic_config ():
26+ ini_path = os .path .join (os .path .dirname (__file__ ), 'alembic.ini' )
27+ cfg = alembic_config .Config (ini_path )
28+ cfg .set_main_option (
29+ 'script_location' ,
30+ os .path .join (os .path .dirname (__file__ ), 'alembic' ))
31+ return cfg
4032
4133
4234def version ():
@@ -45,7 +37,10 @@ def version():
4537 :returns: Database version
4638 :rtype: string
4739 """
48- return get_manager ().version ()
40+ engine = enginefacade .writer .get_engine ()
41+ with engine .connect () as conn :
42+ ctx = alembic_migration .MigrationContext .configure (conn )
43+ return ctx .get_current_revision ()
4944
5045
5146def upgrade (version ):
@@ -55,8 +50,7 @@ def upgrade(version):
5550 :type version: string
5651 """
5752 version = version or 'head'
58-
59- get_manager ().upgrade (version )
53+ alembic_command .upgrade (_get_alembic_config (), version )
6054
6155
6256def stamp (revision ):
@@ -68,7 +62,7 @@ def stamp(revision):
6862 database with most recent revision
6963 :type revision: string
7064 """
71- get_manager () .stamp (revision )
65+ alembic_command .stamp (_get_alembic_config (), revision )
7266
7367
7468def revision (message = None , autogenerate = False ):
@@ -80,4 +74,5 @@ def revision(message=None, autogenerate=False):
8074 state
8175 :type autogenerate: bool
8276 """
83- return get_manager ().revision (message = message , autogenerate = autogenerate )
77+ return alembic_command .revision (
78+ _get_alembic_config (), message = message , autogenerate = autogenerate )
0 commit comments