Example #1
0
def get_document_store(data_source_type, data_source_name, domain):
    if data_source_type == COUCH:
        try:
            return CouchDocumentStore(
                couch_config.get_db_for_db_name(data_source_name))
        except DatabaseNotFound:
            # in debug mode we may be flipping around our databases so don't fail hard here
            if settings.DEBUG:
                return None
            raise
    elif data_source_type == FORM_SQL:
        return ReadonlyFormDocumentStore(domain)
    elif data_source_type == CASE_SQL:
        return ReadonlyCaseDocumentStore(domain)
    elif data_source_type == SMS:
        return ReadonlySMSDocumentStore()
    elif data_source_type == LEDGER_V2:
        return ReadonlyLedgerV2DocumentStore(domain)
    elif data_source_type == LEDGER_V1:
        return LedgerV1DocumentStore(domain)
    elif data_source_type == LOCATION:
        return ReadonlyLocationDocumentStore(domain)
    else:
        raise UnknownDocumentStore(
            'getting document stores for backend {} is not supported!'.format(
                data_source_type))
Example #2
0
def get_document_store_for_doc_type(domain,
                                    doc_type,
                                    case_type_or_xmlns=None,
                                    load_source="unknown"):
    """Only applies to documents that have a document type:
    * forms
    * cases
    * locations
    * leddgers (V2 only)
    * all couch models
    """
    from corehq.apps.change_feed import document_types
    if doc_type in all_known_formlike_doc_types():
        store = FormDocumentStore(domain, xmlns=case_type_or_xmlns)
        load_counter = form_load_counter
    elif doc_type in document_types.CASE_DOC_TYPES:
        store = CaseDocumentStore(domain, case_type=case_type_or_xmlns)
        load_counter = case_load_counter
    elif doc_type == LOCATION_DOC_TYPE:
        return LocationDocumentStore(domain)
    elif doc_type == topics.LEDGER:
        return LedgerV2DocumentStore(domain)
    else:
        # all other types still live in couchdb
        return CouchDocumentStore(couch_db=get_db_by_doc_type(doc_type),
                                  domain=domain,
                                  doc_type=doc_type)
    track_load = load_counter(load_source, domain)
    return DocStoreLoadTracker(store, track_load)
def get_document_store(data_source_type, data_source_name, domain):
    # change this to just 'data_source_name' after June 2018
    type_or_name = (data_source_type, data_source_name)
    if data_source_type == SOURCE_COUCH:
        try:
            return CouchDocumentStore(
                couch_config.get_db_for_db_name(data_source_name))
        except DatabaseNotFound:
            # in debug mode we may be flipping around our databases so don't fail hard here
            if settings.DEBUG:
                return None
            raise
    elif FORM_SQL in type_or_name:
        return ReadonlyFormDocumentStore(domain)
    elif CASE_SQL in type_or_name:
        return ReadonlyCaseDocumentStore(domain)
    elif SMS in type_or_name:
        return ReadonlySMSDocumentStore()
    elif LEDGER_V2 in type_or_name:
        return ReadonlyLedgerV2DocumentStore(domain)
    elif LEDGER_V1 in type_or_name:
        return LedgerV1DocumentStore(domain)
    elif LOCATION in type_or_name:
        return ReadonlyLocationDocumentStore(domain)
    elif SYNCLOG_SQL in type_or_name:
        return ReadonlySyncLogDocumentStore()
    else:
        raise UnknownDocumentStore(
            'getting document stores for backend {} is not supported!'.format(
                data_source_type))
Example #4
0
 def __init__(self, couch_db, include_docs, couch_filter=None, extra_couch_view_params=None):
     self._couch_db = couch_db
     self._document_store = CouchDocumentStore(couch_db)
     self._couch_filter = couch_filter
     self._include_docs = include_docs
     self._extra_couch_view_params = extra_couch_view_params or {}
     self._last_processed_seq = None
Example #5
0
def get_document_store(domain, doc_type):
    use_sql = should_use_sql_backend(domain)
    if use_sql and doc_type == 'XFormInstance':
        return ReadonlyFormDocumentStore(domain)
    elif use_sql and doc_type == 'CommCareCase':
        return ReadonlyCaseDocumentStore(domain)
    else:
        # all other types still live in couchdb
        return CouchDocumentStore(couch_db=get_db_by_doc_type(doc_type),
                                  domain=domain,
                                  doc_type=doc_type)
