-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
names: add internal id to identify the names
- Loading branch information
Showing
8 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
invenio_vocabularies/alembic/3ba812d80559_add_internal_name_id.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,36 @@ | ||
# | ||
# 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. | ||
|
||
"""Add internal name ID.""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "3ba812d80559" | ||
down_revision = "55a700f897b6" | ||
branch_labels = () | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
"""Upgrade database.""" | ||
op.add_column( | ||
"name_metadata", sa.Column("internal_id", sa.String(length=255), nullable=True) | ||
) | ||
op.create_unique_constraint( | ||
op.f("uq_name_metadata_internal_id"), "name_metadata", ["internal_id"] | ||
) | ||
|
||
|
||
def downgrade(): | ||
"""Downgrade database.""" | ||
op.drop_constraint( | ||
op.f("uq_name_metadata_internal_id"), "name_metadata", type_="unique" | ||
) | ||
op.drop_column("name_metadata", "internal_id") |
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,24 @@ | ||
# | ||
# 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)) |
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 |
---|---|---|
|
@@ -65,4 +65,4 @@ | |
"uniqueItems": true | ||
} | ||
} | ||
} | ||
} |
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