mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-04 23:48:42 +01:00
Removed IP column from plan_ips
This commit is contained in:
parent
21d255b611
commit
5af4fea2b4
@ -165,7 +165,7 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
new GeoInfoOptimizationPatch(),
|
||||
new TransferTableRemovalPatch(),
|
||||
new BadAFKThresholdValuePatch(),
|
||||
new DeleteIPHashesPatch(),
|
||||
new DeleteIPsPatch(),
|
||||
new ExtensionShowInPlayersTablePatch(),
|
||||
new ExtensionTableRowValueLengthPatch()
|
||||
};
|
||||
|
@ -136,9 +136,8 @@ public class DataStoreQueries {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
statement.setString(2, geoInfo.getIp());
|
||||
statement.setString(3, geoInfo.getGeolocation());
|
||||
statement.setLong(4, geoInfo.getDate());
|
||||
statement.setString(2, geoInfo.getGeolocation());
|
||||
statement.setLong(3, geoInfo.getDate());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -63,14 +63,12 @@ public class LargeStoreQueries {
|
||||
UUID playerUUID = playerEntry.getKey();
|
||||
// Every GeoInfo
|
||||
for (GeoInfo info : playerEntry.getValue()) {
|
||||
String ip = info.getIp();
|
||||
String geoLocation = info.getGeolocation();
|
||||
long lastUsed = info.getDate();
|
||||
|
||||
statement.setString(1, playerUUID.toString());
|
||||
statement.setString(2, ip);
|
||||
statement.setString(3, geoLocation);
|
||||
statement.setLong(4, lastUsed);
|
||||
statement.setString(2, geoLocation);
|
||||
statement.setLong(3, lastUsed);
|
||||
|
||||
statement.addBatch();
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ public class GeoInfoQueries {
|
||||
*/
|
||||
public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInformation() {
|
||||
String sql = SELECT +
|
||||
GeoInfoTable.IP + ',' +
|
||||
GeoInfoTable.GEOLOCATION + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.USER_UUID +
|
||||
@ -114,8 +113,7 @@ public class GeoInfoQueries {
|
||||
public static Query<Map<UUID, List<GeoInfo>>> fetchServerGeoInformation(UUID serverUUID) {
|
||||
String sql = SELECT + GeoInfoTable.TABLE_NAME + '.' + GeoInfoTable.USER_UUID + ',' +
|
||||
GeoInfoTable.GEOLOCATION + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.IP +
|
||||
GeoInfoTable.LAST_USED +
|
||||
FROM + GeoInfoTable.TABLE_NAME +
|
||||
INNER_JOIN + UserInfoTable.TABLE_NAME + " on " +
|
||||
GeoInfoTable.TABLE_NAME + '.' + GeoInfoTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID +
|
||||
|
@ -19,7 +19,6 @@ package com.djrapitops.plan.storage.database.sql.tables;
|
||||
import com.djrapitops.plan.storage.database.DBType;
|
||||
import com.djrapitops.plan.storage.database.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.storage.database.sql.parsing.Sql;
|
||||
import com.djrapitops.plan.storage.database.transactions.patches.DeleteIPHashesPatch;
|
||||
import com.djrapitops.plan.storage.database.transactions.patches.GeoInfoLastUsedPatch;
|
||||
import com.djrapitops.plan.storage.database.transactions.patches.GeoInfoOptimizationPatch;
|
||||
import com.djrapitops.plan.storage.database.transactions.patches.Version10Patch;
|
||||
@ -34,27 +33,23 @@ import static com.djrapitops.plan.storage.database.sql.parsing.Sql.WHERE;
|
||||
* {@link Version10Patch}
|
||||
* {@link GeoInfoLastUsedPatch}
|
||||
* {@link GeoInfoOptimizationPatch}
|
||||
* {@link DeleteIPHashesPatch}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GeoInfoTable {
|
||||
|
||||
public static final String TABLE_NAME = "plan_ips";
|
||||
public static final String TABLE_NAME = "plan_geolocations";
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String USER_UUID = "uuid";
|
||||
@Deprecated
|
||||
public static final String IP = "ip";
|
||||
public static final String GEOLOCATION = "geolocation";
|
||||
public static final String LAST_USED = "last_used";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ USER_UUID + ','
|
||||
+ IP + ','
|
||||
+ GEOLOCATION + ','
|
||||
+ LAST_USED
|
||||
+ ") VALUES (?, ?, ?, ?)";
|
||||
+ ") VALUES (?, ?, ?)";
|
||||
|
||||
public static final String UPDATE_STATEMENT = "UPDATE " + TABLE_NAME + " SET "
|
||||
+ LAST_USED + "=?" +
|
||||
@ -69,7 +64,6 @@ public class GeoInfoTable {
|
||||
return CreateTableParser.create(TABLE_NAME, dbType)
|
||||
.column(ID, Sql.INT).primaryKey()
|
||||
.column(USER_UUID, Sql.varchar(36)).notNull()
|
||||
.column(IP, Sql.varchar(39)).notNull()
|
||||
.column(GEOLOCATION, Sql.varchar(50)).notNull()
|
||||
.column(LAST_USED, Sql.LONG).notNull().defaultValue("0")
|
||||
.toString();
|
||||
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.storage.database.transactions.patches;
|
||||
|
||||
import com.djrapitops.plan.storage.database.queries.HasMoreThanZeroQueryStatement;
|
||||
import com.djrapitops.plan.storage.database.sql.tables.GeoInfoTable;
|
||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import static com.djrapitops.plan.storage.database.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Patch for removing ip_hash values from plan_ips table.
|
||||
* <p>
|
||||
* The patch is a response to a concern:
|
||||
* "Hashed IP addresses are pseudonymised not anonymised and can be easily decoded using a rainbow table".
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class DeleteIPHashesPatch extends Patch {
|
||||
|
||||
private static final String IP_HASH = "ip_hash";
|
||||
|
||||
private boolean hasNoHashColumn;
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
hasNoHashColumn = !hasColumn(GeoInfoTable.TABLE_NAME, IP_HASH);
|
||||
|
||||
String sql = SELECT + "COUNT(1) as c" + FROM + GeoInfoTable.TABLE_NAME +
|
||||
WHERE + IP_HASH + IS_NOT_NULL;
|
||||
|
||||
return hasNoHashColumn || !query(new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) {
|
||||
/* No variables needed */
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
if (hasNoHashColumn) {
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = "UPDATE " + GeoInfoTable.TABLE_NAME + " SET ip_hash=?" + WHERE + IP_HASH + IS_NOT_NULL;
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setNull(1, Types.VARCHAR);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.storage.database.transactions.patches;
|
||||
|
||||
import com.djrapitops.plan.storage.database.sql.tables.GeoInfoTable;
|
||||
|
||||
import static com.djrapitops.plan.storage.database.sql.parsing.Sql.DISTINCT;
|
||||
import static com.djrapitops.plan.storage.database.sql.parsing.Sql.FROM;
|
||||
|
||||
/**
|
||||
* Patch that replaces plan_ips with plan_geolocations table.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DeleteIPsPatch extends Patch {
|
||||
|
||||
private final String tempTableName;
|
||||
|
||||
public DeleteIPsPatch() {
|
||||
tempTableName = "temp_ips";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return !hasTable("plan_ips");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
tempOldTable();
|
||||
|
||||
dropTable(GeoInfoTable.TABLE_NAME);
|
||||
execute(GeoInfoTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + GeoInfoTable.TABLE_NAME + " (" +
|
||||
GeoInfoTable.USER_UUID + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
") SELECT " + DISTINCT +
|
||||
GeoInfoTable.USER_UUID + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
}
|
||||
|
||||
private void tempOldTable() {
|
||||
if (!hasTable(tempTableName)) {
|
||||
renameTable("plan_ips", tempTableName);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,24 +18,25 @@ package com.djrapitops.plan.storage.database.transactions.patches;
|
||||
|
||||
import com.djrapitops.plan.storage.database.sql.tables.GeoInfoTable;
|
||||
|
||||
import static com.djrapitops.plan.storage.database.sql.parsing.Sql.FROM;
|
||||
import static com.djrapitops.plan.storage.database.sql.parsing.Sql.*;
|
||||
|
||||
public class GeoInfoOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
private String tableName;
|
||||
private String oldTableName;
|
||||
|
||||
public GeoInfoOptimizationPatch() {
|
||||
tableName = GeoInfoTable.TABLE_NAME;
|
||||
oldTableName = "plan_ips";
|
||||
tempTableName = "temp_ips";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return hasColumn(tableName, GeoInfoTable.ID)
|
||||
&& hasColumn(tableName, GeoInfoTable.USER_UUID)
|
||||
&& !hasColumn(tableName, "user_id")
|
||||
&& !hasTable(tempTableName); // If this table exists the patch has failed to finish.
|
||||
return !hasTable(oldTableName)
|
||||
|| (hasColumn(oldTableName, GeoInfoTable.ID)
|
||||
&& hasColumn(oldTableName, GeoInfoTable.USER_UUID)
|
||||
&& !hasColumn(oldTableName, "user_id")
|
||||
&& !hasTable(tempTableName)); // If this table exists the patch has failed to finish.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,14 +44,12 @@ public class GeoInfoOptimizationPatch extends Patch {
|
||||
tempOldTable();
|
||||
execute(GeoInfoTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
execute("INSERT INTO " + GeoInfoTable.TABLE_NAME + " (" +
|
||||
GeoInfoTable.USER_UUID + ',' +
|
||||
GeoInfoTable.IP + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
") SELECT " +
|
||||
") " + SELECT + DISTINCT +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
GeoInfoTable.IP + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
FROM + tempTableName
|
||||
@ -61,7 +60,7 @@ public class GeoInfoOptimizationPatch extends Patch {
|
||||
|
||||
private void tempOldTable() {
|
||||
if (!hasTable(tempTableName)) {
|
||||
renameTable(tableName, tempTableName);
|
||||
renameTable(oldTableName, tempTableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user