Ejemplo n.º 1
0
def _pop_deprecated_field(apps, schema_editor):
    app_ids = (get_doc_ids_by_class(LinkedApplication) +
               get_deleted_doc_ids_by_class(LinkedApplication))
    iter_update(LinkedApplication.get_db(),
                _pop_field,
                with_progress_bar(app_ids),
                chunksize=1)
Ejemplo n.º 2
0
    def handle(self, django_app, class_name, **options):
        self.class_name = class_name
        self.django_app = django_app
        self.models_path = f"corehq.apps.{self.django_app}.models.{self.class_name}"
        self.couch_class = to_function(self.models_path)
        while not self.couch_class:
            self.models_path = input(
                f"Could not find {self.models_path}, please enter path: ")
            self.couch_class = to_function(self.models_path)
            self.class_name = self.models_path.split(".")[-1]

        doc_ids = get_doc_ids_by_class(self.couch_class)
        print("Found {} {} docs\n".format(len(doc_ids), self.class_name))

        for doc in iter_docs(self.couch_class.get_db(), doc_ids):
            self.evaluate_doc(doc)

        self.standardize_max_lengths()

        models_file = self.models_path[:-(len(self.class_name) + 1)].replace(
            ".", os.path.sep) + ".py"
        models_content = self.generate_models_changes()
        print(f"################# edit {models_file} #################")
        print(models_content)

        command_file = "populate_" + self.class_name.lower() + ".py"
        command_file = os.path.join("corehq", "apps", self.django_app,
                                    "management", "commands", command_file)
        command_content = self.generate_management_command()
        print(f"################# add {command_file} #################")
        print(command_content)
Ejemplo n.º 3
0
    def handle(self,
               domain=None,
               app_id=None,
               dry_run=False,
               ignore_deleted=False,
               verbose=False,
               **options):
        self.dry_run = dry_run
        if verbose:
            logger.setLevel(logging.DEBUG)
        else:
            logger.setLevel(logging.ERROR)

        if domain and app_id:
            app = get_app(
                domain,
                app_id)  # Sanity check, will 404 if domain doesn't match
            assert (app.doc_type == 'LinkedApplication'
                    or app.doc_type == 'LinkedApplication-Deleted')
            app_ids = set([
                v.build_id
                for v in get_all_built_app_ids_and_versions(domain, app_id)
            ])
            app_ids.add(app_id)  # in case linked app has no builds yet
        else:
            app_ids = get_doc_ids_by_class(LinkedApplication)
            if not ignore_deleted:
                app_ids += get_deleted_doc_ids_by_class(LinkedApplication)
        iter_update(LinkedApplication.get_db(),
                    self._add_overrides_for_build,
                    with_progress_bar(app_ids),
                    chunksize=1)
Ejemplo n.º 4
0
def saved_exports():
    for group_config_id in get_doc_ids_by_class(HQGroupExportConfiguration):
        export_for_group_async.delay(group_config_id)

    for daily_saved_export_id in get_all_daily_saved_export_instance_ids():
        last_access_cutoff = datetime.utcnow() - timedelta(days=settings.SAVED_EXPORT_ACCESS_CUTOFF)
        rebuild_saved_export(daily_saved_export_id, last_access_cutoff, manual=False)
Ejemplo n.º 5
0
def saved_exports():
    for group_config_id in get_doc_ids_by_class(HQGroupExportConfiguration):
        export_for_group_async.delay(group_config_id)

    for daily_saved_export_id in get_all_daily_saved_export_instance_ids():
        from corehq.apps.export.tasks import rebuild_export_task
        last_access_cutoff = datetime.utcnow() - timedelta(
            days=settings.SAVED_EXPORT_ACCESS_CUTOFF)
        rebuild_export_task.delay(daily_saved_export_id, last_access_cutoff)
Ejemplo n.º 6
0
 def handle(self, dry_run=False, *args, **options):
     self.dry_run = dry_run
     self.reports_using_transform = set()
     report_ids = get_doc_ids_by_class(ReportConfiguration)
     res = iter_update(
         db=ReportConfiguration.get_db(),
         fn=self.migrate_report,
         ids=with_progress_bar(report_ids),
         verbose=True,
     )
     print "Found {} reports using the transform:".format(len(self.reports_using_transform))
     print "\n".join(self.reports_using_transform)
     print "Updated the following reports:"
     print "\n".join(res.updated_ids)
Ejemplo n.º 7
0
def saved_exports():
    for group_config_id in get_doc_ids_by_class(HQGroupExportConfiguration):
        export_for_group_async.delay(group_config_id)

    for daily_saved_export_id in get_all_daily_saved_export_instance_ids():
        from corehq.apps.export.tasks import rebuild_export_task
        last_access_cutoff = datetime.utcnow() - timedelta(
            days=settings.SAVED_EXPORT_ACCESS_CUTOFF)
        rebuild_export_task.apply_async(
            args=[daily_saved_export_id, last_access_cutoff],
            # Normally the rebuild_export_task uses the background queue,
            # however we want to override it to use its own queue so that it does
            # not disrupt other actions.
            queue=SAVED_EXPORTS_QUEUE,
        )
