-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-by: Peter Weber <[email protected]>
- Loading branch information
Showing
27 changed files
with
8,179 additions
and
16,085 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ | |
"pid": { | ||
"type": "keyword" | ||
}, | ||
"bf:Agent": { | ||
"type": "keyword" | ||
}, | ||
"type": { | ||
"type": "keyword" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ | |
"pid": { | ||
"type": "keyword" | ||
}, | ||
"bf:Agent": { | ||
"type": "keyword" | ||
}, | ||
"type": { | ||
"type": "keyword" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ | |
"pid": { | ||
"type": "keyword" | ||
}, | ||
"bf:Agent": { | ||
"type": "keyword" | ||
}, | ||
"type": { | ||
"type": "keyword" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2016-2018 CERN. | ||
# | ||
# Invenio is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""delete bf:Agent""" | ||
|
||
import click | ||
from invenio_db import db | ||
|
||
from rero_mef.agents import AgentMefIndexer, AgentMefRecord | ||
from rero_mef.utils import get_entity_class, get_entity_indexer_class, \ | ||
progressbar | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '28982ef7ce63' | ||
down_revision = '0d0b3009dbe0' | ||
branch_labels = () | ||
depends_on = None | ||
|
||
COMMIT_COUNT = 1000 | ||
|
||
agents = { | ||
'aggnd': 'GND', | ||
'aidref': 'IDREF', | ||
'agrero': 'RERO' | ||
} | ||
|
||
|
||
def commit_changes(indexer, ids): | ||
db.session.commit() | ||
indexer.bulk_index(ids) | ||
indexer.process_bulk_queue() | ||
|
||
|
||
def upgrade(): | ||
"""Upgrade database.""" | ||
for agent, name in agents.items(): | ||
agent_class = get_entity_class(agent) | ||
indexer = get_entity_indexer_class(agent)() | ||
click.echo( | ||
f'Delete bf:Agent from {agent}: {agent_class.count()}') | ||
progress_bar = progressbar( | ||
items=agent_class.get_all_records(), | ||
length=agent_class.count(), | ||
verbose=True | ||
) | ||
ids = [] | ||
for idx, rec in enumerate(progress_bar, 1): | ||
rec.pop('bf:Agent', None) | ||
ids.append(rec.id) | ||
rec.update(data=rec, dbcommit=False, reindex=False) | ||
if idx % COMMIT_COUNT == 0: | ||
commit_changes(indexer, ids) | ||
ids = [] | ||
commit_changes(indexer, ids) | ||
|
||
click.echo(f'Delete bf:Agent from mef: {AgentMefRecord.count()}') | ||
progress_bar = progressbar( | ||
items=AgentMefRecord.get_all_records(), | ||
length=AgentMefRecord.count(), | ||
verbose=True | ||
) | ||
ids = [] | ||
indexer = AgentMefIndexer() | ||
for idx, rec in enumerate(progress_bar, 1): | ||
rec.pop('bf:Agent', None) | ||
ids.append(rec.id) | ||
rec.update(data=rec, dbcommit=False, reindex=False) | ||
if idx % COMMIT_COUNT == 0: | ||
commit_changes(indexer, ids) | ||
ids = [] | ||
commit_changes(indexer, ids) | ||
|
||
|
||
def downgrade(): | ||
"""Downgrade database.""" | ||
for agent, name in agents.items(): | ||
agent_class = get_entity_class(agent) | ||
indexer = get_entity_indexer_class(agent)() | ||
click.echo( | ||
f'Add bf:Agent to {agent}: {agent_class.count()}') | ||
progress_bar = progressbar( | ||
items=agent_class.get_all_records(), | ||
length=agent_class.count(), | ||
verbose=True | ||
) | ||
ids = [] | ||
for idx, rec in enumerate(progress_bar, 1): | ||
rec['bf:Agent'] = rec['type'] | ||
ids.append(rec.id) | ||
rec.update(data=rec, dbcommit=False, reindex=False) | ||
if idx % COMMIT_COUNT == 0: | ||
commit_changes(indexer, ids) | ||
ids = [] | ||
commit_changes(indexer, ids) | ||
|
||
click.echo(f'Add bf:Agent to mef: {AgentMefRecord.count()}') | ||
progress_bar = progressbar( | ||
items=AgentMefRecord.get_all_records(), | ||
length=AgentMefRecord.count(), | ||
verbose=True | ||
) | ||
ids = [] | ||
indexer = AgentMefIndexer() | ||
for idx, rec in enumerate(progress_bar, 1): | ||
rec['bf:Agent'] = rec['type'] | ||
ids.append(rec.id) | ||
rec.update(data=rec, dbcommit=False, reindex=False) | ||
if idx % COMMIT_COUNT == 0: | ||
commit_changes(indexer, ids) | ||
ids = [] | ||
commit_changes(indexer, ids) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.