Ejemplo n.º 1
0
    def inner(table_name: str, repo: Dolt) -> DoltTableUpdate:
        if branch and branch != repo.log():
            repo.checkout(branch)

        query_commit = commit_ref or list(repo.log().keys())[0]
        table = get_table_metadata(repo.engine, table_name)
        from_commit, to_commit = get_from_commit_to_commit(repo, query_commit)
        pks_to_drop = get_dropped_pks(repo.engine, table, from_commit,
                                      to_commit)
        result = _read_from_dolt_history(repo.engine, table, query_commit)
        return pks_to_drop, result
Ejemplo n.º 2
0
def validate_get_table_metadata(engine: Engine, table_name: str):
    """
    Verify that get_table_metadata correctly constructs the metadata associated with the test table. We manually build
    that metadata in helpers/data_helper.py to verify this.
    :param engine:
    :param table_name:
    :return:
    """
    result = get_table_metadata(engine, table_name)
    assert str(TEST_TABLE_METADATA.name) == str(result.name)
    assert len(TEST_TABLE_METADATA.columns) == len(result.columns)
    assert set(col.name for col in TEST_TABLE_METADATA.columns) == set(
        col.name for col in result.columns)
Ejemplo n.º 3
0
    def assertion_helper(commit: str, expected_diff: List[dict]):
        """
        Validates that both the HEAD of the current branch of the Dolt repo match MySQL, and that the diffs created by
        the write match what is expected.
        """
        _, dolt_data = get_dolt_table_reader(commit)(str(dolt_table.name),
                                                     dolt_repo)
        db_table_metadata = get_table_metadata(db_engine, str(db_table.name))
        db_data = get_db_table_reader()(db_engine, db_table_metadata)
        assert_rows_equal(list(dolt_data), db_data)

        _, dolt_diff_data = get_dolt_table_reader_diffs(commit)(str(
            dolt_table.name), dolt_repo)
        assert_rows_equal(expected_diff, list(dolt_diff_data))
Ejemplo n.º 4
0
def test_postgres_to_dolt_array_types(postgres_with_table_with_arrays,
                                      repo_with_table_with_arrays):
    postgres_engine, postgres_table = postgres_with_table_with_arrays
    dolt_repo, dolt_table = repo_with_table_with_arrays

    get_postgres_target_writer(postgres_engine)({
        str(postgres_table.name): ([], TEST_DATA_WITH_ARRAYS)
    })
    source_reader = get_source_reader(postgres_engine, get_table_reader())
    target_writer = get_dolt_target_writer(dolt_repo, commit=True)
    sync_to_dolt(source_reader, target_writer,
                 {str(postgres_table.name): str(dolt_table.name)})
    latest_commit = list(dolt_repo.log().keys())[0]

    _, dolt_data = get_dolt_table_reader(latest_commit)(str(dolt_table.name),
                                                        dolt_repo)
    db_table_metadata = get_table_metadata(postgres_engine,
                                           str(postgres_table.name))
    db_data = get_table_reader()(postgres_engine, db_table_metadata)
    clean_dolt_data = deserialize_longtext(dolt_data)
    assert_rows_equal(clean_dolt_data, db_data, lambda dic: dic['id'])
Ejemplo n.º 5
0
def _dolt_table_read_helper(repo: Dolt, table_name: str):
    table = get_table_metadata(repo.engine, table_name)
    with repo.engine.connect() as conn:
        result = conn.execute(table.select())
        return [dict(row) for row in result]