-
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
28 changed files
with
8,150 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,78 @@ | ||
# | ||
# 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 sqlalchemy import func | ||
|
||
from rero_mef.utils import get_entity_class | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '28982ef7ce63' | ||
down_revision = '0d0b3009dbe0' | ||
branch_labels = () | ||
depends_on = None | ||
|
||
|
||
agents = { | ||
'aggnd': 'GND', | ||
'aidref': 'IDREF', | ||
'agrero': 'RERO' | ||
} | ||
|
||
|
||
def commit_changes(indexer, ids): | ||
"""Commit changes and reindex.""" | ||
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) | ||
|
||
count = agent_class.model_cls.query.filter( | ||
agent_class.model_cls.json.op('->')('bf:Agent') is not None | ||
).update( | ||
{ | ||
agent_class.model_cls.json: | ||
agent_class.model_cls.json - "bf:Agent" | ||
}, | ||
synchronize_session=False | ||
) | ||
click.echo( | ||
f'Delete bf:Agent from {agent}: {count}') | ||
db.session.commit() | ||
# For ES: update mapping must be done. | ||
|
||
|
||
def downgrade(): | ||
"""Downgrade database.""" | ||
for agent, name in agents.items(): | ||
agent_class = get_entity_class(agent) | ||
|
||
count = agent_class.model_cls.query.filter( | ||
agent_class.model_cls.json.op('->')('type') is not None | ||
).update( | ||
{ | ||
"json": func.jsonb_set( | ||
agent_class.model_cls.json, | ||
'{bf:Agent}', | ||
agent_class.model_cls.json.op('->')('type') | ||
) | ||
}, | ||
synchronize_session=False | ||
) | ||
click.echo( | ||
f'Add bf:Agent to {agent}: {count}') | ||
db.session.commit() | ||
# For ES: update mapping must be done | ||
# and all agents and MEF have to be reindexed |
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
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.