Merge "Add version command to murano-db-manage"
This commit is contained in:
commit
c542a50e61
|
@ -36,6 +36,9 @@ class DBCommand(object):
|
|||
def stamp(self, config):
|
||||
migration.stamp(CONF.command.revision, config=config)
|
||||
|
||||
def version(self, config):
|
||||
print(migration.version())
|
||||
|
||||
|
||||
def add_command_parsers(subparsers):
|
||||
command_object = DBCommand()
|
||||
|
@ -57,6 +60,9 @@ def add_command_parsers(subparsers):
|
|||
parser.add_argument('--autogenerate', action='store_true')
|
||||
parser.set_defaults(func=command_object.revision)
|
||||
|
||||
parser = subparsers.add_parser('version')
|
||||
parser.set_defaults(func=command_object.version)
|
||||
|
||||
|
||||
command_opt = cfg.SubCommandOpt('command',
|
||||
title='Command',
|
||||
|
|
|
@ -14,6 +14,9 @@ import os
|
|||
|
||||
import alembic
|
||||
from alembic import config as alembic_config
|
||||
from alembic import migration as alembic_migration
|
||||
|
||||
from murano.db import session as db_session
|
||||
|
||||
|
||||
def get_alembic_config():
|
||||
|
@ -25,9 +28,12 @@ def get_alembic_config():
|
|||
return config
|
||||
|
||||
|
||||
# TODO(ruhe): implement me
|
||||
#def version(config=None):
|
||||
# """Current database version."""
|
||||
def version():
|
||||
"""Returns current database version."""
|
||||
engine = db_session.get_engine()
|
||||
with engine.connect() as conn:
|
||||
context = alembic_migration.MigrationContext.configure(conn)
|
||||
return context.get_current_revision()
|
||||
|
||||
|
||||
def upgrade(revision, config=None):
|
||||
|
|
|
@ -17,6 +17,7 @@ import uuid
|
|||
from oslo.config import cfg
|
||||
from sqlalchemy import exc
|
||||
|
||||
from murano.db.migration import migration
|
||||
from murano.db import models # noqa
|
||||
from murano.openstack.common.db.sqlalchemy import utils as db_utils
|
||||
from murano.tests.db.migration import test_migrations_base as base
|
||||
|
@ -70,6 +71,7 @@ class TestMigrations(base.BaseWalkMigrationTestCase, base.CommonTestsMixIn):
|
|||
self.assertEqual(sorted(members), sorted(index_columns))
|
||||
|
||||
def _check_001(self, engine, data):
|
||||
self.assertEqual('001', migration.version())
|
||||
self.assertColumnExists(engine, 'category', 'id')
|
||||
self.assertColumnExists(engine, 'environment', 'tenant_id')
|
||||
|
||||
|
@ -112,3 +114,7 @@ class TestMigrations(base.BaseWalkMigrationTestCase, base.CommonTestsMixIn):
|
|||
package['id'] = str(uuid.uuid4())
|
||||
self.assertRaises(exc.IntegrityError,
|
||||
package_table.insert().execute, package)
|
||||
|
||||
def _check_002(self, engine, data):
|
||||
self.assertEqual('002', migration.version())
|
||||
self.assertColumnExists(engine, 'package', 'supplier_logo')
|
||||
|
|
Loading…
Reference in New Issue