From 9f58520a12de66b52294da58f5d3534a19323a45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henning=20P=C3=B6ttker?=
<25299532+hpoettker@users.noreply.github.com>
Date: Sun, 25 May 2025 00:41:42 +0200
Subject: [PATCH] Add MySQL schema for `SPRING_AI_CHAT_MEMORY`
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Henning Pöttker <25299532+hpoettker@users.noreply.github.com>
---
.../pom.xml | 14 ++++++++
.../memory/repository/jdbc/schema-mysql.sql | 8 +++++
.../JdbcChatMemoryRepositoryMariaDbIT.java | 36 +++++++++++++++++++
.../jdbc/JdbcChatMemoryRepositoryMysqlIT.java | 5 +--
pom.xml | 1 +
5 files changed, 62 insertions(+), 2 deletions(-)
create mode 100644 memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/resources/org/springframework/ai/chat/memory/repository/jdbc/schema-mysql.sql
create mode 100644 memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMariaDbIT.java
diff --git a/memory/repository/spring-ai-model-chat-memory-repository-jdbc/pom.xml b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/pom.xml
index 534f16e10..75db46a8e 100644
--- a/memory/repository/spring-ai-model-chat-memory-repository-jdbc/pom.xml
+++ b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/pom.xml
@@ -73,6 +73,14 @@
true
+
+ com.mysql
+ mysql-connector-j
+ ${mysql.version}
+ test
+ true
+
+
com.microsoft.sqlserver
mssql-jdbc
@@ -104,6 +112,12 @@
test
+
+ org.testcontainers
+ mysql
+ test
+
+
org.testcontainers
mssqlserver
diff --git a/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/resources/org/springframework/ai/chat/memory/repository/jdbc/schema-mysql.sql b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/resources/org/springframework/ai/chat/memory/repository/jdbc/schema-mysql.sql
new file mode 100644
index 000000000..f8edb0c58
--- /dev/null
+++ b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/resources/org/springframework/ai/chat/memory/repository/jdbc/schema-mysql.sql
@@ -0,0 +1,8 @@
+CREATE TABLE IF NOT EXISTS SPRING_AI_CHAT_MEMORY (
+ `conversation_id` VARCHAR(36) NOT NULL,
+ `content` TEXT NOT NULL,
+ `type` ENUM('USER', 'ASSISTANT', 'SYSTEM', 'TOOL') NOT NULL,
+ `timestamp` TIMESTAMP NOT NULL,
+
+ INDEX `SPRING_AI_CHAT_MEMORY_CONVERSATION_ID_TIMESTAMP_IDX` (`conversation_id`, `timestamp`)
+);
diff --git a/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMariaDbIT.java b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMariaDbIT.java
new file mode 100644
index 000000000..a9127166e
--- /dev/null
+++ b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMariaDbIT.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed 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
+ *
+ * https://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.springframework.ai.chat.memory.repository.jdbc;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.jdbc.Sql;
+
+/**
+ * Integration tests for {@link JdbcChatMemoryRepository} with MariaDB.
+ *
+ * @author Jonathan Leijendekker
+ * @author Thomas Vitale
+ * @author Mark Pollack
+ * @author Yanming Zhou
+ */
+@SpringBootTest
+@TestPropertySource(properties = { "spring.datasource.url=jdbc:tc:mariadb:10.3.39:///" })
+@Sql(scripts = "classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-mariadb.sql")
+class JdbcChatMemoryRepositoryMariaDbIT extends AbstractJdbcChatMemoryRepositoryIT {
+
+}
diff --git a/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMysqlIT.java b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMysqlIT.java
index 3ee33e42b..e4e7eb756 100644
--- a/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMysqlIT.java
+++ b/memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/test/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryMysqlIT.java
@@ -27,10 +27,11 @@ import org.springframework.test.context.jdbc.Sql;
* @author Thomas Vitale
* @author Mark Pollack
* @author Yanming Zhou
+ * @author Henning Pöttker
*/
@SpringBootTest
-@TestPropertySource(properties = { "spring.datasource.url=jdbc:tc:mariadb:10.3.39:///" })
-@Sql(scripts = "classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-mariadb.sql")
+@TestPropertySource(properties = { "spring.datasource.url=jdbc:tc:mysql:8.0.42:///" })
+@Sql(scripts = "classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-mysql.sql")
class JdbcChatMemoryRepositoryMysqlIT extends AbstractJdbcChatMemoryRepositoryIT {
}
diff --git a/pom.xml b/pom.xml
index ca54365aa..29a12653a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -302,6 +302,7 @@
2.23.0
42.7.5
3.5.3
+ 9.2.0
0.22.0
3.8.0