Example #6
0
def get_document_store(domain, doc_type, case_type_or_xmlns=None):
    if doc_type == 'XFormInstance':
        return ReadonlyFormDocumentStore(domain, xmlns=case_type_or_xmlns)
    elif doc_type == 'CommCareCase':
        return ReadonlyCaseDocumentStore(domain, case_type=case_type_or_xmlns)
    elif doc_type == LOCATION_DOC_TYPE:
        return ReadonlyLocationDocumentStore(domain)
    else:
        # all other types still live in couchdb
        return CouchDocumentStore(couch_db=get_db_by_doc_type(doc_type),
                                  domain=domain,
                                  doc_type=doc_type)
Example #7
0
class TestEnsureDocumentExists(TestCase):
    domain = 'ensure-domain'

    def _create_change(self):
        case = CommCareCase(domain=self.domain)
        case.save()

        change = Change(case._id,
                        'seq',
                        document_store=CouchDocumentStore(
                            CommCareCase.get_db(),
                            self.domain,
                        ))
        return change, case
Example #8
0
 def iter_all_changes(self, start_from=None):
     view_kwargs = copy(self._view_kwargs)
     view_kwargs['reduce'] = False  # required to paginate a view
     if start_from is not None:
         # todo: should we abstract out how the keys work inside this class?
         view_kwargs['startkey'] = start_from
     for row in paginate_view(self._couch_db, self._view_name,
                              self._chunk_size, **view_kwargs):
         # todo: if include_docs isn't specified then this will make one request to couch per row
         # to get the documents. In the future we will likely need to add chunking
         yield Change(id=row['id'],
                      sequence_id=None,
                      document=row.get('doc'),
                      deleted=False,
                      document_store=CouchDocumentStore(self._couch_db))
def get_document_store_for_doc_type(domain, doc_type, case_type_or_xmlns=None):
    """Only applies to documents that have a document type:
    * forms
    * cases
    * locations
    * all couch models
    """
    from corehq.apps.change_feed import document_types
    if doc_type in all_known_formlike_doc_types():
        return ReadonlyFormDocumentStore(domain, xmlns=case_type_or_xmlns)
    elif doc_type in document_types.CASE_DOC_TYPES:
        return ReadonlyCaseDocumentStore(domain, case_type=case_type_or_xmlns)
    elif doc_type == LOCATION_DOC_TYPE:
        return ReadonlyLocationDocumentStore(domain)
    else:
        # all other types still live in couchdb
        return CouchDocumentStore(couch_db=get_db_by_doc_type(doc_type),
                                  domain=domain,
                                  doc_type=doc_type)
Example #10
0
def get_document_store(data_source_type,
                       data_source_name,
                       domain,
                       load_source="unknown"):
    # change this to just 'data_source_name' after June 2018
    type_or_name = (data_source_type, data_source_name)
    if data_source_type == SOURCE_COUCH:
        try:
            return CouchDocumentStore(
                couch_config.get_db_for_db_name(data_source_name))
        except DatabaseNotFound:
            # in debug mode we may be flipping around our databases so don't fail hard here
            if settings.DEBUG:
                return None
            raise
    elif FORM_SQL in type_or_name:
        store = FormDocumentStore(domain)
        load_counter = form_load_counter
    elif CASE_SQL in type_or_name:
        store = CaseDocumentStore(domain)
        load_counter = case_load_counter
    elif SMS in type_or_name:
        store = SMSDocumentStore()
        load_counter = sms_load_counter
    elif LEDGER_V2 in type_or_name:
        store = LedgerV2DocumentStore(domain)
        load_counter = ledger_load_counter
    elif LEDGER_V1 in type_or_name:
        store = LedgerV1DocumentStore(domain)
        load_counter = ledger_load_counter
    elif LOCATION in type_or_name:
        return LocationDocumentStore(domain)
    elif SYNCLOG_SQL in type_or_name:
        return SyncLogDocumentStore()
    else:
        raise UnknownDocumentStore(
            'getting document stores for backend {} is not supported!'.format(
                data_source_type))
    track_load = load_counter(load_source, domain)
    return DocStoreLoadTracker(store, track_load)
Example #11
0
 def dao(self):
     return CouchDocumentStore(FakeCouchDb())