mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-26 10:01:23 +01:00
Fix BadJoinAddressDataCorrectionPatch
This commit is contained in:
parent
6e8dc2215e
commit
d0030fc6e3
@ -80,14 +80,17 @@ public class BadJoinAddressDataCorrectionPatch extends Patch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateOldIds(Map<Integer, Integer> oldToNewIds) {
|
private void updateOldIds(Map<Integer, Integer> oldToNewIds) {
|
||||||
String sql = "UPDATE " + SessionsTable.TABLE_NAME + " SET " + SessionsTable.JOIN_ADDRESS_ID + "=?" +
|
String sql = "UPDATE " + SessionsTable.TABLE_NAME +
|
||||||
|
" SET " + SessionsTable.JOIN_ADDRESS_ID + "=?" +
|
||||||
WHERE + SessionsTable.JOIN_ADDRESS_ID + "=?";
|
WHERE + SessionsTable.JOIN_ADDRESS_ID + "=?";
|
||||||
execute(new ExecBatchStatement(sql) {
|
execute(new ExecBatchStatement(sql) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
for (Map.Entry<Integer, Integer> entry : oldToNewIds.entrySet()) {
|
for (Map.Entry<Integer, Integer> entry : oldToNewIds.entrySet()) {
|
||||||
statement.setInt(1, entry.getKey());
|
Integer newId = entry.getValue();
|
||||||
statement.setInt(2, entry.getValue());
|
Integer oldId = entry.getKey();
|
||||||
|
statement.setInt(1, newId);
|
||||||
|
statement.setInt(2, oldId);
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.storage.database.transactions.patches;
|
package com.djrapitops.plan.storage.database.transactions.patches;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.gathering.domain.FinishedSession;
|
||||||
|
import com.djrapitops.plan.gathering.domain.event.JoinAddress;
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
import com.djrapitops.plan.storage.database.Database;
|
||||||
import com.djrapitops.plan.storage.database.DatabaseTestPreparer;
|
import com.djrapitops.plan.storage.database.DatabaseTestPreparer;
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.JoinAddressQueries;
|
import com.djrapitops.plan.storage.database.queries.objects.JoinAddressQueries;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable;
|
import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||||
import com.djrapitops.plan.storage.database.transactions.events.StoreJoinAddressTransaction;
|
import com.djrapitops.plan.storage.database.transactions.events.StoreJoinAddressTransaction;
|
||||||
|
import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction;
|
||||||
|
import com.djrapitops.plan.storage.database.transactions.events.StoreWorldNameTransaction;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
|
||||||
@ -74,6 +78,35 @@ public interface BadJoinAddressDataCorrectionPatchTest extends DatabaseTestPrepa
|
|||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
default void joinAddressWithBadDataIsCorrectedWithOriginalPlusSessions() {
|
||||||
|
Database db = db();
|
||||||
|
String correct = "correct_address";
|
||||||
|
String bad = "correct_address\u000062.6.…zwyzyty0zmnlowzmmtqynmm";
|
||||||
|
db.executeTransaction(new StoreJoinAddressTransaction(correct));
|
||||||
|
db.executeTransaction(new StoreJoinAddressTransaction(bad));
|
||||||
|
|
||||||
|
executeTransactions(new StoreWorldNameTransaction(serverUUID(), worlds[0]));
|
||||||
|
executeTransactions(new StoreWorldNameTransaction(serverUUID(), worlds[1]));
|
||||||
|
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
|
||||||
|
session.getExtraData().put(JoinAddress.class, new JoinAddress(bad));
|
||||||
|
executeTransactions(new StoreSessionTransaction(session));
|
||||||
|
|
||||||
|
Set<String> preTestExpected = Set.of(bad);
|
||||||
|
Set<String> preTestResult = db.query(JoinAddressQueries.latestJoinAddresses()).keySet();
|
||||||
|
assertEquals(preTestExpected, preTestResult);
|
||||||
|
|
||||||
|
System.out.println(db.queryList("SELECT join_address_id FROM plan_sessions", set -> set.getInt(1)));
|
||||||
|
BadJoinAddressDataCorrectionPatch patch = new BadJoinAddressDataCorrectionPatch();
|
||||||
|
db.executeTransaction(patch);
|
||||||
|
assertTrue(patch.wasApplied());
|
||||||
|
System.out.println(db.queryList("SELECT join_address_id FROM plan_sessions", set -> set.getInt(1)));
|
||||||
|
|
||||||
|
Set<String> expected = Set.of(correct);
|
||||||
|
Set<String> result = db.query(JoinAddressQueries.latestJoinAddresses()).keySet();
|
||||||
|
assertEquals(expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
default void joinAddressWithBadDataIsCorrectedWithoutOriginal() {
|
default void joinAddressWithBadDataIsCorrectedWithoutOriginal() {
|
||||||
Database db = db();
|
Database db = db();
|
||||||
|
Loading…
Reference in New Issue
Block a user