Skip to content

Commit

Permalink
Drop IP column from the Network table
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Dec 18, 2024
1 parent 369f358 commit 49a93af
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.ooni.engine.models.NetworkType
data class NetworkModel(
@SerialName("id") val id: Id? = null,
@SerialName("network_name") val networkName: String?,
@SerialName("ip") val ip: String?,
@SerialName("asn") val asn: String?,
@SerialName("country_code") val countryCode: String?,
@SerialName("networkType") val networkType: NetworkType?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class NetworkRepository(
if (model.id == null) {
database.networkQueries.selectByValues(
network_name = model.networkName,
ip = model.ip,
asn = model.asn,
country_code = model.countryCode,
network_type = model.networkType?.value,
Expand All @@ -37,7 +36,6 @@ class NetworkRepository(
database.networkQueries.insertOrReplace(
id = model.id?.value,
network_name = model.networkName,
ip = model.ip,
asn = model.asn,
country_code = model.countryCode,
network_type = model.networkType?.value,
Expand All @@ -62,7 +60,6 @@ fun Network.toModel(): NetworkModel =
NetworkModel(
id = NetworkModel.Id(id),
networkName = network_name,
ip = ip,
asn = asn,
countryCode = country_code,
networkType = network_type?.let(NetworkType::fromValue),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class ResultRepository(
Network(
id = networkId,
network_name = network_name,
ip = ip,
asn = asn,
country_code = country_code,
network_type = network_type,
Expand Down Expand Up @@ -203,7 +202,6 @@ class ResultRepository(
Network(
id = networkId,
network_name = network_name,
ip = ip,
asn = asn,
country_code = country_code,
network_type = network_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class RunNetTest(
is TaskEvent.GeoIpLookup -> {
val network = NetworkModel(
networkName = event.networkName,
ip = event.ip,
asn = event.asn,
countryCode = event.countryCode,
networkType = event.networkType,
Expand Down
16 changes: 16 additions & 0 deletions composeApp/src/commonMain/sqldelight/migrations/9.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN TRANSACTION;

CREATE TABLE NetworkTemporary(
id INTEGER PRIMARY KEY AUTOINCREMENT,
network_name TEXT,
asn TEXT,
country_code TEXT,
network_type TEXT
);

INSERT INTO NetworkTemporary SELECT id, network_name, asn, country_code, network_type FROM Network;

DROP TABLE Network;
ALTER TABLE NetworkTemporary RENAME TO Network;

COMMIT;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CREATE TABLE Network(
id INTEGER PRIMARY KEY AUTOINCREMENT,
network_name TEXT,
ip TEXT,
asn TEXT,
country_code TEXT,
network_type TEXT
Expand All @@ -11,11 +10,10 @@ insertOrReplace:
INSERT OR REPLACE INTO Network (
id,
network_name,
ip,
asn,
country_code,
network_type
) VALUES (?,?,?,?,?,?);
) VALUES (?,?,?,?,?);

deleteAll:
DELETE FROM Network;
Expand All @@ -28,5 +26,5 @@ SELECT * FROM Network;

selectByValues:
SELECT * FROM Network
WHERE network_name = ? AND ip = ? AND asn = ? AND country_code = ? AND network_type = ?
WHERE network_name = ? AND asn = ? AND country_code = ? AND network_type = ?
LIMIT 1;
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ object NetworkModelFactory {
fun build(
id: NetworkModel.Id? = null,
networkName: String? = "Vodafone",
ip: String? = null,
asn: String? = null,
countryCode: String? = null,
networkType: NetworkType? = null,
) = NetworkModel(
id = id,
networkName = networkName,
ip = ip,
asn = asn,
countryCode = countryCode,
networkType = networkType,
Expand Down

0 comments on commit 49a93af

Please sign in to comment.