Skip to content

STAND-109: Replace the embedded mysql with mariadb4j#68

Merged
dkayiwa merged 45 commits intoopenmrs:masterfrom
Muta-Jonathan:STAND-109
Jun 16, 2025
Merged

STAND-109: Replace the embedded mysql with mariadb4j#68
dkayiwa merged 45 commits intoopenmrs:masterfrom
Muta-Jonathan:STAND-109

Conversation

@Muta-Jonathan
Copy link
Member

@Muta-Jonathan Muta-Jonathan commented May 1, 2025

See https://openmrs.atlassian.net/browse/STAND-109

Description

The change migrates the embedded database used by openmrs-standalone from mysql mxj to MariaDB4j (see https://github.com/MariaDB4j/MariaDB4j)

In order to keep the PR simple I opted to continue using the mysql driver instead of a MariaDB driver as mysql drivers are compatible with MariaDB.

on this PR, uses java version to 8 as the minimum java version. Also using MariaDB4J (3.2.0v) latest version with mac silicon (M1,M2+) support

Testing

In addition to the new unit tests I also performed the below manual tests and not sure if I need to do any validation on the other artifacts that get generated from packaging.


NOTE: Some liquidbase files in script testing are outdated in line with the current openmrs tables thats why are commented out and unused


Use cases

Am using a mac M2 chip and the following are the steps needed to run the openmrs-standalone-2.4.0

  1. After clone, run mvn clean
  2. then mvn package
  3. Copy generated openmrs-standalone/target/openmrs-standalone-2.4.0-SNAPSHOT.zip zipped file to any desired destination on unzip from there
  4. Make sure u have java installed can check using java --version in your terminal
  5. Inside your unzipped folder double click on openmrs-standalone.jar
  6. And start your openmrs instance

ScreenShots

Showing the folder

Screenshot 2025-05-01 at 9 59 47 PM


Screenshot 2025-05-01 at 10 02 14 PM
Screenshot 2025-05-01 at 10 03 23 PM

@Muta-Jonathan
Copy link
Member Author

cc @dkayiwa @wikumChamith


// Grant privileges to openmrs user
mariaDB.run("GRANT ALL PRIVILEGES ON *.* TO '" + DATABASE_USER_NAME + "'@'localhost';");
mariaDB.run("FLUSH PRIVILEGES;");
Copy link
Member Author

@Muta-Jonathan Muta-Jonathan May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used direct sql here but these above commands can be compiled in a sql file and sourced using mariaDB.source(fileName) but for now as per this PR's aim this should still be good

@dkayiwa
Copy link
Member

dkayiwa commented May 2, 2025

When i build and run, on choosing the Demonstration mode option, i get these errors in the logs: https://pastebin.com/DF2hiztT

@Muta-Jonathan
Copy link
Member Author

Muta-Jonathan commented May 2, 2025

I believe these come from the commented out liquidbase changesets @dkayiwa do we have any recent updated liquidbase changesets i can use

  1. liquibase.cieldata
  2. liquibasechangelog (liquibase.databaseChangeLogTableName)

@Muta-Jonathan
Copy link
Member Author

When i build and run, on choosing the Demonstration mode option, i get these errors in the logs: https://pastebin.com/DF2hiztT

Also seems there is a database connectivity issue let me look into it 🙂

@Muta-Jonathan
Copy link
Member Author

cc @dkayiwa

@dkayiwa
Copy link
Member

dkayiwa commented May 4, 2025

Does this fix the runtime error that i reported?

@Muta-Jonathan
Copy link
Member Author

Does this fix the runtime error that i reported?

oh yes now on end get the tables error https://pastebin.com/2Wh4KygA which will need just a bump to the latest dump sql openmrs file

@dkayiwa
Copy link
Member

dkayiwa commented May 4, 2025

Meaning that this is not yet ready for review and testing?

@Muta-Jonathan
Copy link
Member Author

sure in the meantime am going to convert it to draft .. however am wondering if we have archives for the latest dump files I can use inorder to fix the sql table errors also updated liquibase files to try out on the latest version

@dkayiwa
Copy link
Member

dkayiwa commented May 4, 2025

And FWIW, now the mvn package stage results into this: https://pastebin.com/SWD8mpSF

@Muta-Jonathan Muta-Jonathan marked this pull request as draft May 4, 2025 22:12
@Muta-Jonathan Muta-Jonathan marked this pull request as ready for review May 13, 2025 13:52
@Muta-Jonathan
Copy link
Member Author

cc @wikumChamith @dkayiwa

@dkayiwa
Copy link
Member

dkayiwa commented May 13, 2025

Choosing the demo data option takes me to the The OpenMRS 2.8.0 server is currently in maintenance mode. page. It is supposed to do all the setup behind the scenes and just take me to the log in page.

@Muta-Jonathan
Copy link
Member Author

On this small adjustment have been able to load the updated demo data which have named 2.0.0 however found out that in liquibase-update-to-latest.xml we have changesets with defined dbms="mysql" such as <changeSet id="20100128-1" author="djazayeri" dbms="mysql"> and this to note comes from the core which is resulting into

resulting into errors like

Running Changeset: liquibase-update-to-latest.xml::20090402-1516-encounter_type::bwolfe
INFO - Slf4JLogger.log(43) |2025-05-15T21:23:20,743| Marking ChangeSet: "liquibase-update-to-latest.xml::20090402-1516-encounter_type::bwolfe" as ran despite precondition failure due to onFail='MARK_RAN': 
          liquibase-update-to-latest.xml : DBMS Precondition failed: expected mysql, got mariadb
          liquibase-update-to-latest.xml : DBMS Precondition failed: expected oracle, got mariadb

find the full errors here https://pastebin.com/LbhM5DRY

cc @dkayiwa @wikumChamith

@dkayiwa
Copy link
Member

dkayiwa commented May 15, 2025

@Muta-Jonathan which version of liquibase is the standalone configured with?

@Muta-Jonathan
Copy link
Member Author

liquibase

4.4.1

@dkayiwa
Copy link
Member

dkayiwa commented May 15, 2025

Does it help if you switch it to 4.31.1?

@Muta-Jonathan
Copy link
Member Author

Does it help if you switch it to 4.31.1?

let me try that

@dkayiwa
Copy link
Member

dkayiwa commented May 15, 2025

@Muta-Jonathan i have just run your changes but i still get the The OpenMRS 2.8.0 server is currently in maintenance mode. I should instead see the normal login screen instead of the setup login page.

@Muta-Jonathan
Copy link
Member Author

@Muta-Jonathan i have just run your changes but i still get the The OpenMRS 2.8.0 server is currently in maintenance mode. I should instead see the normal login screen instead of the setup login page.

Am trying to figure out why the war file is not triggering the setup wizard which will then re-direct to the login in page but currently unable to find the cause .... however seen in core for the installation wizard to load the setup must be missing openmrs-runtime.properties For this i dont know for sure if am oon the right track could there be something am missing?

@Muta-Jonathan Muta-Jonathan requested a review from dkayiwa June 16, 2025 07:30
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.build.directory}/demodatabase/data</directory>
<!-- <directory>${project.build.directory}/demodatabase/data</directory>-->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choosing the demo data option takes me to the The OpenMRS 2.8.0 server is currently in maintenance mode. page. It is supposed to do all the setup behind the scenes and just take me to the log in page.

