From f77577351bbc5f85e958842ff4f3a311167c9c09 Mon Sep 17 00:00:00 2001 From: Tony Germano Date: Fri, 27 Nov 2026 09:40:52 -0500 Subject: [PATCH 1/2] Quote the LIBRARY column for MySQL MySQL 9.2 made LIBRARY a reserved word, so creating CODE_TEMPLATE_LIBRARY failed with a syntax error and the rest of mysql-database.sql never ran. Quote the column with backticks in the MySQL schema, the 3.2.2-3.3.0 delta and the MySQL code template mapper. The migrators share their SQL across databases, so add Migrator.quoteColumn() to quote only when the database type is mysql and use it for the two LIBRARY statements there. MigratorTest covers it, since ServerMigratorTest runs on Derby only and never reaches the quoted path. Verified on MySQL 9.2.0: the schema script runs and the column can be inserted, updated and selected. Issue: https://github.com/OpenIntegrationEngine/engine/issues/607 Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Tony Germano --- server/dbconf/deltas/mysql-3.2.2-3.3.0.sql | 2 +- server/dbconf/mysql/mysql-codeTemplate.xml | 8 ++-- server/dbconf/mysql/mysql-database.sql | 2 +- .../server/migration/Migrate3_3_0.java | 2 +- .../connect/server/migration/Migrator.java | 8 ++++ .../server/migration/ServerMigrator.java | 3 +- .../server/migration/MigratorTest.java | 37 +++++++++++++++++++ 7 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 server/src/test/java/com/mirth/connect/server/migration/MigratorTest.java diff --git a/server/dbconf/deltas/mysql-3.2.2-3.3.0.sql b/server/dbconf/deltas/mysql-3.2.2-3.3.0.sql index 65d1ba6b5..29c6182cf 100644 --- a/server/dbconf/deltas/mysql-3.2.2-3.3.0.sql +++ b/server/dbconf/deltas/mysql-3.2.2-3.3.0.sql @@ -4,7 +4,7 @@ CREATE TABLE CODE_TEMPLATE_LIBRARY (ID VARCHAR(255) NOT NULL PRIMARY KEY, NAME VARCHAR(255) NOT NULL UNIQUE, REVISION INTEGER, - LIBRARY LONGTEXT + `LIBRARY` LONGTEXT ) ENGINE=InnoDB CREATE TABLE CODE_TEMPLATE ( diff --git a/server/dbconf/mysql/mysql-codeTemplate.xml b/server/dbconf/mysql/mysql-codeTemplate.xml index a1fb56258..d53d15edf 100644 --- a/server/dbconf/mysql/mysql-codeTemplate.xml +++ b/server/dbconf/mysql/mysql-codeTemplate.xml @@ -18,7 +18,7 @@ @@ -37,7 +37,7 @@ INSERT INTO - CODE_TEMPLATE_LIBRARY (ID, NAME, REVISION, LIBRARY) + CODE_TEMPLATE_LIBRARY (ID, NAME, REVISION, `LIBRARY`) VALUES (#{id}, #{name}, #{revision}, #{library}) @@ -45,7 +45,7 @@ UPDATE CODE_TEMPLATE_LIBRARY SET NAME = #{name}, REVISION = #{revision}, - LIBRARY = #{library} + `LIBRARY` = #{library} WHERE ID = #{id} diff --git a/server/dbconf/mysql/mysql-database.sql b/server/dbconf/mysql/mysql-database.sql index 27ea4cb8b..621c4eb16 100644 --- a/server/dbconf/mysql/mysql-database.sql +++ b/server/dbconf/mysql/mysql-database.sql @@ -73,7 +73,7 @@ CREATE TABLE CODE_TEMPLATE_LIBRARY (ID VARCHAR(255) NOT NULL PRIMARY KEY, NAME VARCHAR(255) NOT NULL UNIQUE, REVISION INTEGER, - LIBRARY LONGTEXT + `LIBRARY` LONGTEXT ) ENGINE=InnoDB; CREATE TABLE CODE_TEMPLATE ( diff --git a/server/src/main/java/com/mirth/connect/server/migration/Migrate3_3_0.java b/server/src/main/java/com/mirth/connect/server/migration/Migrate3_3_0.java index cd83bb21f..f77d8433f 100644 --- a/server/src/main/java/com/mirth/connect/server/migration/Migrate3_3_0.java +++ b/server/src/main/java/com/mirth/connect/server/migration/Migrate3_3_0.java @@ -125,7 +125,7 @@ private void migrateCodeTemplates() { String libraryXml = libraryElement.toXml(); try { - updateStatement = connection.prepareStatement("INSERT INTO CODE_TEMPLATE_LIBRARY (ID, NAME, REVISION, LIBRARY) VALUES (?, ?, ?, ?)"); + updateStatement = connection.prepareStatement("INSERT INTO CODE_TEMPLATE_LIBRARY (ID, NAME, REVISION, " + quoteColumn("LIBRARY") + ") VALUES (?, ?, ?, ?)"); updateStatement.setString(1, libraryId); updateStatement.setString(2, name); updateStatement.setInt(3, revision); diff --git a/server/src/main/java/com/mirth/connect/server/migration/Migrator.java b/server/src/main/java/com/mirth/connect/server/migration/Migrator.java index 4a51019e1..ca5822808 100644 --- a/server/src/main/java/com/mirth/connect/server/migration/Migrator.java +++ b/server/src/main/java/com/mirth/connect/server/migration/Migrator.java @@ -63,6 +63,14 @@ public void setDatabaseType(String databaseType) { this.databaseType = databaseType; } + /** + * Returns the given column name quoted if the current database requires it. Currently only + * MySQL does, because newer versions (9.2+) reserve words such as LIBRARY. + */ + protected String quoteColumn(String column) { + return "mysql".equals(databaseType) ? "`" + column + "`" : column; + } + public String getDefaultScriptPath() { return defaultScriptPath; } diff --git a/server/src/main/java/com/mirth/connect/server/migration/ServerMigrator.java b/server/src/main/java/com/mirth/connect/server/migration/ServerMigrator.java index efb77503f..701d91b01 100644 --- a/server/src/main/java/com/mirth/connect/server/migration/ServerMigrator.java +++ b/server/src/main/java/com/mirth/connect/server/migration/ServerMigrator.java @@ -96,7 +96,8 @@ public void migrate() throws MigrationException { public void migrateSerializedData() { migrateSerializedData("SELECT ID, CHANNEL FROM CHANNEL", "UPDATE CHANNEL SET CHANNEL = ? WHERE ID = ?", Channel.class); migrateSerializedData("SELECT ID, ALERT FROM ALERT", "UPDATE ALERT SET ALERT = ? WHERE ID = ?", AlertModel.class); - migrateSerializedData("SELECT ID, LIBRARY FROM CODE_TEMPLATE_LIBRARY", "UPDATE CODE_TEMPLATE_LIBRARY SET LIBRARY = ? WHERE ID = ?", CodeTemplateLibrary.class); + String library = quoteColumn("LIBRARY"); + migrateSerializedData("SELECT ID, " + library + " FROM CODE_TEMPLATE_LIBRARY", "UPDATE CODE_TEMPLATE_LIBRARY SET " + library + " = ? WHERE ID = ?", CodeTemplateLibrary.class); migrateSerializedData("SELECT ID, CODE_TEMPLATE FROM CODE_TEMPLATE", "UPDATE CODE_TEMPLATE SET CODE_TEMPLATE = ? WHERE ID = ?", CodeTemplate.class); } diff --git a/server/src/test/java/com/mirth/connect/server/migration/MigratorTest.java b/server/src/test/java/com/mirth/connect/server/migration/MigratorTest.java new file mode 100644 index 000000000..d30fc59d6 --- /dev/null +++ b/server/src/test/java/com/mirth/connect/server/migration/MigratorTest.java @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: 2026 Tony Germano + +package com.mirth.connect.server.migration; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.mirth.connect.model.util.MigrationException; + +public class MigratorTest { + + private static Migrator migratorFor(String databaseType) { + Migrator migrator = new Migrator() { + @Override + public void migrate() throws MigrationException {} + + @Override + public void migrateSerializedData() throws MigrationException {} + }; + migrator.setDatabaseType(databaseType); + return migrator; + } + + @Test + public void quoteColumnQuotesForMysql() { + assertEquals("`LIBRARY`", migratorFor("mysql").quoteColumn("LIBRARY")); + } + + @Test + public void quoteColumnLeavesOtherDatabasesUnquoted() { + for (String databaseType : new String[] { "derby", "postgres", "oracle", "sqlserver", null }) { + assertEquals(databaseType, "LIBRARY", migratorFor(databaseType).quoteColumn("LIBRARY")); + } + } +} From 55585f2de49c8c8bfb4dbcc41e76405bb6e3f5de Mon Sep 17 00:00:00 2001 From: Tony Germano Date: Fri, 27 Nov 2026 09:27:55 -0500 Subject: [PATCH 2/2] Test against real MySQL in CI The mysql configuration actually ran MariaDB, which does not reserve LIBRARY, so it could not catch the MySQL 9.2 failure fixed in the previous commit. Rename it to alpine-temurin21-mariadb and make alpine-temurin21-mysql use the mysql image (9.7). Issue: https://github.com/OpenIntegrationEngine/engine/issues/607 Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Tony Germano --- .../alpine-temurin21-mariadb.compose.yml | 49 +++++++++++++++++++ .../alpine-temurin21-mysql.compose.yml | 13 ++--- 2 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 ci/configurations/alpine-temurin21-mariadb.compose.yml diff --git a/ci/configurations/alpine-temurin21-mariadb.compose.yml b/ci/configurations/alpine-temurin21-mariadb.compose.yml new file mode 100644 index 000000000..d8416a08c --- /dev/null +++ b/ci/configurations/alpine-temurin21-mariadb.compose.yml @@ -0,0 +1,49 @@ +services: + db: + image: mariadb:11.8 + environment: + MARIADB_ROOT_PASSWORD: root_password + MARIADB_DATABASE: mirthdb + MARIADB_USER: mirthdb + MARIADB_PASSWORD: mirthdb + healthcheck: + test: + - CMD-SHELL + - mariadb-admin ping -h 127.0.0.1 -umirthdb -pmirthdb + interval: 3s + timeout: 5s + retries: 20 + start_period: 20s + + oie: + image: ${OIE_IMAGE} + depends_on: + db: + condition: service_healthy + environment: + DATABASE: mysql + DATABASE_URL: jdbc:mysql://db:3306/mirthdb + DATABASE_USERNAME: mirthdb + DATABASE_PASSWORD: mirthdb + DATABASE_MAX_CONNECTIONS: 20 + DATABASE_MAX_RETRY: 10 + DATABASE_RETRY_WAIT: 5000 + ports: + - "8443:8443" + healthcheck: + test: + - CMD-SHELL + - bash -lc 'exec 3<>/dev/tcp/127.0.0.1/8443' + interval: 3s + timeout: 5s + retries: 30 + start_period: 40s + + # Lets the Database Connector metadata test reach this configuration's database. The URL is + # resolved by the oie service, not the harness, so it is the same one the engine uses. + harness: + environment: + OIE_DB_DRIVER: com.mysql.cj.jdbc.Driver + OIE_DB_URL: jdbc:mysql://db:3306/mirthdb + OIE_DB_USERNAME: mirthdb + OIE_DB_PASSWORD: mirthdb diff --git a/ci/configurations/alpine-temurin21-mysql.compose.yml b/ci/configurations/alpine-temurin21-mysql.compose.yml index d8416a08c..d2ee9e766 100644 --- a/ci/configurations/alpine-temurin21-mysql.compose.yml +++ b/ci/configurations/alpine-temurin21-mysql.compose.yml @@ -1,15 +1,16 @@ services: db: - image: mariadb:11.8 + # Real MySQL (not MariaDB) so this catches newer reserved words, e.g. LIBRARY in 9.2. + image: mysql:9.7 environment: - MARIADB_ROOT_PASSWORD: root_password - MARIADB_DATABASE: mirthdb - MARIADB_USER: mirthdb - MARIADB_PASSWORD: mirthdb + MYSQL_ROOT_PASSWORD: root_password + MYSQL_DATABASE: mirthdb + MYSQL_USER: mirthdb + MYSQL_PASSWORD: mirthdb healthcheck: test: - CMD-SHELL - - mariadb-admin ping -h 127.0.0.1 -umirthdb -pmirthdb + - mysqladmin ping -h 127.0.0.1 -umirthdb -pmirthdb interval: 3s timeout: 5s retries: 20