From c103ec01efa17362de9ec52d2a2c49dba1f1043b Mon Sep 17 00:00:00 2001 From: diegonighty Date: Sun, 4 Aug 2024 15:31:44 -0500 Subject: [PATCH] fix: add database migration --- .../ChestShop/Database/Migrations.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Database/Migrations.java b/src/main/java/com/Acrobot/ChestShop/Database/Migrations.java index f5a2a2c..5d8e322 100644 --- a/src/main/java/com/Acrobot/ChestShop/Database/Migrations.java +++ b/src/main/java/com/Acrobot/ChestShop/Database/Migrations.java @@ -5,7 +5,6 @@ import com.j256.ormlite.dao.CloseableIterator; import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.GenericRawResults; -import java.io.IOException; import java.sql.SQLException; import java.util.Date; import java.util.UUID; @@ -17,7 +16,7 @@ import java.util.logging.Level; * @author Andrzej Pomirski */ public class Migrations { - public static final int CURRENT_DATABASE_VERSION = 4; + public static final int CURRENT_DATABASE_VERSION = 5; /** * Migrates a database from the given version @@ -50,6 +49,12 @@ public class Migrations { return -1; } case 4: + if (migrateTo5()) { + currentVersion++; + } else { + return -1; + } + case 5: default: break; //do nothing @@ -147,4 +152,15 @@ public class Migrations { return false; } } + + private static boolean migrateTo5() { + try { + Dao accounts = DaoCreator.getDao(Account.class); + accounts.executeRaw("ALTER TABLE `accounts` ADD COLUMN ignoreMessages BOOLEAN"); + return true; + } catch (SQLException e) { + ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while migrating database to v5", e); + return false; + } + } }