Remove database migration from old versions

This commit is contained in:
Eric 2018-07-29 12:27:24 +02:00
parent b23040f7ce
commit 09fef5b38c

View File

@ -94,66 +94,20 @@ public abstract class Database {
"time LONG NOT NULL" + "time LONG NOT NULL" +
")"; ")";
String queryCheckIfTableExists =
(Database.this instanceof SQLite ?
"SELECT name FROM sqlite_master WHERE type='table' AND name='shop_list'" :
"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='shop_list'");
String queryCheckIfBackupTableExists =
(Database.this instanceof SQLite ?
"SELECT name FROM sqlite_master WHERE type='table' AND name='shop_list_old'" :
"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='shop_list_old'");
String queryCopyTableShopList = "INSERT INTO shops (vendor,product,world,x,y,z,buyprice,sellprice,shoptype) SELECT vendor,product,world,x,y,z,buyprice,sellprice,shoptype FROM shop_list";
String queryRenameTableShopList = "ALTER TABLE shop_list RENAME TO shop_list_old";
// Create table "shops" // Create table "shops"
Statement s = connection.createStatement(); Statement s = connection.createStatement();
s.executeUpdate(queryCreateTableShopList); s.executeUpdate(queryCreateTableShopList);
s.close(); s.close();
// Check if old table "shop_list" exists
Statement s2 = connection.createStatement();
ResultSet rs = s2.executeQuery(queryCheckIfTableExists);
if (rs.next()) {
plugin.debug("Table 'shop_list' exists");
// Check if backup table "shop_list_old" already exists
Statement s3 = connection.createStatement();
ResultSet rs2 = s3.executeQuery(queryCheckIfBackupTableExists);
if (rs2.next()) {
plugin.debug("Backup table 'shop_list_old' already exists: Cannot backup current table");
} else {
plugin.debug("Backing up old table");
// Table exists: Copy contents to new table
PreparedStatement ps = connection.prepareStatement(queryCopyTableShopList);
ps.executeUpdate();
ps.close();
plugin.debug("Renaming table");
// Rename/Backup old table
PreparedStatement ps2 = connection.prepareStatement(queryRenameTableShopList);
ps2.executeUpdate();
ps2.close();
}
close(s3, rs2);
}
close(s2, rs);
// Create table "shop_log" // Create table "shop_log"
Statement s3 = connection.createStatement(); Statement s2 = connection.createStatement();
s3.executeUpdate(queryCreateTableShopLog); s2.executeUpdate(queryCreateTableShopLog);
s3.close(); s2.close();
// Create table "player_logout" // Create table "player_logout"
Statement s4 = connection.createStatement(); Statement s3 = connection.createStatement();
s4.executeUpdate(queryCreateTablePlayerLogout); s3.executeUpdate(queryCreateTablePlayerLogout);
s4.close(); s3.close();
// Clean up economy log // Clean up economy log
if (Config.cleanupEconomyLogDays > 0) { if (Config.cleanupEconomyLogDays > 0) {