def downgrade(): """Downgrade patron type records.""" query = PatronTypesSearch()\ .filter('exists', field='limits.unpaid_subscription')\ .source('pid') patron_type_pids = [hit.pid for hit in query.scan()] ids = [] for pid in patron_type_pids: record = PatronType.get_record_by_pid(pid) del record['limits']['unpaid_subscription'] record.update(record, dbcommit=True, reindex=False) LOGGER.info(f' * Updated PatronType#{record.pid}') ids.append(record.id) _indexing_records(ids) LOGGER.info(f'TOTAL :: {len(ids)}')
def test_patron_type_es_mapping(es_clear, db, organisation, patron_type_data_tmp): """.""" search = PatronTypesSearch() mapping = get_mapping(search.Meta.index) assert mapping PatronType.create(patron_type_data_tmp, dbcommit=True, reindex=True, delete_pid=True) assert mapping == get_mapping(search.Meta.index)
def test_patron_type_es_mapping(es_clear, db, org_martigny, patron_type_children_martigny_data): """Test patron types es mapping.""" search = PatronTypesSearch() mapping = get_mapping(search.Meta.index) assert mapping PatronType.create(patron_type_children_martigny_data, dbcommit=True, reindex=True, delete_pid=True) assert mapping == get_mapping(search.Meta.index)
def upgrade(): """Upgrade patron type records. We need to add the new 'unpaid_subscription' limit to each patron_type records that doesn't already define such a limit. The default value for existing records will be `False` to not generate unstable behavior. """ query = PatronTypesSearch()\ .exclude('exists', field='limits.unpaid_subscription')\ .source('pid') patron_type_pids = [hit.pid for hit in query.scan()] ids = [] for pid in patron_type_pids: record = PatronType.get_record_by_pid(pid) record\ .setdefault('limits', {})\ .setdefault('unpaid_subscription', False) record.update(record, dbcommit=True, reindex=False) LOGGER.info(f' * Updated PatronType#{record.pid}') ids.append(record.id) _indexing_records(ids) LOGGER.info(f'TOTAL :: {len(ids)}')
def test_patron_types_search_mapping( app, patron_types_records ): """Test patron type search mapping.""" search = PatronTypesSearch() c = search.query('query_string', query='patrons').count() assert c == 4 c = search.query('match', name='patrons').count() assert c == 0 c = search.query('match', name='children').count() assert c == 1 pids = [r.pid for r in search.query( 'match', name='children').source(['pid']).scan()] assert 'ptty1' in pids