Call alembic migrations after sqlalchemy-migrate
Removed version parameter from storage.upgrade method since it was never used and partial upgrade is not supported by the code base Removed downgrade call from db_sync since it's never used Implements blueprint convert-to-alembic Change-Id: I2aeabc111e5d3728fdcd0df45bf56f0aa68ed199
This commit is contained in:
parent
5983a99da9
commit
9dc5ab7ad0
@ -65,7 +65,7 @@ class Connection(object):
|
||||
"""Constructor."""
|
||||
|
||||
@abc.abstractmethod
|
||||
def upgrade(self, version=None):
|
||||
def upgrade(self):
|
||||
"""Migrate the database to `version` or the most recent version."""
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -102,7 +102,7 @@ class Connection(base.Connection):
|
||||
self.conn = self._get_connection(opts)
|
||||
self.conn.open()
|
||||
|
||||
def upgrade(self, version=None):
|
||||
def upgrade(self):
|
||||
self.conn.create_table(self.PROJECT_TABLE, {'f': dict()})
|
||||
self.conn.create_table(self.USER_TABLE, {'f': dict()})
|
||||
self.conn.create_table(self.RESOURCE_TABLE, {'f': dict()})
|
||||
|
@ -41,7 +41,7 @@ class Connection(base.Connection):
|
||||
def __init__(self, conf):
|
||||
pass
|
||||
|
||||
def upgrade(self, version=None):
|
||||
def upgrade(self):
|
||||
pass
|
||||
|
||||
def clear(self):
|
||||
|
@ -260,7 +260,7 @@ class Connection(base.Connection):
|
||||
# needed.
|
||||
self.upgrade()
|
||||
|
||||
def upgrade(self, version=None):
|
||||
def upgrade(self):
|
||||
# Establish indexes
|
||||
#
|
||||
# We need variations for user_id vs. project_id because of the
|
||||
|
@ -147,9 +147,9 @@ class Connection(base.Connection):
|
||||
conf.database.connection = \
|
||||
os.environ.get('CEILOMETER_TEST_SQL_URL', url)
|
||||
|
||||
def upgrade(self, version=None):
|
||||
def upgrade(self):
|
||||
session = sqlalchemy_session.get_session()
|
||||
migration.db_sync(session.get_bind(), version=version)
|
||||
migration.db_sync(session.get_bind())
|
||||
|
||||
def clear(self):
|
||||
session = sqlalchemy_session.get_session()
|
||||
|
@ -1 +1,9 @@
|
||||
Generic single-database configuration.
|
||||
Please see https://alembic.readthedocs.org/en/latest/index.html for general documentation
|
||||
|
||||
To create alembic migrations you need to have alembic installed and available in PATH:
|
||||
# pip install alembic
|
||||
$ cd ./ceilometer/storage/sqlalchemy/alembic
|
||||
$ alembic revision -m "migration_description"
|
||||
|
||||
See Operation Reference https://alembic.readthedocs.org/en/latest/ops.html#ops
|
||||
for a short list of commands
|
||||
|
@ -1,4 +1,4 @@
|
||||
This is a database migration repository.
|
||||
sqlalchemy-migrate is DEPRECATED.
|
||||
|
||||
More information at
|
||||
http://code.google.com/p/sqlalchemy-migrate/
|
||||
All new migrations should be written using alembic.
|
||||
Please see ceilometer/storage/sqlalchemy/alembic/README
|
||||
|
@ -18,6 +18,9 @@
|
||||
import distutils.version as dist_version
|
||||
import os
|
||||
|
||||
import alembic
|
||||
from alembic import config as alembic_config
|
||||
|
||||
import migrate
|
||||
from migrate.versioning import util as migrate_util
|
||||
import sqlalchemy
|
||||
@ -59,20 +62,17 @@ from migrate.versioning.repository import Repository
|
||||
_REPOSITORY = None
|
||||
|
||||
|
||||
def db_sync(engine, version=None):
|
||||
if version is not None:
|
||||
try:
|
||||
version = int(version)
|
||||
except ValueError:
|
||||
raise Exception(_("version should be an integer"))
|
||||
|
||||
current_version = db_version(engine)
|
||||
def db_sync(engine):
|
||||
db_version(engine) # This is needed to create a version stamp in empty DB
|
||||
repository = _find_migrate_repo()
|
||||
if version is None or version > current_version:
|
||||
return versioning_api.upgrade(engine, repository, version)
|
||||
else:
|
||||
return versioning_api.downgrade(engine, repository,
|
||||
version)
|
||||
versioning_api.upgrade(engine, repository)
|
||||
alembic.command.upgrade(_alembic_config(), "head")
|
||||
|
||||
|
||||
def _alembic_config():
|
||||
path = os.path.join(os.path.dirname(__file__), 'alembic/alembic.ini')
|
||||
config = alembic_config.Config(path)
|
||||
return config
|
||||
|
||||
|
||||
def db_version(engine):
|
||||
|
@ -35,8 +35,6 @@ class TestBase(test_base.TestCase):
|
||||
group='database')
|
||||
self.conn = storage.get_connection(cfg.CONF)
|
||||
self.conn.upgrade()
|
||||
self.conn.clear()
|
||||
self.conn.upgrade()
|
||||
|
||||
def tearDown(self):
|
||||
self.conn.clear()
|
||||
|
Loading…
x
Reference in New Issue
Block a user