We do enjoy killing off orphans

This commit is contained in:
T00thpick1 2013-05-16 17:26:16 -04:00
parent d1a7ce827a
commit 9678875b4b
2 changed files with 32 additions and 1 deletions

View File

@ -151,6 +151,7 @@ public final class SQLDatabaseManager {
checkDatabaseStructure(DatabaseUpdateType.INDEX); checkDatabaseStructure(DatabaseUpdateType.INDEX);
checkDatabaseStructure(DatabaseUpdateType.MOB_HEALTHBARS); checkDatabaseStructure(DatabaseUpdateType.MOB_HEALTHBARS);
checkDatabaseStructure(DatabaseUpdateType.PARTY_NAMES); checkDatabaseStructure(DatabaseUpdateType.PARTY_NAMES);
checkDatabaseStructure(DatabaseUpdateType.KILL_ORPHANS);
} }
/** /**
@ -573,6 +574,34 @@ public final class SQLDatabaseManager {
write("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party` ;"); write("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party` ;");
break; 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: default:
break; break;
} }

View File

@ -5,5 +5,7 @@ public enum DatabaseUpdateType {
BLAST_MINING, BLAST_MINING,
INDEX, INDEX,
MOB_HEALTHBARS, MOB_HEALTHBARS,
PARTY_NAMES, PARTY_NAMES,
KILL_ORPHANS,
;
} }