Beispiel #1
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)
Beispiel #2
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)
def _migrate_linked_apps(apps, schema_editor):
    app_db = LinkedApplication.get_db()
    linked_apps = get_all_docs_with_doc_types(
        app_db, ['LinkedApplication', 'LinkedApplication-Deleted']
    )
    errors = []
    for app_doc in linked_apps:
        remote_details = None
        remote_url = app_doc.pop('remote_url_base', None)
        if remote_url:
            auth = app_doc.pop('remote_auth', {})
            remote_details = RemoteLinkDetails(
                remote_url,
                auth.get('username'),
                auth.get('api_key'),
            )

        master_domain = app_doc.pop('master_domain', None)
        if not master_domain and not remote_url:
            master_domain = get_app(None, app_doc['master']).domain
        try:
            DomainLink.link_domains(app_doc['domain'], master_domain, remote_details)
        except DomainLinkError as e:
            errors.append(str(e))
        else:
            app_db.save_doc(app_doc)

    _assert = soft_assert('{}@dimagi.com'.format('skelly'), exponential_backoff=False)
    _assert(not errors, 'Errors migrating linked apps to linked domain', {
        'errors': errors
    })