Skip to content

Conversation

@hpoettker
Copy link
Contributor

@hpoettker hpoettker commented May 24, 2025

Problem statement

Although there is a MysqlChatMemoryRepositoryDialect for the JDBC chat memory repository, auto-configuration of the repository currently fails to initialize the table in MySQL databases.

When schema initialization is enabled, the application fails with the message:

Error creating bean with name 'jdbcChatMemoryScriptDatabaseInitializer' defined in class path resource [org/springframework/ai/model/chat/memory/repository/jdbc/autoconfigure/JdbcChatMemoryRepositoryAutoConfiguration.class]: No schema scripts found at location 'classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-mysql.sql'

Among other schema files, there is a schema-mariadb.sql, but this file doesn't work with MySQL as MySQL doesn't support CREATE INDEX with IF NOT EXISTS.

Proposed change

This pull request

  • adds a schema-mysql.sql,
  • renames the existing test JdbcChatMemoryRepositoryMysqlIT, which tests against MariaDB, to JdbcChatMemoryRepositoryMariaDbIT,
  • adds a new JdbcChatMemoryRepositoryMysqlIT, which tests against MySQL.

Remarks on the MySQL schema

In the MySQL schema, I've used the column type ENUM instead of a check constraint. A check constraint would also work in recent MySQL releases, as they have been added in MySQL 8.0.16. But using an ENUM extends compatibility even back to MySQL 5.7 and is also a more direct representation of the Java Enum MessageType.

@ilayaperumalg
Copy link
Member

@hpoettker Thanks for the PR adding the schema for MySQL JDBC chat memory repository! The changes look good. Rebased and merged as 9f58520. Also back-ported into 1.0.x as 148bf33

@hpoettker hpoettker deleted the mysql-chat-memory-repository branch June 1, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants