[#860] Fixed MySQL errno 150

Fixed by disabling foreign key checks before applying patches and
enabling afterwards.

Error was caused by re-creation of plan_sessions table during
plan_world_times creation (This was done by the database engine),
but plan_sessions was referenced by temp_world_times and so could not
be recreated as those references would become invalid.
This commit is contained in:
Rsl1122 2019-01-12 14:25:17 +02:00
parent 8edc621761
commit 4767de6687
22 changed files with 36 additions and 22 deletions

View File

@ -31,7 +31,7 @@ public class DiskUsagePatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
addColumn(TPSTable.TABLE_NAME,
TPSTable.Col.FREE_DISK + " bigint NOT NULL DEFAULT -1"
);

View File

@ -31,7 +31,7 @@ public class GeoInfoLastUsedPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
addColumn(GeoInfoTable.TABLE_NAME,
GeoInfoTable.Col.LAST_USED + " bigint NOT NULL DEFAULT 0"
);

View File

@ -41,7 +41,7 @@ public class GeoInfoOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getGeoInfoTable().createTable();

View File

@ -68,7 +68,7 @@ public class IPAnonPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
Map<UUID, List<GeoInfo>> allGeoInfo = db.getGeoInfoTable().getAllGeoInfo();
anonymizeIPs(allGeoInfo);
groupHashedIPs();

View File

@ -31,7 +31,7 @@ public class IPHashPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
addColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.Col.IP_HASH.get() + " varchar(200) DEFAULT ''");
}
}

View File

@ -44,7 +44,7 @@ public class KillsOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getKillsTable().createTable();

View File

@ -58,7 +58,7 @@ public class KillsServerIDPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
addColumn(KillsTable.TABLE_NAME, "server_id integer NOT NULL DEFAULT 0");
Map<Integer, Integer> sessionIDServerIDRelation = db.getSessionsTable().getIDServerIDRelation();

View File

@ -41,7 +41,7 @@ public class NicknameLastSeenPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
addColumn(NicknamesTable.TABLE_NAME,
NicknamesTable.Col.LAST_USED + " bigint NOT NULL DEFAULT '0'"
);

View File

@ -42,7 +42,7 @@ public class NicknamesOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getNicknamesTable().createTable();

View File

@ -45,7 +45,21 @@ public abstract class Patch {
public abstract boolean hasBeenApplied();
public abstract void apply();
protected abstract void applyPatch();
public void apply() {
if (dbType == DBType.MYSQL) disableForeignKeyChecks();
applyPatch();
if (dbType == DBType.MYSQL) enableForeignKeyChecks();
}
private void enableForeignKeyChecks() {
db.execute("SET FOREIGN_KEY_CHECKS=1");
}
private void disableForeignKeyChecks() {
db.execute("SET FOREIGN_KEY_CHECKS=0");
}
public <T> T query(QueryStatement<T> query) {
return db.query(query);

View File

@ -42,7 +42,7 @@ public class PingOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getPingTable().createTable();

View File

@ -31,7 +31,7 @@ public class SessionAFKTimePatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
addColumn(SessionsTable.TABLE_NAME,
SessionsTable.Col.AFK_TIME + " bigint NOT NULL DEFAULT 0"
);

View File

@ -42,7 +42,7 @@ public class SessionsOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
dropForeignKeys(tableName);
ensureNoForeignKeyConstraints(tableName);

View File

@ -30,7 +30,7 @@ public class TransferTableRemovalPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
dropTable("plan_transfer");
}
}

View File

@ -42,7 +42,7 @@ public class UserInfoOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getUserInfoTable().createTable();

View File

@ -37,7 +37,7 @@ public class Version10Patch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
Optional<Integer> fetchedServerID = db.getServerTable().getServerID(getServerUUID());
if (!fetchedServerID.isPresent()) {

View File

@ -30,7 +30,7 @@ public class VersionTableRemovalPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
dropTable("plan_version");
}
}

View File

@ -43,7 +43,7 @@ public class WorldTimesOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getWorldTimesTable().createTable();

View File

@ -59,7 +59,7 @@ public class WorldTimesSeverIDPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
Map<Integer, Integer> sessionIDServerIDRelation = db.getSessionsTable().getIDServerIDRelation();
String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " +

View File

@ -41,7 +41,7 @@ public class WorldsOptimizationPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
try {
dropForeignKeys(tableName);
ensureNoForeignKeyConstraints(tableName);

View File

@ -64,7 +64,7 @@ public class WorldsServerIDPatch extends Patch {
}
@Override
public void apply() {
protected void applyPatch() {
WorldTable worldTable = db.getWorldTable();
List<UUID> serverUUIDs = db.getServerTable().getServerUUIDs();

View File

@ -111,7 +111,7 @@ public abstract class CommonDBTest {
}
@Override
public void apply() {
public void applyPatch() {
dropTable("plan_world_times");
dropTable("plan_kills");
dropTable("plan_sessions");