From 09fef5b38c1749033a436cdb01a1655e3880d559 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 29 Jul 2018 12:27:24 +0200 Subject: [PATCH] Remove database migration from old versions --- .../de/epiceric/shopchest/sql/Database.java | 58 ++----------------- 1 file changed, 6 insertions(+), 52 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/sql/Database.java b/src/main/java/de/epiceric/shopchest/sql/Database.java index 6e9b77e..1248f45 100644 --- a/src/main/java/de/epiceric/shopchest/sql/Database.java +++ b/src/main/java/de/epiceric/shopchest/sql/Database.java @@ -94,66 +94,20 @@ public abstract class Database { "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" Statement s = connection.createStatement(); s.executeUpdate(queryCreateTableShopList); 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" - Statement s3 = connection.createStatement(); - s3.executeUpdate(queryCreateTableShopLog); - s3.close(); + Statement s2 = connection.createStatement(); + s2.executeUpdate(queryCreateTableShopLog); + s2.close(); // Create table "player_logout" - Statement s4 = connection.createStatement(); - s4.executeUpdate(queryCreateTablePlayerLogout); - s4.close(); + Statement s3 = connection.createStatement(); + s3.executeUpdate(queryCreateTablePlayerLogout); + s3.close(); // Clean up economy log if (Config.cleanupEconomyLogDays > 0) {