From 9678875b4b8cce8f428d650f520c3d8dfe63b8dc Mon Sep 17 00:00:00 2001 From: T00thpick1 Date: Thu, 16 May 2013 17:26:16 -0400 Subject: [PATCH] We do enjoy killing off orphans --- .../nossr50/database/SQLDatabaseManager.java | 29 +++++++++++++++++++ .../database/DatabaseUpdateType.java | 4 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index bfefa2193..f4fb5be14 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -151,6 +151,7 @@ public final class SQLDatabaseManager { checkDatabaseStructure(DatabaseUpdateType.INDEX); checkDatabaseStructure(DatabaseUpdateType.MOB_HEALTHBARS); checkDatabaseStructure(DatabaseUpdateType.PARTY_NAMES); + checkDatabaseStructure(DatabaseUpdateType.KILL_ORPHANS); } /** @@ -573,6 +574,34 @@ public final class SQLDatabaseManager { write("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party` ;"); break; + case KILL_ORPHANS: + mcMMO.p.getLogger().info("Killing orphans"); + write( + "DELETE FROM " + tablePrefix + "experience " + + "WHERE NOT EXISTS (SELECT * FROM " + + tablePrefix + "users u WHERE " + + tablePrefix + "experience.user_id = u.id);" + ); + write( + "DELETE FROM " + tablePrefix + "huds " + + "WHERE NOT EXISTS (SELECT * FROM " + + tablePrefix + "users u WHERE " + + tablePrefix + "huds.user_id = u.id);" + ); + write( + "DELETE FROM " + tablePrefix + "cooldowns " + + "WHERE NOT EXISTS (SELECT * FROM " + + tablePrefix + "users u WHERE " + + tablePrefix + "cooldowns.user_id = u.id);" + ); + write( + "DELETE FROM " + tablePrefix + "skills " + + "WHERE NOT EXISTS (SELECT * FROM " + + tablePrefix + "users u WHERE " + + tablePrefix + "skills.user_id = u.id);" + ); + break; + default: break; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/database/DatabaseUpdateType.java b/src/main/java/com/gmail/nossr50/datatypes/database/DatabaseUpdateType.java index efeeafb04..c47919501 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/database/DatabaseUpdateType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/database/DatabaseUpdateType.java @@ -5,5 +5,7 @@ public enum DatabaseUpdateType { BLAST_MINING, INDEX, MOB_HEALTHBARS, - PARTY_NAMES, + PARTY_NAMES, + KILL_ORPHANS, + ; }