Add cinder.db.migration.db_initial_version()
Updates Cinder to use a new function called db_initial_version() instead of the INIT_VERSION constant. This allows us to move the top level INIT_VERSION constant into the sqlalchemy migration.py implementation where it belongs. Change-Id: I10dacdebb50d3121e3bfd094e40138807233aa64
This commit is contained in:
parent
64c6eea42a
commit
25a279b5ac
|
@ -25,9 +25,6 @@ IMPL = utils.LazyPluggable('db_backend',
|
|||
sqlalchemy='cinder.db.sqlalchemy.migration')
|
||||
|
||||
|
||||
INIT_VERSION = 000
|
||||
|
||||
|
||||
def db_sync(version=None):
|
||||
"""Migrate the database to `version` or the most recent version."""
|
||||
return IMPL.db_sync(version=version)
|
||||
|
@ -36,3 +33,8 @@ def db_sync(version=None):
|
|||
def db_version():
|
||||
"""Display the current database version."""
|
||||
return IMPL.db_version()
|
||||
|
||||
|
||||
def db_initial_version():
|
||||
"""The starting version for the database."""
|
||||
return IMPL.db_initial_version()
|
||||
|
|
|
@ -24,12 +24,12 @@ import migrate
|
|||
from migrate.versioning import util as migrate_util
|
||||
import sqlalchemy
|
||||
|
||||
from cinder.db import migration
|
||||
from cinder.db.sqlalchemy.api import get_engine
|
||||
from cinder import exception
|
||||
from cinder.openstack.common import log as logging
|
||||
|
||||
|
||||
INIT_VERSION = 000
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -93,12 +93,16 @@ def db_version():
|
|||
meta.reflect(bind=engine)
|
||||
tables = meta.tables
|
||||
if len(tables) == 0:
|
||||
db_version_control(migration.INIT_VERSION)
|
||||
db_version_control(INIT_VERSION)
|
||||
return versioning_api.db_version(get_engine(), repository)
|
||||
else:
|
||||
raise exception.Error(_("Upgrade DB using Essex release first."))
|
||||
|
||||
|
||||
def db_initial_version():
|
||||
return INIT_VERSION
|
||||
|
||||
|
||||
def db_version_control(version=None):
|
||||
repository = _find_migrate_repo()
|
||||
versioning_api.version_control(get_engine(), repository, version)
|
||||
|
|
|
@ -78,7 +78,7 @@ class Database(fixtures.Fixture):
|
|||
self.engine.dispose()
|
||||
conn = self.engine.connect()
|
||||
if sql_connection == "sqlite://":
|
||||
if db_migrate.db_version() > db_migrate.INIT_VERSION:
|
||||
if db_migrate.db_version() > db_migrate.db_initial_version():
|
||||
return
|
||||
else:
|
||||
testdb = os.path.join(CONF.state_path, sqlite_db)
|
||||
|
|
|
@ -309,17 +309,17 @@ class TestMigrations(test.TestCase):
|
|||
# Place the database under version control
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
self.assertEqual(migration.INIT_VERSION,
|
||||
migration.db_initial_version())
|
||||
self.assertEqual(migration.db_initial_version(),
|
||||
migration_api.db_version(engine,
|
||||
TestMigrations.REPOSITORY))
|
||||
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION + 1)
|
||||
migration.db_initial_version() + 1)
|
||||
|
||||
LOG.debug('latest version is %s' % TestMigrations.REPOSITORY.latest)
|
||||
|
||||
for version in xrange(migration.INIT_VERSION + 2,
|
||||
for version in xrange(migration.db_initial_version() + 2,
|
||||
TestMigrations.REPOSITORY.latest + 1):
|
||||
# upgrade -> downgrade -> upgrade
|
||||
self._migrate_up(engine, version, with_data=True)
|
||||
|
@ -331,7 +331,7 @@ class TestMigrations(test.TestCase):
|
|||
# Now walk it back down to 0 from the latest, testing
|
||||
# the downgrade paths.
|
||||
for version in reversed(
|
||||
xrange(migration.INIT_VERSION + 1,
|
||||
xrange(migration.db_initial_version() + 1,
|
||||
TestMigrations.REPOSITORY.latest)):
|
||||
# downgrade -> upgrade -> downgrade
|
||||
self._migrate_down(engine, version)
|
||||
|
@ -472,7 +472,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 4)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -488,7 +488,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
upgrade_to)
|
||||
|
@ -539,7 +539,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 7)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -601,7 +601,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 8)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -643,7 +643,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 9)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -686,7 +686,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 10)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -730,7 +730,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 11)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -756,7 +756,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 12)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -782,7 +782,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 13)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -808,7 +808,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 15)
|
||||
|
||||
self.assertFalse(engine.dialect.has_table(engine.connect(),
|
||||
|
@ -824,7 +824,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 15)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -852,7 +852,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 16)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -905,7 +905,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 17)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -943,7 +943,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 18)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
@ -969,7 +969,7 @@ class TestMigrations(test.TestCase):
|
|||
for (key, engine) in self.engines.items():
|
||||
migration_api.version_control(engine,
|
||||
TestMigrations.REPOSITORY,
|
||||
migration.INIT_VERSION)
|
||||
migration.db_initial_version())
|
||||
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 19)
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
|
|
Loading…
Reference in New Issue