This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new efe32bddcc fix: include manually assigned id in scale history inserts 
(#6993)
efe32bddcc is described below

commit efe32bddcc2307a540b6f2224333f64ecf18f949
Author: Southern <[email protected]>
AuthorDate: Thu Sep 3 13:29:29 2026 +0800

    fix: include manually assigned id in scale history inserts (#6993)
    
    Remove LAST_INSERT_ID selectKey usage from scale_history inserts and bind
      the caller-provided varchar primary key. Add mapper integration tests for
      regular and selective inserts.
    
    Co-authored-by: aias00 <[email protected]>
---
 .../resources/mappers/scale-history-sqlmap.xml     | 16 +++---
 .../admin/mapper/ScaleHistoryMapperTest.java       | 65 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 8 deletions(-)

diff --git a/shenyu-admin/src/main/resources/mappers/scale-history-sqlmap.xml 
b/shenyu-admin/src/main/resources/mappers/scale-history-sqlmap.xml
index 1a2eb10491..b005ac7d05 100644
--- a/shenyu-admin/src/main/resources/mappers/scale-history-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/scale-history-sqlmap.xml
@@ -54,22 +54,19 @@
     where id = #{id,jdbcType=VARCHAR}
   </delete>
   <insert id="insert" 
parameterType="org.apache.shenyu.admin.model.entity.ScaleHistoryDO">
-    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.String">
-      SELECT LAST_INSERT_ID()
-    </selectKey>
-    insert into scale_history (config_id, num, `action`, 
+    insert into scale_history (id, config_id, num, `action`,
       date_created, date_updated, msg
       )
-    values (#{configId,jdbcType=INTEGER}, #{num,jdbcType=INTEGER}, 
#{action,jdbcType=INTEGER}, 
+    values (#{id,jdbcType=VARCHAR}, #{configId,jdbcType=INTEGER}, 
#{num,jdbcType=INTEGER}, #{action,jdbcType=INTEGER},
       #{dateCreated,jdbcType=TIMESTAMP}, #{dateUpdated,jdbcType=TIMESTAMP}, 
#{msg,jdbcType=LONGVARCHAR}
       )
   </insert>
   <insert id="insertSelective" 
parameterType="org.apache.shenyu.admin.model.entity.ScaleHistoryDO">
-    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.String">
-      SELECT LAST_INSERT_ID()
-    </selectKey>
     insert into scale_history
     <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
       <if test="configId != null">
         config_id,
       </if>
@@ -90,6 +87,9 @@
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=VARCHAR},
+      </if>
       <if test="configId != null">
         #{configId,jdbcType=INTEGER},
       </if>
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScaleHistoryMapperTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScaleHistoryMapperTest.java
new file mode 100644
index 0000000000..c327167b63
--- /dev/null
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScaleHistoryMapperTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.mapper;
+
+import org.apache.shenyu.admin.AbstractSpringIntegrationTest;
+import org.apache.shenyu.admin.model.entity.ScaleHistoryDO;
+import org.apache.shenyu.common.utils.UUIDUtils;
+import org.junit.jupiter.api.Test;
+
+import jakarta.annotation.Resource;
+import java.sql.Timestamp;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Test cases for ScaleHistoryMapper.
+ */
+public final class ScaleHistoryMapperTest extends 
AbstractSpringIntegrationTest {
+
+    @Resource
+    private ScaleHistoryMapper scaleHistoryMapper;
+
+    @Test
+    public void insertPreservesManuallyAssignedId() {
+        String id = UUIDUtils.getInstance().generateShortUuid();
+        Timestamp now = new Timestamp(System.currentTimeMillis());
+        ScaleHistoryDO record = new ScaleHistoryDO(1, 2, 1, "scale");
+        record.setId(id);
+        record.setDateCreated(now);
+        record.setDateUpdated(now);
+
+        assertEquals(1, scaleHistoryMapper.insert(record));
+        assertEquals(id, scaleHistoryMapper.selectByPrimaryKey(id).getId());
+        assertEquals(1, scaleHistoryMapper.deleteByPrimaryKey(id));
+    }
+
+    @Test
+    public void insertSelectiveIncludesIdAndUsesDatabaseDefaults() {
+        String id = UUIDUtils.getInstance().generateShortUuid();
+        ScaleHistoryDO record = new ScaleHistoryDO(1, 1, 0, null);
+        record.setId(id);
+
+        assertEquals(1, scaleHistoryMapper.insertSelective(record));
+        ScaleHistoryDO stored = scaleHistoryMapper.selectByPrimaryKey(id);
+        assertEquals(id, stored.getId());
+        assertNull(stored.getMsg());
+        assertEquals(1, scaleHistoryMapper.deleteByPrimaryKey(id));
+    }
+}

Reply via email to