Exemple #1
0
def upgrade(ctx):
    """
    Upgrade the database to revision
    """
    try:
        upgrade_path = get_upgrade_path(ctx.obj.db_path)
    except NoMigrationsFoundException:
        click.echo("Did not find any migrations to run in %s" %
                   ctx.obj.db_path)
        click.echo(
            "Have you tried running `tomb db revision -m <description>`?")
        sys.exit(1)

    for revision in upgrade_path:
        for name, engine in ctx.obj.db_engines.items():
            current_version = engine.current_version()
            if current_version >= revision.version:
                msg = "%s already on %s, skipping" % (engine, revision.version)
                click.echo(click.style(msg, fg='yellow'))
                continue

            click.echo('Running upgrade %s on %s' % (revision, engine))

            try:
                revision.upgrade(engine)
                engine.update(revision.version)
            except NotInitializedException:
                msg = (
                    "Upgraded was not completed!, Looks like %s has not been "
                    "initialized. Run `tomb init`") % name
                error_msg(msg)
                sys.exit(1)

    click.echo('Done upgrading')
Exemple #2
0
def test_get_upgrade_path_with_version(list_dir, isdir, isfile, file_loader):
    from tomb_migrate.utils import get_upgrade_path
    from tomb_migrate.utils import Revision

    isfile.return_value = True
    isdir.return_value = True

    list_dir.return_value = [
        '00006_qix.py',
        '00001_foo.py',
        '00003_baz.py',
        '00002_bar.py',
        '00004_qux.py',
        '00010_peña.py',
        '00011_foo_bar_baz.py',
    ]

    files = get_upgrade_path('boom', version=3)

    expected = [
        Revision('00003_baz.py'),
        Revision('00004_qux.py'),
        Revision('00006_qix.py'),
        Revision('00010_peña.py'),
        Revision('00011_foo_bar_baz.py'),
    ]

    assert files == expected
Exemple #3
0
def test_get_upgrade_path_bad_file(list_dir, is_file, file_loader, mkdir):
    from tomb_migrate.utils import get_upgrade_path
    from tomb_migrate.utils import InvalidMigrationFileName

    is_file.return_value = True
    list_dir.return_value = [
        '00006_qix.py',
        '00001_foo.py',
        '00003_baz.py',
        '00002_bar.py',
        '00004_qux.py',
        '00010_peña.py',
        'foo.tmp~',
    ]

    with pytest.raises(InvalidMigrationFileName):
        get_upgrade_path('boom')