mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 04:25:14 +01:00
Migrate all versions and disable on fail.
This should make it possible to theoretically upgrade from version 1 to version 3 databases.
This commit is contained in:
parent
5d73320889
commit
0354258251
@ -91,7 +91,9 @@ public class ChestShop extends JavaPlugin {
|
||||
Configuration.pairFileAndClass(loadFile("local.yml"), Messages.class);
|
||||
|
||||
turnOffDatabaseLogging();
|
||||
handleMigrations();
|
||||
if (!handleMigrations()) {
|
||||
return;
|
||||
}
|
||||
|
||||
itemDatabase = new ItemDatabase();
|
||||
|
||||
@ -164,7 +166,7 @@ public class ChestShop extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
private void handleMigrations() {
|
||||
private boolean handleMigrations() {
|
||||
File versionFile = loadFile("version");
|
||||
YamlConfiguration previousVersion = YamlConfiguration.loadConfiguration(versionFile);
|
||||
|
||||
@ -181,7 +183,11 @@ public class ChestShop extends JavaPlugin {
|
||||
int lastVersion = previousVersion.getInt("version");
|
||||
int newVersion = Migrations.migrate(lastVersion);
|
||||
|
||||
if (lastVersion != newVersion) {
|
||||
if (newVersion == -1) {
|
||||
plugin.getLogger().log(java.util.logging.Level.SEVERE, "Error while migrating! ChestShop can not run with a broken/outdated database...");
|
||||
plugin.getServer().getPluginManager().disablePlugin(this);
|
||||
return false;
|
||||
} else if (lastVersion != newVersion) {
|
||||
previousVersion.set("version", newVersion);
|
||||
|
||||
try {
|
||||
@ -190,6 +196,7 @@ public class ChestShop extends JavaPlugin {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static File loadFile(String string) {
|
||||
|
@ -33,22 +33,18 @@ public class Migrations {
|
||||
|
||||
switch (currentVersion) {
|
||||
case 1:
|
||||
boolean migrated = migrateTo2();
|
||||
|
||||
if (migrated) {
|
||||
if (migrateTo2()) {
|
||||
currentVersion++;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
|
||||
boolean migrated3 = migrateTo3();
|
||||
|
||||
if (migrated3) {
|
||||
if (migrateTo3()) {
|
||||
currentVersion++;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
//do nothing
|
||||
|
Loading…
Reference in New Issue
Block a user