Skip to content

Commit

Permalink
[#860] Fixed MySQL errno 150
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AuroraLS3 committed Jan 12, 2019
1 parent 8edc621 commit 4767de6
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
addColumn(TPSTable.TABLE_NAME,
TPSTable.Col.FREE_DISK + " bigint NOT NULL DEFAULT -1"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
addColumn(GeoInfoTable.TABLE_NAME,
GeoInfoTable.Col.LAST_USED + " bigint NOT NULL DEFAULT 0"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ && hasColumn(tableName, Col.UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getGeoInfoTable().createTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Boolean processResults(ResultSet set) throws SQLException {
}

@Override
public void apply() {
protected void applyPatch() {
Map<UUID, List<GeoInfo>> allGeoInfo = db.getGeoInfoTable().getAllGeoInfo();
anonymizeIPs(allGeoInfo);
groupHashedIPs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
addColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.Col.IP_HASH.get() + " varchar(200) DEFAULT ''");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ && hasColumn(tableName, Col.SERVER_UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getKillsTable().createTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Boolean processResults(ResultSet set) throws SQLException {
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
addColumn(NicknamesTable.TABLE_NAME,
NicknamesTable.Col.LAST_USED + " bigint NOT NULL DEFAULT '0'"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ && hasColumn(tableName, Col.SERVER_UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getNicknamesTable().createTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ public Patch(SQLDB db) {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ && hasColumn(tableName, Col.SERVER_UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getPingTable().createTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
addColumn(SessionsTable.TABLE_NAME,
SessionsTable.Col.AFK_TIME + " bigint NOT NULL DEFAULT 0"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ && hasColumn(tableName, Col.SERVER_UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
dropForeignKeys(tableName);
ensureNoForeignKeyConstraints(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
dropTable("plan_transfer");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ && hasColumn(tableName, Col.SERVER_UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getUserInfoTable().createTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
try {
Optional<Integer> fetchedServerID = db.getServerTable().getServerID(getServerUUID());
if (!fetchedServerID.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
protected void applyPatch() {
dropTable("plan_version");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ && hasColumn(tableName, Col.SERVER_UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
tempOldTable();
db.getWorldTimesTable().createTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Boolean processResults(ResultSet set) throws SQLException {
}

@Override
public void apply() {
protected void applyPatch() {
Map<Integer, Integer> sessionIDServerIDRelation = db.getSessionsTable().getIDServerIDRelation();

String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ && hasColumn(tableName, Col.SERVER_UUID.get())
}

@Override
public void apply() {
protected void applyPatch() {
try {
dropForeignKeys(tableName);
ensureNoForeignKeyConstraints(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Boolean processResults(ResultSet set) throws SQLException {
}

@Override
public void apply() {
protected void applyPatch() {
WorldTable worldTable = db.getWorldTable();

List<UUID> serverUUIDs = db.getServerTable().getServerUUIDs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public boolean hasBeenApplied() {
}

@Override
public void apply() {
public void applyPatch() {
dropTable("plan_world_times");
dropTable("plan_kills");
dropTable("plan_sessions");
Expand Down

0 comments on commit 4767de6

Please sign in to comment.