From 479a6523770bb7283682d61f79fd9e9ccbad49c5 Mon Sep 17 00:00:00 2001 From: xuyaqist Date: Mon, 2 Mar 2026 14:07:48 +0800 Subject: [PATCH 1/2] Bugfix: error when update a tool & adding a agent relation (cherry picked from commit 3b067c7058d55b4fff60f0d1ac9a4d8bba7538cb) --- backend/database/db_models.py | 9 +++++++-- docker/init.sql | 4 ++-- ...l_instance_id_seq_and_agent_relation_id_seq.sql | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 docker/sql/v1.8.0.1_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql diff --git a/backend/database/db_models.py b/backend/database/db_models.py index a3ecb7120..efb401d64 100644 --- a/backend/database/db_models.py +++ b/backend/database/db_models.py @@ -236,7 +236,12 @@ class ToolInstance(TableBase): __table_args__ = {"schema": SCHEMA} tool_instance_id = Column( - Integer, primary_key=True, nullable=False, doc="ID") + Integer, + Sequence("ag_tool_instance_t_tool_instance_id_seq", schema=SCHEMA), + primary_key=True, + nullable=False, + doc="ID" + ) tool_id = Column(Integer, doc="Tenant tool ID") agent_id = Column(Integer, doc="Agent ID") params = Column(JSON, doc="Parameter configuration") @@ -351,7 +356,7 @@ class AgentRelation(TableBase): __tablename__ = "ag_agent_relation_t" __table_args__ = {"schema": SCHEMA} - relation_id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, doc="Relationship ID, primary key") + relation_id = Column(Integer, Sequence("ag_agent_relation_t_relation_id_seq", schema=SCHEMA), primary_key=True, nullable=False, doc="Relationship ID, primary key") selected_agent_id = Column(Integer, primary_key=True, doc="Selected agent ID") parent_agent_id = Column(Integer, doc="Parent agent ID") tenant_id = Column(String(100), doc="Tenant ID") diff --git a/docker/init.sql b/docker/init.sql index 9c3fac948..2462dc63b 100644 --- a/docker/init.sql +++ b/docker/init.sql @@ -380,7 +380,7 @@ WHERE delete_flag = 'N'; -- Create the ag_tool_instance_t table in the nexent schema CREATE TABLE IF NOT EXISTS nexent.ag_tool_instance_t ( - tool_instance_id INTEGER NOT NULL, + tool_instance_id SERIAL NOT NULL, tool_id INTEGER, agent_id INTEGER, params JSON, @@ -564,7 +564,7 @@ COMMENT ON COLUMN nexent.user_tenant_t.delete_flag IS 'Delete flag, Y/N'; -- Create the ag_agent_relation_t table in the nexent schema CREATE TABLE IF NOT EXISTS nexent.ag_agent_relation_t ( - relation_id INTEGER NOT NULL, + relation_id SERIAL NOT NULL, selected_agent_id INTEGER, parent_agent_id INTEGER, tenant_id VARCHAR(100), diff --git a/docker/sql/v1.8.0.1_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql b/docker/sql/v1.8.0.1_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql new file mode 100644 index 000000000..06fde6435 --- /dev/null +++ b/docker/sql/v1.8.0.1_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql @@ -0,0 +1,14 @@ +-- Step 1: Create sequence for auto-increment +CREATE SEQUENCE IF NOT EXISTS "nexent"."ag_tool_instance_t_tool_instance_id_seq" +INCREMENT 1 +MINVALUE 1 +MAXVALUE 2147483647 +START 1 +CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS "nexent"."ag_agent_relation_t_relation_id_seq" +INCREMENT 1 +MINVALUE 1 +MAXVALUE 2147483647 +START 1 +CACHE 1; From b5f748759c7725227c625e8b5d7329afe3904e98 Mon Sep 17 00:00:00 2001 From: xuyaqist Date: Mon, 2 Mar 2026 14:50:28 +0800 Subject: [PATCH 2/2] change updated sql name (cherry picked from commit 55aee73017343cf5ba5549787c0dc9a0f0a5c863) --- ...2_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docker/sql/{v1.8.0.1_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql => v1.8.0.2_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql} (100%) diff --git a/docker/sql/v1.8.0.1_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql b/docker/sql/v1.8.0.2_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql similarity index 100% rename from docker/sql/v1.8.0.1_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql rename to docker/sql/v1.8.0.2_0302_add_tool_instance_id_seq_and_agent_relation_id_seq.sql