diff --git a/libervia/backend/memory/migration/versions/ccd879fef17e_add_namespace_indexes_to_privateind_.py b/libervia/backend/memory/migration/versions/ccd879fef17e_add_namespace_indexes_to_privateind_.py new file mode 100644 index 00000000..86e945e2 --- /dev/null +++ b/libervia/backend/memory/migration/versions/ccd879fef17e_add_namespace_indexes_to_privateind_.py @@ -0,0 +1,38 @@ +"""add namespace indexes to "PrivateInd*" tables + +Revision ID: ccd879fef17e +Revises: 3ddac15a0a39 +Create Date: 2026-04-28 12:16:01.759630 + +""" + +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = "ccd879fef17e" +down_revision = "3ddac15a0a39" +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table("private_ind", schema=None) as batch_op: + batch_op.create_index( + "private_ind__namespace_profile_id", ["namespace", "profile_id"], unique=False + ) + + with op.batch_alter_table("private_ind_bin", schema=None) as batch_op: + batch_op.create_index( + "private_ind_bin__namespace_profile_id", + ["namespace", "profile_id"], + unique=False, + ) + + +def downgrade(): + with op.batch_alter_table("private_ind_bin", schema=None) as batch_op: + batch_op.drop_index("private_ind_bin__namespace_profile_id") + + with op.batch_alter_table("private_ind", schema=None) as batch_op: + batch_op.drop_index("private_ind__namespace_profile_id") diff --git a/libervia/backend/memory/sqla_mapping.py b/libervia/backend/memory/sqla_mapping.py index 2e18d9c7..7bcc35dc 100644 --- a/libervia/backend/memory/sqla_mapping.py +++ b/libervia/backend/memory/sqla_mapping.py @@ -547,6 +547,9 @@ class PrivateGen(Base): class PrivateInd(Base): __tablename__ = "private_ind" + __table_args__ = ( + Index("private_ind__namespace_profile_id", "namespace", "profile_id"), + ) namespace = Column(Text, primary_key=True) key = Column(Text, primary_key=True) @@ -566,6 +569,9 @@ class PrivateGenBin(Base): class PrivateIndBin(Base): __tablename__ = "private_ind_bin" + __table_args__ = ( + Index("private_ind_bin__namespace_profile_id", "namespace", "profile_id"), + ) namespace = Column(Text, primary_key=True) key = Column(Text, primary_key=True)