sqlalchemy: allow to upgrade schema from Ceilometer Liberty

This should allow to upgrade database schemas from Ceilometer Liberty
without much trouble.

Change-Id: Ie8c0873f0c3ceb2daa964417e19cfc7da5bea3e8
(cherry picked from commit 7b82364b51)
This commit is contained in:
Julien Danjou 2016-06-29 15:51:12 +02:00
parent 5c98334eed
commit 4a53f93f60

View File

@ -19,6 +19,7 @@ import os.path
from alembic import command
from alembic import config
from alembic import migration
from oslo_db import exception
from oslo_db.sqlalchemy import session as db_session
from oslo_log import log
from oslo_utils import timeutils
@ -89,7 +90,14 @@ class Connection(base.Connection):
ctxt = migration.MigrationContext.configure(engine.connect())
current_version = ctxt.get_current_revision()
if current_version is None:
models.Base.metadata.create_all(engine)
try:
models.Base.metadata.create_all(engine, checkfirst=False)
except exception.DBError:
# Assume tables exist from Ceilometer, take control
# FIXME(jd) Remove in Ocata
command.stamp(cfg, "12fe8fac9fe4")
command.upgrade(cfg, "head")
else:
command.stamp(cfg, "head")
else:
command.upgrade(cfg, "head")