I believe this is happening because of this line in trying to zip the demodatabase it fails here saying the demo is not in the directory

<configuration>
<tasks>
\ <unzip src="${liquibase.demodata.archive}" dest="." />
<unzip src="${liquibase.demodata.archive}" dest="." />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which executes here named in the pom.xml as
<liquibase.demodata.archive>Demo-1.9.0.sql.zip</liquibase.demodata.archive>
And since the Unzipped db at this stage contains no tables and schema for the Db ... the tables are not created hence the re-direct to Maintainance page

mariaDB.run("FLUSH PRIVILEGES;");

// Create the OpenMRS database schema if it doesn't exist
mariaDB.createDB(DATABASE_NAME, DATABASE_USER_NAME, userPassword);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just found the issue causing the installation wizard to fail to start ... this is due to creating the Openmrs database schema here which tells the core that already the scheme is available ...

build-macos:
name: on macOS (Java 21)
runs-on: macos-latest
runs-on: macos-15
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was getting this error on Ci

dyld[2778]: Symbol not found: _vidattr$NCURSES60
Referenced from: mariadb (built for macOS 15.0 which is newer than running OS)
Expected in: /usr/lib/libncurses.5.4.dylib

According to this so far github maps macos-latest to OS Version: macOS 14.7.6 (23H626) https://arc.net/l/quote/tdcfqkkj ...now had to manually specify macos-15


