From ca50fd97ab8e7c2323e11d2a1b90892bdcdb4fad Mon Sep 17 00:00:00 2001 From: jrcastro2 Date: Thu, 19 Dec 2024 10:57:29 +0100 Subject: [PATCH] names: remove internal_id * closes https://github.com/CERNDocumentServer/cds-rdm/issues/284 --- ..._removes_internal_id_from_name_metadata.py | 37 +++++++++++++++++++ .../contrib/names/components.py | 24 ------------ invenio_vocabularies/contrib/names/config.py | 2 - invenio_vocabularies/contrib/names/names.py | 2 - invenio_vocabularies/contrib/names/schema.py | 1 - tests/contrib/names/test_names_service.py | 2 +- 6 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 invenio_vocabularies/alembic/8a91f4cfedd2_removes_internal_id_from_name_metadata.py delete mode 100644 invenio_vocabularies/contrib/names/components.py diff --git a/invenio_vocabularies/alembic/8a91f4cfedd2_removes_internal_id_from_name_metadata.py b/invenio_vocabularies/alembic/8a91f4cfedd2_removes_internal_id_from_name_metadata.py new file mode 100644 index 00000000..ea78a865 --- /dev/null +++ b/invenio_vocabularies/alembic/8a91f4cfedd2_removes_internal_id_from_name_metadata.py @@ -0,0 +1,37 @@ +# +# 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. + +"""Removes internal_id from name_metadata.""" + +import sqlalchemy as sa +from alembic import op +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "8a91f4cfedd2" +down_revision = "af2457652217" +branch_labels = () +depends_on = None + + +def upgrade(): + """Upgrade database.""" + op.drop_index("ix_name_metadata_internal_id", table_name="name_metadata") + op.drop_column("name_metadata", "internal_id") + + +def downgrade(): + """Downgrade database.""" + op.add_column( + "name_metadata", + sa.Column( + "internal_id", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + ) + op.create_index( + "ix_name_metadata_internal_id", "name_metadata", ["internal_id"], unique=False + ) diff --git a/invenio_vocabularies/contrib/names/components.py b/invenio_vocabularies/contrib/names/components.py deleted file mode 100644 index 73ec07a3..00000000 --- a/invenio_vocabularies/contrib/names/components.py +++ /dev/null @@ -1,24 +0,0 @@ -# -# This file is part of Invenio. -# Copyright (C) 2024 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. - -"""Names service components.""" - -from invenio_records_resources.services.records.components import ServiceComponent - - -class InternalIDComponent(ServiceComponent): - """Service component for internal id field.""" - - field = "internal_id" - - def create(self, identity, data=None, record=None, **kwargs): - """Create handler.""" - setattr(record, self.field, data.pop(self.field, None)) - - def update(self, identity, data=None, record=None, **kwargs): - """Update handler.""" - setattr(record, self.field, data.pop(self.field, None)) diff --git a/invenio_vocabularies/contrib/names/config.py b/invenio_vocabularies/contrib/names/config.py index 509c7c89..f5ddab0b 100644 --- a/invenio_vocabularies/contrib/names/config.py +++ b/invenio_vocabularies/contrib/names/config.py @@ -21,7 +21,6 @@ from werkzeug.local import LocalProxy from ...services.components import PIDComponent -from .components import InternalIDComponent names_schemes = LocalProxy(lambda: current_app.config["VOCABULARIES_NAMES_SCHEMES"]) @@ -68,7 +67,6 @@ class NamesSearchOptions(SearchOptions): service_components = [ # Order of components are important! - InternalIDComponent, DataComponent, PIDComponent, RelationsComponent, diff --git a/invenio_vocabularies/contrib/names/names.py b/invenio_vocabularies/contrib/names/names.py index 9d71ee05..0269d1dd 100644 --- a/invenio_vocabularies/contrib/names/names.py +++ b/invenio_vocabularies/contrib/names/names.py @@ -47,12 +47,10 @@ # cannot set to nullable=False because it would fail at # service level when create({}), see records-resources. "pid": db.Column(db.String(255), unique=True), - "internal_id": db.Column(db.String(255), nullable=True, index=True), }, schema_version="1.0.0", schema_path="local://names/name-v1.0.0.json", index_name="names-name-v2.0.0", - record_cls_attrs={"internal_id": ModelField("internal_id", dump=False)}, record_relations=name_relations, record_dumper=SearchDumper( model_fields={"pid": ("id", str)}, diff --git a/invenio_vocabularies/contrib/names/schema.py b/invenio_vocabularies/contrib/names/schema.py index 77586e79..b55347a5 100644 --- a/invenio_vocabularies/contrib/names/schema.py +++ b/invenio_vocabularies/contrib/names/schema.py @@ -47,7 +47,6 @@ class NameSchema(BaseVocabularySchema, ModePIDFieldVocabularyMixin): so it does not inherit from it. """ - internal_id = fields.Str(allow_none=True) name = SanitizedUnicode() given_name = SanitizedUnicode() family_name = SanitizedUnicode() diff --git a/tests/contrib/names/test_names_service.py b/tests/contrib/names/test_names_service.py index 261373a9..e5461fb8 100644 --- a/tests/contrib/names/test_names_service.py +++ b/tests/contrib/names/test_names_service.py @@ -69,7 +69,7 @@ def test_simple_flow(app, service, identity, name_full_data, example_affiliation # Fail to retrieve it # - db # only the metadata is removed from the record, it is still resolvable - base_keys = {"created", "updated", "id", "links", "revision_id", "internal_id"} + base_keys = {"created", "updated", "id", "links", "revision_id"} deleted_rec = service.read(identity, id_).to_dict() assert set(deleted_rec.keys()) == base_keys # - search