From 79c23194031c4d82204dad00fd0c8b92f1fb1349 Mon Sep 17 00:00:00 2001 From: Ari Webb Date: Wed, 17 Dec 2025 16:02:49 -0800 Subject: [PATCH] chore: add project constraint on tools db (#7360) --- ...145c45d_add_project_constraint_on_tools.py | 33 +++++++++++++++++++ letta/orm/tool.py | 1 + 2 files changed, 34 insertions(+) create mode 100644 alembic/versions/39577145c45d_add_project_constraint_on_tools.py diff --git a/alembic/versions/39577145c45d_add_project_constraint_on_tools.py b/alembic/versions/39577145c45d_add_project_constraint_on_tools.py new file mode 100644 index 00000000..98a6b6be --- /dev/null +++ b/alembic/versions/39577145c45d_add_project_constraint_on_tools.py @@ -0,0 +1,33 @@ +"""add project constraint on tools + +Revision ID: 39577145c45d +Revises: d0880aae6cee +Create Date: 2025-12-17 15:46:06.184858 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "39577145c45d" +down_revision: Union[str, None] = "d0880aae6cee" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_unique_constraint( + "uix_organization_project_name", "tools", ["organization_id", "project_id", "name"], postgresql_nulls_not_distinct=True + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint("uix_organization_project_name", "tools", type_="unique") + # ### end Alembic commands ### diff --git a/letta/orm/tool.py b/letta/orm/tool.py index 2034cc35..46ebe016 100644 --- a/letta/orm/tool.py +++ b/letta/orm/tool.py @@ -29,6 +29,7 @@ class Tool(SqlalchemyBase, OrganizationMixin, ProjectMixin): # An organization should not have multiple tools with the same name __table_args__ = ( UniqueConstraint("name", "organization_id", name="uix_name_organization"), + UniqueConstraint("organization_id", "project_id", "name", name="uix_organization_project_name", postgresql_nulls_not_distinct=True), Index("ix_tools_created_at_name", "created_at", "name"), Index("ix_tools_organization_id", "organization_id"), Index("ix_tools_organization_id_name", "organization_id", "name"),