Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: add tool index (#2152)

Yeuolyc8fb619d37c9
diff --git a/api/migrations/versions/dfb3b7f477da_add_tool_index.py b/api/migrations/versions/dfb3b7f477da_add_tool_index.py
new file mode 100644
index 00000000000..66e2a4f863a
--- /dev/null
+++ b/api/migrations/versions/dfb3b7f477da_add_tool_index.py
@@ -0,0 +1,38 @@
+"""add-tool-index
+
+Revision ID: dfb3b7f477da
+Revises: b24be59fbb04
+Create Date: 2024-01-24 02:17:01.631635
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'dfb3b7f477da'
+down_revision = 'b24be59fbb04'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
+ batch_op.create_unique_constraint('unique_api_tool_provider', ['name', 'tenant_id'])
+
+ with op.batch_alter_table('tool_files', schema=None) as batch_op:
+ batch_op.create_index('tool_file_conversation_id_idx', ['conversation_id'], unique=False)
+
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table('tool_files', schema=None) as batch_op:
+ batch_op.drop_index('tool_file_conversation_id_idx')
+
+ with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
+ batch_op.drop_constraint('unique_api_tool_provider', type_='unique')
+
+ # ### end Alembic commands ###
diff --git a/api/models/tools.py b/api/models/tools.py
index 74da1cd9411..04bd662c3c8 100644
--- a/api/models/tools.py
+++ b/api/models/tools.py
@@ -87,6 +87,7 @@ class ApiToolProvider(db.Model):
__tablename__ = 'tool_api_providers'
__table_args__ = (
db.PrimaryKeyConstraint('id', name='tool_api_provider_pkey'),
+ db.UniqueConstraint('name', 'tenant_id', name='unique_api_tool_provider')
)
id = db.Column(UUID, server_default=db.text('uuid_generate_v4()'))
@@ -210,6 +211,8 @@ class ToolFile(db.Model):
__tablename__ = "tool_files"
__table_args__ = (
db.PrimaryKeyConstraint('id', name='tool_file_pkey'),
+ # add index for conversation_id
+ db.Index('tool_file_conversation_id_idx', 'conversation_id'),
)
id = db.Column(UUID, server_default=db.text('uuid_generate_v4()'))