Ejemplo n.º 8
0
 def handle(self, dry_run=False, **options):
     self.dry_run = dry_run
     self.reports_using_transform = set()
     report_ids = get_doc_ids_by_class(ReportConfiguration)
     res = iter_update(
         db=ReportConfiguration.get_db(),
         fn=self.migrate_report,
         ids=with_progress_bar(report_ids),
         verbose=True,
     )
     print("Found {} reports using the transform:".format(
         len(self.reports_using_transform)))
     print("\n".join(self.reports_using_transform))
     print("Updated the following reports:")
     print("\n".join(res.updated_ids))
Ejemplo n.º 9
0
    def handle(self, **options):
        config_ids = get_doc_ids_by_class(ReportConfiguration)

        builder_count, ucr_count = 0, 0
        for doc in iter_docs(ReportConfiguration.get_db(), config_ids):
            if doc['report_meta']['created_by_builder']:
                builder_count += 1
            else:
                ucr_count += 1

        static_count = len(list(StaticReportConfiguration.all()))
        total_count = builder_count + ucr_count + static_count

        print(textwrap.dedent("""
            As of {}, on {} there are {} total UCRs:
            {} Report Builder Reports
            {} UCR Report Configs
            {} Static Report Configs enabled for the environment
        """.format(datetime.utcnow().date(), settings.SERVER_ENVIRONMENT, total_count,
                   builder_count, ucr_count, static_count)))
Ejemplo n.º 10
0
    def handle(self, django_app, class_name, **options):
        path = f"corehq.apps.{django_app}.models.{class_name}"
        couch_class = to_function(path)
        while not couch_class:
            path = input(f"Could not find {path}, please enter path: ")
            couch_class = to_function(path)
            class_name = path.split(".")[-1]

        doc_ids = get_doc_ids_by_class(couch_class)
        print("Found {} {} docs\n".format(len(doc_ids), class_name))

        for doc in iter_docs(couch_class.get_db(), doc_ids):
            self.evaluate_doc(doc)

        for key, field in self.field_data.items():
            print("{} is a {}, is {} null and has max length of {}".format(
                key,
                field['field_type'] or 'unknown',
                'somtimes' if field['null'] else 'never',
                field['max_length'],
            ))
Ejemplo n.º 11
0
    def handle(self, **options):
        config_ids = get_doc_ids_by_class(ReportConfiguration)

        builder_count, ucr_count = 0, 0
        for doc in iter_docs(ReportConfiguration.get_db(), config_ids):
            if doc['report_meta']['created_by_builder']:
                builder_count += 1
            else:
                ucr_count += 1

        static_count = len(list(StaticReportConfiguration.all()))
        total_count = builder_count + ucr_count + static_count

        print(
            textwrap.dedent("""
            As of {}, on {} there are {} total UCRs:
            {} Report Builder Reports
            {} UCR Report Configs
            {} Static Report Configs enabled for the environment
        """.format(datetime.utcnow().date(), settings.SERVER_ENVIRONMENT,
                   total_count, builder_count, ucr_count, static_count)))
    def handle(self, dry_run=False, **options):
        def _add_field(doc):
            updated = False
            log_prefix = "{} Domain {}, form unique_id {}".format(
                "[DRY RUN]" if dry_run else "", doc['domain'],
                doc['form_unique_id'])

            if doc.get('form_unique_id', None) and not doc.get('app_id', None):
                doc['app_id'] = get_app_id_from_form_unique_id(
                    doc['domain'], doc['form_unique_id'])
                if doc['app_id']:
                    updated = True
                    logger.info("{}: Updated {} to use app id {}".format(
                        log_prefix, doc['_id'], doc['app_id']))
                else:
                    logger.info("{}: Could not find app".format(log_prefix))

            for action in doc.get('actions', []):
                if action.get('form_unique_id',
                              None) and not action.get('app_id', None):
                    action['app_id'] = get_app_id_from_form_unique_id(
                        doc['domain'], action['form_unique_id'])
                    if action['app_id']:
                        updated = True
                        logger.info(
                            "{}: Updated action in {} to use app id {}".format(
                                log_prefix, doc['_id'], action['app_id']))
                    else:
                        logger.info(
                            "{}: Could not find app".format(log_prefix))

            if updated and not dry_run:
                return DocUpdate(doc)

        doc_ids = get_doc_ids_by_class(
            SurveyKeyword) + get_deleted_doc_ids_by_class(SurveyKeyword)
        iter_update(SurveyKeyword.get_db(), _add_field, doc_ids)
Ejemplo n.º 13
0
 def test_get_all_hq_group_export_configs(self):
     self.assertEqual(len(get_doc_ids_by_class(HQGroupExportConfiguration)),
                      3)
Ejemplo n.º 14
0
def update_all_roles():
    all_role_ids = get_doc_ids_by_class(UserRole)
    iter_update(UserRole.get_db(), update_role, with_progress_bar(all_role_ids), verbose=True)
Ejemplo n.º 15
0
def get_all_role_ids():
    return get_doc_ids_by_class(UserRole)
Ejemplo n.º 16
0
 def test_get_all_hq_group_export_configs(self):
     self.assertEqual(len(get_doc_ids_by_class(HQGroupExportConfiguration)), 3)