def print_stats(self, domain, short=True, diffs_only=False): status = get_couch_sql_migration_status(domain) if not self.live_migrate: self.live_migrate = status == MigrationStatus.DRY_RUN if self.missing_docs != CACHED: resume = self.missing_docs == RESUME find_missing_docs(domain, self.state_dir, self.live_migrate, resume) print("Couch to SQL migration status for {}: {}".format(domain, status)) statedb = open_state_db(domain, self.state_dir) doc_counts = statedb.get_doc_counts() has_diffs = False ZERO = Counts() for doc_type in ( list(doc_types()) + ["HQSubmission", "XFormInstance-Deleted"] + CASE_DOC_TYPES ): has_diffs |= self._print_status( doc_type, doc_counts.get(doc_type, ZERO), statedb, short, diffs_only, ) if diffs_only and not has_diffs: print(shell_green("No differences found between old and new docs!")) return has_diffs
def print_stats(self, domain, short=True, diffs_only=False): status = get_couch_sql_migration_status(domain) if not self.live_migrate: self.live_migrate = status == MigrationStatus.DRY_RUN if self.missing_docs == RECHECK: recheck_missing_docs(domain, self.state_dir) elif self.missing_docs != CACHED: resume = self.missing_docs == RESUME find_missing_docs(domain, self.state_dir, self.live_migrate, resume) print(f"Couch to SQL migration status for {domain}: {status}") statedb = open_state_db(domain, self.state_dir) doc_counts = statedb.get_doc_counts() has_diffs = False ZERO = Counts() print(f"{'':<22} Docs Diffs Missing Changes") for doc_type in (list(doc_types()) + ["HQSubmission", "XFormInstance-Deleted"] + CASE_DOC_TYPES): has_diffs |= self._print_status( doc_type, doc_counts.get(doc_type, ZERO), statedb, short, diffs_only, ) pending = statedb.count_undiffed_cases() if pending: print(shell_red(f"\nThere are {pending} case diffs pending.")) print( f"Resolution: couch_sql_diff cases {domain} --select=pending") return True if diffs_only and not has_diffs: print( shell_green("No differences found between old and new docs!")) return has_diffs
def print_stats(self, domain, short=True, diffs_only=False): status = get_couch_sql_migration_status(domain) print("Couch to SQL migration status for {}: {}".format( domain, status)) db = open_state_db(domain, self.state_dir) try: diff_stats = db.get_diff_stats() except OperationalError: diff_stats = {} has_diffs = False for doc_type in doc_types(): form_ids_in_couch = set(get_form_ids_by_type(domain, doc_type)) if doc_type == "XFormInstance": form_ids_in_couch.update( get_doc_ids_in_domain_by_type(domain, "HQSubmission", XFormInstance.get_db())) form_ids_in_sql = set( FormAccessorSQL.get_form_ids_in_domain_by_type( domain, doc_type)) diff_count, num_docs_with_diffs = diff_stats.pop(doc_type, (0, 0)) has_diffs |= self._print_status(doc_type, form_ids_in_couch, form_ids_in_sql, diff_count, num_docs_with_diffs, short, diffs_only) form_ids_in_couch = set( get_doc_ids_in_domain_by_type(domain, "XFormInstance-Deleted", XFormInstance.get_db())) form_ids_in_sql = set( FormAccessorSQL.get_deleted_form_ids_in_domain(domain)) diff_count, num_docs_with_diffs = diff_stats.pop( "XFormInstance-Deleted", (0, 0)) has_diffs |= self._print_status("XFormInstance-Deleted", form_ids_in_couch, form_ids_in_sql, diff_count, num_docs_with_diffs, short, diffs_only) ZERO = Counts(0, 0) if db.has_doc_counts(): doc_counts = db.get_doc_counts() couch_missing_cases = doc_counts.get("CommCareCase-couch", ZERO).missing else: doc_counts = None couch_missing_cases = 0 for doc_type in CASE_DOC_TYPES: if doc_counts is not None: counts = doc_counts.get(doc_type, ZERO) case_ids_in_couch = db.get_missing_doc_ids( doc_type) if counts.missing else set() case_ids_in_sql = counts elif doc_type == "CommCareCase": case_ids_in_couch = set(get_case_ids_in_domain(domain)) case_ids_in_sql = set( CaseAccessorSQL.get_case_ids_in_domain(domain)) elif doc_type == "CommCareCase-Deleted": case_ids_in_couch = set( get_doc_ids_in_domain_by_type(domain, "CommCareCase-Deleted", XFormInstance.get_db())) case_ids_in_sql = set( CaseAccessorSQL.get_deleted_case_ids_in_domain(domain)) else: raise NotImplementedError(doc_type) diff_count, num_docs_with_diffs = diff_stats.pop(doc_type, (0, 0)) has_diffs |= self._print_status( doc_type, case_ids_in_couch, case_ids_in_sql, diff_count, num_docs_with_diffs, short, diffs_only, ) if doc_type == "CommCareCase" and couch_missing_cases: has_diffs = True print( shell_red("%s cases could not be loaded from Couch" % couch_missing_cases)) if not short: for case_id in db.get_missing_doc_ids( "CommCareCase-couch"): print(case_id) if diff_stats: for key, counts in diff_stats.items(): diff_count, num_docs_with_diffs = counts has_diffs |= self._print_status(key, set(), set(), diff_count, num_docs_with_diffs, short, diffs_only) if diffs_only and not has_diffs: print( shell_green("No differences found between old and new docs!")) return has_diffs