Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

chore: add project constraint on tools db (#7360)

Ari Webb79c23194031c
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 000000000..98a6b6be2
--- /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 2034cc350..46ebe0168 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"),