- name: Build and Test with Maven
run: mvn clean install
run: mvn clean install -DskipTests
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally this i placed it here because the maven liquibase tests start the db which later seems to delay to close for macos and windows conflicting with the normal java tests causing database fails to start


- name: Build and Test with Maven
run: mvn clean install
run: mvn clean install -DskipTests
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the question still stands ...let me try to refactor for both mac and windows

build-macos:
name: on macOS (Java 21)
runs-on: macos-latest
runs-on: macos-15
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes @dkayiwa explained the error i was getting above and why i used macos-15

Was getting this error on Ci

dyld[2778]: Symbol not found: _vidattr$NCURSES60
Referenced from: mariadb (built for macOS 15.0 which is newer than running OS)
Expected in: /usr/lib/libncurses.5.4.dylib

According to this so far github maps macos-latest to OS Version: macOS 14.7.6 (23H626) https://arc.net/l/quote/tdcfqkkj ...now had to manually specify macos-15

cp ../target/*database.zip .
ln -s ../tomcat tomcat
cp ../*.png .
cp ../openmrs-standalone-runtime.properties .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you renamed this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this was coping ../openmrs-standalone-runtime.properties which doesnot exist basically it is now ../openmrs-runtime.properties

cp ../openmrs-standalone-runtime.properties .
cp ../openmrs-runtime.properties .
cp ../target/*.jar .
cp ../target/openmrs-standalone.war tomcat/webapps/openmrs-standalone.war
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you renamed this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this was coping ../target/openmrs-standalone.war yet in target we have ../target/openmrs.war also the in the standalone code we look for openmrs.war in the webapps directory not openmrs-standalone.war

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did we do to change it from the original name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from this commit here Muta-Jonathan@c3ea3fc i see that Raf removed it and later openmrs.war was introduced Muta-Jonathan@305097c

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit explains why it has been like that for a while ... this is the last commit before my changes Muta-Jonathan@248ac66 here i see in pom.xml that

<configuration>Add commentMore actions
     <artifactItems>
	  <artifactItem>
		<groupId>org.openmrs.web</groupId>
	        <artifactId>openmrs-webapp</artifactId>
		<version>${openmrs.version}</version>
		<type>war</type>
		<outputDirectory>target</outputDirectory>
		<destFileName>openmrs-standalone.war</destFileName>
	</artifactItem>
    </artifactItems>
</configuration>

which shows that the packagezip.sh expected the change also done in that commit cp ../target/openmrs-standalone.war tomcat/webapps/openmrs-standalone.war which later even after the update to openmrs.war in the pom.xml this Muta-Jonathan@305097c wasnt addressed

StandaloneUtil.resetConnectionPassword();
StandaloneUtil.startupDatabaseToCreateDefaultUser();
StandaloneUtil.startupDatabaseToCreateDefaultUser(mySqlPort);
System.out.println("Database mode using wizard: " + applyDatabaseChange );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need the System.out.println statements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these to be shown in the logs

@Muta-Jonathan Muta-Jonathan requested a review from dkayiwa June 16, 2025 19:38
@dkayiwa dkayiwa merged commit 2f591f8 into openmrs:master Jun 16, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants