Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ci/configurations/alpine-temurin21-mariadb.compose.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions ci/configurations/alpine-temurin21-mysql.compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/dbconf/deltas/mysql-3.2.2-3.3.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 4 additions & 4 deletions server/dbconf/mysql/mysql-codeTemplate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
</resultMap>

<select id='getLibrary' parameterType='String' resultType="com.mirth.connect.model.codetemplates.CodeTemplateLibrary">
SELECT LIBRARY
SELECT `LIBRARY`
FROM CODE_TEMPLATE_LIBRARY
<where>
<if test='value != null'>ID = #{value}</if>
</where>
</select>

<select id="getSerializedLibraryData" resultMap="library-serialized-data">
SELECT ID, LIBRARY
SELECT ID, `LIBRARY`
FROM CODE_TEMPLATE_LIBRARY
</select>

Expand All @@ -37,15 +37,15 @@

<insert id='insertLibrary' parameterType='map'>
INSERT INTO
CODE_TEMPLATE_LIBRARY (ID, NAME, REVISION, LIBRARY)
CODE_TEMPLATE_LIBRARY (ID, NAME, REVISION, `LIBRARY`)
VALUES (#{id}, #{name}, #{revision}, #{library})
</insert>

<update id="updateLibrary" parameterType="map">
UPDATE CODE_TEMPLATE_LIBRARY
SET NAME = #{name},
REVISION = #{revision},
LIBRARY = #{library}
`LIBRARY` = #{library}
WHERE ID = #{id}
</update>

Expand Down
2 changes: 1 addition & 1 deletion server/dbconf/mysql/mysql-database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>

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"));
}
}
}
Loading