-
Notifications
You must be signed in to change notification settings - Fork 13
Migration workflow
Johnny Mariéthoz edited this page Feb 12, 2026
·
55 revisions
- Change grobid version to
grobid/grobid:0.8.2-crf
- for all projects where organisation is not "hepvs", delete
validationfield
"""Remove validation field from projects not belonging to hepvs.
Usage (from flask shell):
from scripts.remove_validation_non_hepvs import run
run(dry_run=True) # simulation
run() # exécution réelle
"""
from elasticsearch_dsl import Q, Search
from invenio_db import db
from invenio_pidstore.models import PersistentIdentifier
from invenio_search import current_search
from sonar.resources.projects.api import Record
from sonar.proxies import sonar
def run(dry_run=False):
"""Remove the validation field from all projects not belonging to hepvs."""
client = current_search.client
service = sonar.service("projects")
# Search for projects that:
# - do NOT belong to organisation "hepvs"
# - have a validation field
search = Search(using=client, index="projects").query(
Q(
"bool",
must=[
Q("exists", field="metadata.validation"),
],
must_not=[
Q("term", metadata__organisation__pid="hepvs"),
],
)
)
total = search.count()
print(f"Found {total} project(s) to update.")
if total == 0:
print("Nothing to do.")
return
updated = 0
errors = 0
for hit in search.scan():
project_id = hit.meta.id
try:
record = Record.get_record(project_id)
except Exception as exc:
print(f" ERROR loading project {project_id}: {exc}")
errors += 1
continue
org_info = hit.to_dict().get("metadata", {}).get("organisation", {})
org_pid = org_info.get("pid", "unknown")
if "validation" not in record.get("metadata", {}):
print(f" Skipping {project_id} (org={org_pid}): no validation field in DB.")
continue
print(f" Removing validation from project {project_id} (org={org_pid})")
if not dry_run:
del record["metadata"]["validation"]
record.commit()
db.session.commit()
service.indexer.index(record)
updated += 1
if dry_run:
print(f"\n[DRY RUN] Would have updated {updated} project(s). {errors} error(s).")
else:
print(f"\nDone. Updated {updated} project(s). {errors} error(s).")uv run invenio alembic stamp 428b919be0ea
uv run invenio alembic upgradefrom invenio_search import current_search_client
current_search_client.indices.create('records-record-v1.0.0')uv run invenio rero es index update-mappingRemove _oai in documents.
# estimation for 300'000 records: 5h
from invenio_pidstore.models import PersistentIdentifier
from rero_invenio_base.modules.tasks import run_on_worker
from rero_invenio_base.modules.utils import chunk
code = '''
def pop_oai(_ids):
from sonar.modules.documents.api import DocumentRecord
from invenio_db import db
success = 0
failed = 0
for uuid in _ids:
try:
record = DocumentRecord.get_record(uuid)
if record.get('_oai'):
record['_oai'].pop('updated', None)
record['_oai'].pop('sets', None)
record.commit()
db.session.commit()
record.reindex()
success += 1
except Exception as err:
print(f"Exception {uuid}: {err}")
failed += 1
return {"success": success, "failed": failed}
'''
parallel = 7
ids = [pid.object_uuid for pid in PersistentIdentifier.query.filter_by(pid_type='doc').filter_by(status='R').all()]
for count, c in enumerate(chunk([str(val) for val in ids], len(ids) // parallel), 1):
res = run_on_worker.delay(code, 'pop_oai', c)
print('documents', count, len(c), res)index_name=`uv run invenio rero es index info -i documents |grep -v percolator`
echo $index_name
uv run invenio rero es index move documents $index_name documents-document-v1.0.0-20250923 -v
uv run invenio index delete $index_name --yes-i-knowRemove category from deposit.
from sonar.modules.deposits.api import DepositRecord
n = 0
for pid in PersistentIdentifier.query.filter_by(
pid_type='depo').filter_by(status='R').all():
try:
record = DepositRecord.get_record(pid.object_uuid)
n += 1
changed = False
for f in record.get('_files', []):
if 'category' in f:
del f['category']
changed = True
if 'embargo' in f:
del f['embargo']
changed = True
if changed:
record.commit()
db.session.commit()
record.reindex()
except:
print(f"Failed to update record {pid.pid_value}")
print(f"Updated {n} records")index_name=`uv run invenio rero es index info -i deposits | grep -v percolator`
echo $index_name
uv run invenio rero es index move deposits $index_name deposits-deposit-v1.0.0-20250923 -v
uv run invenio index delete $index_name --yes-i-knowindex_name=`uv run invenio rero es index info -i organisations | grep -v percolator`
echo $index_name
uv run invenio rero es index move organisations $index_name organisations-organisation-v1.0.0-20250923 -v
uv run invenio index delete $index_name --yes-i-knowindex_name=`uv run invenio rero es index info -i collections | grep -v percolator`
echo $index_name
uv run invenio rero es index move collections $index_name collections-collection-v1.0.0-20250923 -v
uv run invenio index delete $index_name --yes-i-know- replace
INVENIO_SQLALCHEMY_POOL_RECYCLEbyINVENIO_SQLALCHEMY_ENGINE_OPTIONS: '{ "pool_recycle": 360 }' - set the config in the sqlalchemy container/server by setting
PGOPTIONSto-c statement_timeout=30s -c idle_in_transaction_session_timeout=60s - add
IDP_CERTIFICATES_DIR: /invenio/storage/prod/data/idp_certificates - add
SONAR_FILES_PATH: /invenio/storage/files - add
PYTHONWARNINGS: ignore
- fix res in update mapping -> fix(es): error handling in update_mapping #24
- fix number of replicas for event stats and stats
- add move files to rero-invenio-base
- make a minor version with the APP_ENV fix -> fix: flask env does not exists anymore #1062
- fix monitoring db_connection_counts "error": "Textual SQL expression '\n select\n ...' should be explicitly declared as text('\n select\n ...')" -> fix(monitoring): database counts #1063