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."""
|
"""Constructor."""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def upgrade(self, version=None):
|
def upgrade(self):
|
||||||
"""Migrate the database to `version` or the most recent version."""
|
"""Migrate the database to `version` or the most recent version."""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
@ -102,7 +102,7 @@ class Connection(base.Connection):
|
|||||||
self.conn = self._get_connection(opts)
|
self.conn = self._get_connection(opts)
|
||||||
self.conn.open()
|
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.PROJECT_TABLE, {'f': dict()})
|
||||||
self.conn.create_table(self.USER_TABLE, {'f': dict()})
|
self.conn.create_table(self.USER_TABLE, {'f': dict()})
|
||||||
self.conn.create_table(self.RESOURCE_TABLE, {'f': dict()})
|
self.conn.create_table(self.RESOURCE_TABLE, {'f': dict()})
|
||||||
|
@ -41,7 +41,7 @@ class Connection(base.Connection):
|
|||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def upgrade(self, version=None):
|
def upgrade(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
|
@ -260,7 +260,7 @@ class Connection(base.Connection):
|
|||||||
# needed.
|
# needed.
|
||||||
self.upgrade()
|
self.upgrade()
|
||||||
|
|
||||||
def upgrade(self, version=None):
|
def upgrade(self):
|
||||||
# Establish indexes
|
# Establish indexes
|
||||||
#
|
#
|
||||||
# We need variations for user_id vs. project_id because of the
|
# We need variations for user_id vs. project_id because of the
|
||||||
|
@ -147,9 +147,9 @@ class Connection(base.Connection):
|
|||||||
conf.database.connection = \
|
conf.database.connection = \
|
||||||
os.environ.get('CEILOMETER_TEST_SQL_URL', url)
|
os.environ.get('CEILOMETER_TEST_SQL_URL', url)
|
||||||
|
|
||||||
def upgrade(self, version=None):
|
def upgrade(self):
|
||||||
session = sqlalchemy_session.get_session()
|
session = sqlalchemy_session.get_session()
|
||||||
migration.db_sync(session.get_bind(), version=version)
|
migration.db_sync(session.get_bind())
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
session = sqlalchemy_session.get_session()
|
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
|
All new migrations should be written using alembic.
|
||||||
http://code.google.com/p/sqlalchemy-migrate/
|
Please see ceilometer/storage/sqlalchemy/alembic/README
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
import distutils.version as dist_version
|
import distutils.version as dist_version
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import alembic
|
||||||
|
from alembic import config as alembic_config
|
||||||
|
|
||||||
import migrate
|
import migrate
|
||||||
from migrate.versioning import util as migrate_util
|
from migrate.versioning import util as migrate_util
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
@ -59,20 +62,17 @@ from migrate.versioning.repository import Repository
|
|||||||
_REPOSITORY = None
|
_REPOSITORY = None
|
||||||
|
|
||||||
|
|
||||||
def db_sync(engine, version=None):
|
def db_sync(engine):
|
||||||
if version is not None:
|
db_version(engine) # This is needed to create a version stamp in empty DB
|
||||||
try:
|
|
||||||
version = int(version)
|
|
||||||
except ValueError:
|
|
||||||
raise Exception(_("version should be an integer"))
|
|
||||||
|
|
||||||
current_version = db_version(engine)
|
|
||||||
repository = _find_migrate_repo()
|
repository = _find_migrate_repo()
|
||||||
if version is None or version > current_version:
|
versioning_api.upgrade(engine, repository)
|
||||||
return versioning_api.upgrade(engine, repository, version)
|
alembic.command.upgrade(_alembic_config(), "head")
|
||||||
else:
|
|
||||||
return versioning_api.downgrade(engine, repository,
|
|
||||||
version)
|
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):
|
def db_version(engine):
|
||||||
|
@ -35,8 +35,6 @@ class TestBase(test_base.TestCase):
|
|||||||
group='database')
|
group='database')
|
||||||
self.conn = storage.get_connection(cfg.CONF)
|
self.conn = storage.get_connection(cfg.CONF)
|
||||||
self.conn.upgrade()
|
self.conn.upgrade()
|
||||||
self.conn.clear()
|
|
||||||
self.conn.upgrade()
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.conn.clear()
|
self.conn.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user