diff --git a/pom.xml b/pom.xml
index 373713bd7e..945a417fd8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,6 +66,7 @@
6.3.0
9.3.0
3.49.5
+ 4.32.0
5.13.1
5.18.0
@@ -98,7 +99,11 @@
jdbi3-core
${jdbi-version}
-
+
+ org.liquibase
+ liquibase-core
+ ${liquibase-core.version}
+
diff --git a/src/main/java/database/DatabaseMigrations.java b/src/main/java/database/DatabaseMigrations.java
new file mode 100644
index 0000000000..9033b3d689
--- /dev/null
+++ b/src/main/java/database/DatabaseMigrations.java
@@ -0,0 +1,35 @@
+package database;
+
+import liquibase.Liquibase;
+import liquibase.UpdateSummaryOutputEnum;
+import liquibase.database.jvm.JdbcConnection;
+import liquibase.exception.LiquibaseException;
+import liquibase.resource.ClassLoaderResourceAccessor;
+import tools.DatabaseConnection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class DatabaseMigrations {
+
+ public static void runDatabaseMigrations() {
+ suppressLiquibaseLogs();
+ runLiquibaseUpdate();
+ }
+
+ private static void suppressLiquibaseLogs() {
+ java.util.logging.Logger liquibaseLogger = java.util.logging.Logger.getLogger("liquibase");
+ liquibaseLogger.setLevel(java.util.logging.Level.WARNING);
+ }
+
+ private static void runLiquibaseUpdate() {
+ try (Connection connection = DatabaseConnection.getConnection()) {
+ liquibase.database.DatabaseConnection databaseConnection = new JdbcConnection(connection);
+ Liquibase liquibase = new Liquibase("db/changelog.xml", new ClassLoaderResourceAccessor(), databaseConnection);
+ liquibase.setShowSummaryOutput(UpdateSummaryOutputEnum.LOG);
+ liquibase.update();
+ } catch (SQLException | LiquibaseException e) {
+ throw new RuntimeException("Failed to run database migrations", e);
+ }
+ }
+}
diff --git a/src/main/java/net/server/Server.java b/src/main/java/net/server/Server.java
index 1b0159d2cc..6c61e5ce2a 100644
--- a/src/main/java/net/server/Server.java
+++ b/src/main/java/net/server/Server.java
@@ -36,6 +36,7 @@ import constants.game.GameConstants;
import constants.inventory.ItemConstants;
import constants.net.OpcodeConstants;
import constants.net.ServerConstants;
+import database.DatabaseMigrations;
import database.note.NoteDao;
import net.ChannelDependencies;
import net.PacketProcessor;
@@ -869,6 +870,8 @@ public class Server {
throw new IllegalStateException("Failed to initiate a connection to the database");
}
+ DatabaseMigrations.runDatabaseMigrations();
+
channelDependencies = registerChannelDependencies();
final ExecutorService initExecutor = Executors.newFixedThreadPool(10);
diff --git a/src/main/resources/db/changelog.xml b/src/main/resources/db/changelog.xml
new file mode 100644
index 0000000000..a1f0567ef1
--- /dev/null
+++ b/src/main/resources/db/changelog.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/db/test-liquibase.sql b/src/main/resources/db/test-liquibase.sql
new file mode 100644
index 0000000000..f6e0582883
--- /dev/null
+++ b/src/main/resources/db/test-liquibase.sql
@@ -0,0 +1,4 @@
+CREATE TABLE test_liquibase
+(
+ id INT NOT NULL
+);
\ No newline at end of file