DB migration version
1. What is the problem Based on the bug report https://bugs.launchpad.net/tricircle/+bug/1652708, currently the version migrated to is fixed to 2 in cmd/manage.py. 2. What is the solution to the problem We should use the version specified in the CLI, if no target version is specified, then migrate the db to the latest version. 3. What the features need to be implemented to the Tricircle No new features Change-Id: I00703578ecd2017836be9ac6e93a4bfd784e650e
This commit is contained in:
parent
d9f4bb3258
commit
3457145512
|
@ -153,7 +153,7 @@ if [[ "$Q_ENABLE_TRICIRCLE" == "True" ]]; then
|
|||
setup_package $TRICIRCLE_DIR -e
|
||||
|
||||
recreate_database tricircle
|
||||
tricircle-db-manage "$TRICIRCLE_API_CONF"
|
||||
tricircle-db-manage --config-file="$TRICIRCLE_API_CONF" db_sync
|
||||
|
||||
if is_service_enabled q-svc ; then
|
||||
start_central_neutron_server $CENTRAL_REGION_NAME $TRICIRCLE_NEUTRON_PORT
|
||||
|
|
|
@ -17,19 +17,52 @@
|
|||
import sys
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from tricircle.db import core
|
||||
from tricircle.db import migration_helpers
|
||||
|
||||
import pbr.version
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
def do_db_version():
|
||||
print(migration_helpers.db_version())
|
||||
|
||||
|
||||
def do_db_sync():
|
||||
migration_helpers.sync_repo(CONF.command.version)
|
||||
|
||||
|
||||
def add_command_parsers(subparsers):
|
||||
parser = subparsers.add_parser('db_version')
|
||||
parser.set_defaults(func=do_db_version)
|
||||
|
||||
parser = subparsers.add_parser('db_sync')
|
||||
parser.set_defaults(func=do_db_sync)
|
||||
parser.add_argument('version', nargs='?')
|
||||
|
||||
command_opt = cfg.SubCommandOpt('command',
|
||||
title='Commands',
|
||||
help='Show available commands.',
|
||||
handler=add_command_parsers)
|
||||
|
||||
|
||||
def main():
|
||||
core.initialize()
|
||||
cfg.CONF(args=sys.argv[2:],
|
||||
project='tricircle',
|
||||
default_config_files=[sys.argv[1]])
|
||||
migration_helpers.find_migrate_repo()
|
||||
migration_helpers.sync_repo(2)
|
||||
logging.register_options(CONF)
|
||||
logging.setup(CONF, 'tricircle-db-manage')
|
||||
CONF.register_cli_opt(command_opt)
|
||||
version_info = pbr.version.VersionInfo('tricircle')
|
||||
|
||||
try:
|
||||
CONF(sys.argv[1:], project='tricircle', prog='tricircle-db-manage',
|
||||
version=version_info.version_string())
|
||||
except RuntimeError as e:
|
||||
sys.exit("ERROR: %s" % e)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
try:
|
||||
CONF.command.func()
|
||||
except Exception as e:
|
||||
sys.exit("ERROR: %s" % e)
|
||||
|
|
|
@ -23,6 +23,13 @@ from tricircle.db import core
|
|||
from tricircle.db import migrate_repo
|
||||
|
||||
|
||||
def db_version():
|
||||
engine = core.get_engine()
|
||||
repo_abs_path = find_migrate_repo()
|
||||
init_version = migrate_repo.DB_INIT_VERSION
|
||||
return migration.db_version(engine, repo_abs_path, init_version)
|
||||
|
||||
|
||||
def find_migrate_repo(package=None, repo_name='migrate_repo'):
|
||||
package = package or db
|
||||
path = os.path.abspath(os.path.join(
|
||||
|
|
Loading…
Reference in New Issue