Skip to content

Commit 5c07624

Browse files
committed
Add cellular data usage tracking schema
Adds database infrastructure for tracking data usage: - CellularDataUsageRecord GRDB model with operation type, connection type, and bytes - CellularDataUsageManager with record/query methods - Weekly aggregation queries for reporting
1 parent 6508cd9 commit 5c07624

File tree

4 files changed

+474
-0
lines changed

4 files changed

+474
-0
lines changed

Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/Util/DatabaseHelper.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,34 @@ class DatabaseHelper {
882882
}
883883
}
884884

885+
if schemaVersion < 72 {
886+
do {
887+
try db.executeUpdate("""
888+
CREATE TABLE IF NOT EXISTS CellularDataUsage (
889+
id INTEGER PRIMARY KEY AUTOINCREMENT,
890+
timestamp REAL NOT NULL,
891+
episode_uuid TEXT,
892+
podcast_uuid TEXT,
893+
bytes_downloaded INTEGER NOT NULL DEFAULT 0,
894+
bytes_streamed INTEGER NOT NULL DEFAULT 0,
895+
bytes_uploaded INTEGER NOT NULL DEFAULT 0,
896+
operation_type TEXT NOT NULL,
897+
connection_type INTEGER NOT NULL,
898+
session_type TEXT
899+
);
900+
""", values: nil)
901+
902+
try db.executeUpdate("CREATE INDEX IF NOT EXISTS cellular_data_timestamp ON CellularDataUsage (timestamp);", values: nil)
903+
try db.executeUpdate("CREATE INDEX IF NOT EXISTS cellular_data_episode ON CellularDataUsage (episode_uuid);", values: nil)
904+
try db.executeUpdate("CREATE INDEX IF NOT EXISTS cellular_data_connection ON CellularDataUsage (connection_type);", values: nil)
905+
906+
schemaVersion = 72
907+
} catch {
908+
failedAt(72)
909+
return
910+
}
911+
}
912+
885913
db.commit()
886914
}
887915
}

0 commit comments

Comments
 (0)