-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jsonschemas: add 2 new document types
* Adds conference object and book review document types for documents and deposits. * Changes value and label for document_type_other for better clarity. * Initializes alembic. * Includes alembic script for db migration. * Closes #881. Co-Authored-by: Pascal Repond <[email protected]>
- Loading branch information
1 parent
dae2214
commit 11236f2
Showing
7 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
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,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# SONAR | ||
# Copyright (C) 2022 RERO+ | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Initialize alembic.""" | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "3d3309f660e4" | ||
down_revision = None | ||
branch_labels = ("sonar",) | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
"""Upgrade database.""" | ||
|
||
|
||
def downgrade(): | ||
"""Downgrade database.""" |
62 changes: 62 additions & 0 deletions
62
sonar/alembic/e1eb7549728f_replace_document_type_field_in_documents.py
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,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# SONAR | ||
# Copyright (C) 2022 RERO+ | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Replace document type field in documents.""" | ||
from logging import getLogger | ||
|
||
from invenio_db import db | ||
|
||
from sonar.modules.api import SonarRecord | ||
from sonar.modules.documents.api import DocumentSearch | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "e1eb7549728f" | ||
down_revision = "3d3309f660e4" | ||
branch_labels = () | ||
depends_on = None | ||
|
||
LOGGER = getLogger("alembic") | ||
|
||
|
||
def upgrade(): | ||
"""Upgrade database.""" | ||
migrate_doctype("other", "other_thesis") | ||
|
||
|
||
def downgrade(): | ||
"""Downgrade database.""" | ||
migrate_doctype("other_thesis", "other") | ||
|
||
|
||
def migrate_doctype(old_value, new_value): | ||
"""Change doctype in all documents.""" | ||
# find documents to modify | ||
doc_search = DocumentSearch() | ||
|
||
n = 0 | ||
for hit in doc_search.filter("term", documentType=old_value).scan(): | ||
# get the record in the database | ||
record = SonarRecord.get_record_by_pid(hit.pid) | ||
# update the record | ||
record["documentType"] = new_value | ||
# commit and reindex | ||
record.commit() | ||
db.session.commit() | ||
record.reindex() | ||
n += 1 | ||
|
||
LOGGER.info(f"{n} documents updated.") |
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