Esempio n. 1
0
def test_reset_autoincrements(base_db):
    engines = base_db.engines
    shard_schemas = get_shard_schemas()

    # A correctly set auto_increment.
    key = 0
    init_db(engines[key], key)
    reset_tables = reset_invalid_autoincrements(engines[key],
                                                shard_schemas[key], key,
                                                False)
    assert len(reset_tables) == 0

    # Ensure dry_run mode does not reset tables
    key = 1
    init_db(engines[key], key + 1)
    reset_tables = reset_invalid_autoincrements(engines[key],
                                                shard_schemas[key], key,
                                                True)
    assert len(reset_tables) > 0

    with pytest.raises(AssertionError):
        verify_db(engines[key], shard_schemas[key], key)

    reset_tables = reset_invalid_autoincrements(engines[key],
                                                shard_schemas[key], key,
                                                False)

    assert len(reset_tables) > 0
    verify_db(engines[key], shard_schemas[key], key)
Esempio n. 2
0
def test_reset_autoincrements(base_db):
    engines = base_db.engines
    shard_schemas = get_shard_schemas()

    # A correctly set auto_increment.
    key = 0
    init_db(engines[key], key)
    reset_tables = reset_invalid_autoincrements(engines[key],
                                                shard_schemas[key], key, False)
    assert len(reset_tables) == 0

    # Ensure dry_run mode does not reset tables
    key = 1
    init_db(engines[key], key + 1)
    reset_tables = reset_invalid_autoincrements(engines[key],
                                                shard_schemas[key], key, True)
    assert len(reset_tables) > 0

    with pytest.raises(AssertionError):
        verify_db(engines[key], shard_schemas[key], key)

    reset_tables = reset_invalid_autoincrements(engines[key],
                                                shard_schemas[key], key, False)

    assert len(reset_tables) > 0
    verify_db(engines[key], shard_schemas[key], key)
Esempio n. 3
0
def reset_db(dry_run):
    maybe_enable_rollbar()

    database_hosts = config.get_required("DATABASE_HOSTS")
    database_users = config.get_required("DATABASE_USERS")
    # Do not include disabled shards since application services do not use them.
    engine_manager = EngineManager(database_hosts,
                                   database_users,
                                   include_disabled=False)

    for host in database_hosts:
        for shard in host["SHARDS"]:
            if shard.get("DISABLED"):
                continue
            key = int(shard["ID"])
            engine = engine_manager.engines[key]
            schema = shard["SCHEMA_NAME"]

            print("Resetting invalid autoincrements for database: {}".format(
                schema))
            reset_tables = reset_invalid_autoincrements(
                engine, schema, key, dry_run)
            if dry_run:
                print("dry_run=True")
            if reset_tables:
                print("Reset tables: {}".format(", ".join(reset_tables)))
            else:
                print("Schema {} okay".format(schema))