예제 #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
예제 #2
0
    def inner(table_name: str, repo: Dolt) -> DoltTableUpdate:
        current_branch, _ = repo.branch()
        if branch and branch != current_branch:
            repo.checkout(branch)

        from_commit, to_commit = get_from_commit_to_commit(repo, commit_ref)
        metadata = MetaData(bind=repo.engine)
        metadata.reflect()
        table = metadata.tables[table_name]
        pks_to_drop = get_dropped_pks(repo.engine, table, from_commit,
                                      to_commit)
        result = _read_from_dolt_diff(repo.engine, table, from_commit,
                                      to_commit)
        return pks_to_drop, result
예제 #3
0
    def inner(repo: Dolt):
        current_branch, current_branch_list = repo.branch()
        original_branch = current_branch.name

        if branch != original_branch and not commit:
            raise ValueError(
                'If writes are to another branch, and commit is not True, writes will be lost'
            )

        if current_branch.name != branch:
            logger.info('Current branch is {}, checking out {}'.format(
                current_branch.name, branch))
            if branch not in [b.name for b in current_branch_list]:
                logger.info('{} does not exist, creating'.format(branch))
                repo.branch(branch_name=branch)
            repo.checkout(branch)

        if transaction_mode:
            raise NotImplementedError(
                'transaction_mode is not yet implemented')

        tables_updated = [writer(repo) for writer in writers]

        if commit:
            if not repo.status().is_clean:
                logger.info(
                    'Committing to repo located in {} for tables:\n{}'.format(
                        repo.repo_dir, tables_updated))
                for table in tables_updated:
                    repo.add(table)
                repo.commit(message)

            else:
                logger.warning('No changes to repo in:\n{}'.format(
                    repo.repo_dir))

        current_branch, branches = repo.branch()
        if original_branch != current_branch.name:
            logger.info(
                'Checked out {} from {}, checking out {} to restore state'.
                format([b.name for b in branches], original_branch,
                       original_branch))
            repo.checkout(original_branch)

        return branch