Skip to content

Commit

Permalink
models: add index on bucket_id
Browse files Browse the repository at this point in the history
* adds alembic recipe
* closes zenodo/rdm-project#640
  • Loading branch information
jrcastro2 authored and slint committed Feb 5, 2024
1 parent f94fb10 commit a55f7a9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# This file is part of Invenio.
# Copyright (C) 2023 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.

"""Create indeces for bucket_id."""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "72b37bb4119c"
down_revision = "5c68d45c80f0"
branch_labels = ()
depends_on = None


def upgrade():
"""Upgrade database."""
op.create_index(
op.f("ix_communities_metadata_bucket_id"),
"communities_metadata",
["bucket_id"],
unique=False,
)
op.create_index(
op.f("ix_communities_files_object_version_id"),
"communities_files",
["object_version_id"],
unique=False,
)


def downgrade():
"""Downgrade database."""
op.drop_index(
op.f("ix_communities_metadata_bucket_id"), table_name="communities_metadata"
)
op.drop_index(
op.f("ix_communities_files_object_version_id"), table_name="communities_files"
)
2 changes: 1 addition & 1 deletion invenio_communities/communities/records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CommunityMetadata(db.Model, RecordMetadataBase):

slug = db.Column(String(255), unique=True, nullable=True)

bucket_id = db.Column(UUIDType, db.ForeignKey(Bucket.id))
bucket_id = db.Column(UUIDType, db.ForeignKey(Bucket.id), index=True)
bucket = db.relationship(Bucket)

# The deletion status is stored in the model so that we can use it in SQL queries
Expand Down

0 comments on commit a55f7a9

Please sign in to comment.