From 45299a153c3acd508d27743f3477da892a0b572d Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 16 Jan 2022 20:22:16 -0600 Subject: [PATCH] Finish upgrade SQL --- .../org/dynmap/storage/mysql/MySQLMapStorage.java | 13 +++++++++---- .../storage/postgresql/PostgreSQLMapStorage.java | 4 ++++ .../org/dynmap/storage/sqllte/SQLiteMapStorage.java | 3 +++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java index 46152a6c..d3a81472 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/mysql/MySQLMapStorage.java @@ -469,6 +469,7 @@ public class MySQLMapStorage extends MapStorage { // If new, add our tables if (version == 0) { try { + Log.info("Initializing database schema"); c = getConnection(); doUpdate(c, "CREATE TABLE " + tableMaps + " (ID INTEGER PRIMARY KEY AUTO_INCREMENT, WorldID VARCHAR(64) NOT NULL, MapID VARCHAR(64) NOT NULL, Variant VARCHAR(16) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0)"); doUpdate(c, "CREATE TABLE " + tableTiles + " (MapID INT NOT NULL, x INT NOT NULL, y INT NOT NULL, zoom INT NOT NULL, HashCode BIGINT NOT NULL, LastUpdate BIGINT NOT NULL, Format INT NOT NULL, Image MEDIUMBLOB, PRIMARY KEY(MapID, x, y, zoom))"); @@ -490,6 +491,7 @@ public class MySQLMapStorage extends MapStorage { } if (version == 1) { try { + Log.info("Updating database schema from version = " + version); c = getConnection(); doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content MEDIUMTEXT, PRIMARY KEY (FileName, ServerID))"); doUpdate(c, "ALTER TABLE " + tableMaps + " ADD COLUMN ServerID BIGINT NOT NULL DEFAULT 0 AFTER Variant"); @@ -506,6 +508,7 @@ public class MySQLMapStorage extends MapStorage { } if (version == 2) { try { + Log.info("Updating database schema from version = " + version); c = getConnection(); doUpdate(c, "DELETE FROM " + tableStandaloneFiles + ";"); doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " DROP COLUMN Content;"); @@ -523,11 +526,13 @@ public class MySQLMapStorage extends MapStorage { } if (version == 3) { try { + Log.info("Updating database schema from version = " + version); c = getConnection(); - doUpdate(c, "ALTER TABLE " + tableTiles + " ALTER COLUMN Image MEDIUMBLOB;"); - doUpdate(c, "ALTER TABLE " + tableFaces + " ALTER COLUMN Image MEDIUMBLOB;"); - doUpdate(c, "ALTER TABLE " + tableMarkerIcons + " ALTER COLUMN Image MEDIUMBLOB;"); + doUpdate(c, "ALTER TABLE " + tableTiles + " CHANGE COLUMN Image Image MEDIUMBLOB;"); + doUpdate(c, "ALTER TABLE " + tableFaces + " CHANGE COLUMN Image Image MEDIUMBLOB;"); + doUpdate(c, "ALTER TABLE " + tableMarkerIcons + " CHANGE COLUMN Image Image MEDIUMBLOB;"); doUpdate(c, "UPDATE " + tableSchemaVersion + " SET level=4 WHERE level = 3;"); + version = 4; } catch (SQLException x) { Log.severe("Error creating tables - " + x.getMessage()); err = true; @@ -536,8 +541,8 @@ public class MySQLMapStorage extends MapStorage { releaseConnection(c, err); c = null; } - } + Log.info("Schema version = " + version); // Load maps table - cache results doLoadMaps(); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java index 185e1642..683e6e6f 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java @@ -455,6 +455,7 @@ public class PostgreSQLMapStorage extends MapStorage { // If new, add our tables if (version == 0) { try { + Log.info("Initializing database schema"); c = getConnection(); doUpdate(c, "CREATE TABLE " + tableMaps + " (ID SERIAL PRIMARY KEY, WorldID VARCHAR(64) NOT NULL, MapID VARCHAR(64) NOT NULL, Variant VARCHAR(16) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0)"); doUpdate(c, "CREATE TABLE " + tableTiles + " (MapID INT NOT NULL, x INT NOT NULL, y INT NOT NULL, zoom INT NOT NULL, HashCode BIGINT NOT NULL, LastUpdate BIGINT NOT NULL, Format INT NOT NULL, Image BYTEA, PRIMARY KEY(MapID, x, y, zoom))"); @@ -476,6 +477,7 @@ public class PostgreSQLMapStorage extends MapStorage { } if (version == 1) { try { + Log.info("Updating database schema from version = " + version); c = getConnection(); doUpdate(c, "CREATE TABLE " + tableStandaloneFiles + " (FileName VARCHAR(128) NOT NULL, ServerID BIGINT NOT NULL DEFAULT 0, Content TEXT, PRIMARY KEY (FileName, ServerID))"); doUpdate(c, "ALTER TABLE " + tableMaps + " ADD COLUMN ServerID BIGINT NOT NULL DEFAULT 0 AFTER Variant"); @@ -492,6 +494,7 @@ public class PostgreSQLMapStorage extends MapStorage { } if (version == 2) { try { + Log.info("Updating database schema from version = " + version); c = getConnection(); doUpdate(c, "DELETE FROM " + tableStandaloneFiles + ";"); doUpdate(c, "ALTER TABLE " + tableStandaloneFiles + " DROP COLUMN Content;"); @@ -507,6 +510,7 @@ public class PostgreSQLMapStorage extends MapStorage { c = null; } } + Log.info("Schema version = " + version); // Load maps table - cache results doLoadMaps(); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java index 48cdfbcc..cf4b2476 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java @@ -394,6 +394,7 @@ public class SQLiteMapStorage extends MapStorage { // If new, add our tables if (version == 0) { try { + Log.info("Initializing database schema"); c = getConnection(); doUpdate(c, "CREATE TABLE Maps (ID INTEGER PRIMARY KEY AUTOINCREMENT, WorldID STRING NOT NULL, MapID STRING NOT NULL, Variant STRING NOT NULL)"); doUpdate(c, "CREATE TABLE Tiles (MapID INT NOT NULL, x INT NOT NULL, y INT NOT NULL, zoom INT NOT NULL, HashCode INT NOT NULL, LastUpdate INT NOT NULL, Format INT NOT NULL, Image BLOB, ImageLen INT, PRIMARY KEY(MapID, x, y, zoom))"); @@ -414,6 +415,7 @@ public class SQLiteMapStorage extends MapStorage { } if (version == 1) { // Add ImageLen columns try { + Log.info("Updating database schema from version = " + version); c = getConnection(); doUpdate(c, "ALTER TABLE Tiles ADD ImageLen INT"); doUpdate(c, "ALTER TABLE Faces ADD ImageLen INT"); @@ -429,6 +431,7 @@ public class SQLiteMapStorage extends MapStorage { c = null; } } + Log.info("Schema version = " + version); // Load maps table - cache results doLoadMaps();