'Place an existing database under migration control and upgrade it.'

@args('--version', metavar='<version>', help='Database    version')
def sync(self, version=db_migration.LATEST_REVISION):

    if (version is None):
        version = db_migration.LATEST_REVISION
    alembic_migrations.place_database_under_alembic_control()
    a_config = alembic_migrations.get_alembic_config()
    alembic_command.upgrade(a_config, version)
    heads = alembic_migrations.get_current_alembic_heads()
    if (heads is None):
        raise exception.GlanceException('Database    sync    failed')
    revs = ',    '.join(heads)
    if (version == 'heads'):
        print(_('Upgraded    database,    current    revision(s):'), revs)
    else:
        print((_('Upgraded    database    to:    %(v)s,    current    revision(s):    %(r)s') % {'v': version, 'r': revs}))
