From 24dbd614ad555176eecfead06a86bd3deb3c87c0 Mon Sep 17 00:00:00 2001 From: F0x1d Date: Sun, 17 Dec 2023 15:02:10 +0300 Subject: [PATCH] [fix]: removed old log dumps in database --- .../13.json | 192 ++++++++++++++++++ .../com/f0x1d/logfox/database/AppDatabase.kt | 21 +- .../f0x1d/logfox/database/entity/AppCrash.kt | 1 - .../crashes/CrashDetailsViewModel.kt | 4 - 4 files changed, 212 insertions(+), 6 deletions(-) create mode 100644 app/schemas/com.f0x1d.logfox.database.AppDatabase/13.json diff --git a/app/schemas/com.f0x1d.logfox.database.AppDatabase/13.json b/app/schemas/com.f0x1d.logfox.database.AppDatabase/13.json new file mode 100644 index 00000000..651d2a8e --- /dev/null +++ b/app/schemas/com.f0x1d.logfox.database.AppDatabase/13.json @@ -0,0 +1,192 @@ +{ + "formatVersion": 1, + "database": { + "version": 13, + "identityHash": "af5c43f71282bbd112ac34b19baec49e", + "entities": [ + { + "tableName": "AppCrash", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`app_name` TEXT, `package_name` TEXT NOT NULL, `crash_type` INTEGER NOT NULL, `date_and_time` INTEGER NOT NULL, `log` TEXT NOT NULL, `log_dump_file` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "appName", + "columnName": "app_name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "packageName", + "columnName": "package_name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "crashType", + "columnName": "crash_type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "dateAndTime", + "columnName": "date_and_time", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "log", + "columnName": "log", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "logDumpFile", + "columnName": "log_dump_file", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_AppCrash_date_and_time", + "unique": false, + "columnNames": [ + "date_and_time" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_AppCrash_date_and_time` ON `${TABLE_NAME}` (`date_and_time`)" + } + ], + "foreignKeys": [] + }, + { + "tableName": "LogRecording", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `date_and_time` INTEGER NOT NULL, `file` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "dateAndTime", + "columnName": "date_and_time", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "file", + "columnName": "file", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "UserFilter", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`including` INTEGER NOT NULL, `allowed_levels` TEXT NOT NULL, `uid` TEXT, `pid` TEXT, `tid` TEXT, `package_name` TEXT, `tag` TEXT, `content` TEXT, `enabled` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "including", + "columnName": "including", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "allowedLevels", + "columnName": "allowed_levels", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "uid", + "columnName": "uid", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "pid", + "columnName": "pid", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "tid", + "columnName": "tid", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "packageName", + "columnName": "package_name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "tag", + "columnName": "tag", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "content", + "columnName": "content", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "enabled", + "columnName": "enabled", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'af5c43f71282bbd112ac34b19baec49e')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/database/AppDatabase.kt b/app/src/main/java/com/f0x1d/logfox/database/AppDatabase.kt index 142d295a..de8826d8 100644 --- a/app/src/main/java/com/f0x1d/logfox/database/AppDatabase.kt +++ b/app/src/main/java/com/f0x1d/logfox/database/AppDatabase.kt @@ -1,8 +1,11 @@ package com.f0x1d.logfox.database +import androidx.room.AutoMigration import androidx.room.Database +import androidx.room.DeleteColumn import androidx.room.RoomDatabase import androidx.room.TypeConverters +import androidx.room.migration.AutoMigrationSpec import androidx.room.migration.Migration import com.f0x1d.logfox.LogFoxApp import com.f0x1d.logfox.R @@ -15,7 +18,21 @@ import com.f0x1d.logfox.database.entity.LogRecordingDao import com.f0x1d.logfox.database.entity.UserFilter import com.f0x1d.logfox.database.entity.UserFilterDao -@Database(entities = [AppCrash::class, LogRecording::class, UserFilter::class], version = 12) +@Database( + entities = [ + AppCrash::class, + LogRecording::class, + UserFilter::class + ], + version = 13, + autoMigrations = [ + AutoMigration( + from = 12, + to = 13, + spec = AppDatabase.Companion.AutoMigration12_13::class + ) + ] +) @TypeConverters(CrashTypeConverter::class, AllowedLevelsConverter::class) abstract class AppDatabase: RoomDatabase() { @@ -54,6 +71,8 @@ abstract class AppDatabase: RoomDatabase() { val MIGRATION_11_12 = Migration(11, 12) { it.execSQL("CREATE INDEX index_AppCrash_date_and_time ON AppCrash(date_and_time)") } + @DeleteColumn(tableName = "AppCrash", columnName = "log_dump") + class AutoMigration12_13: AutoMigrationSpec } abstract fun appCrashDao(): AppCrashDao diff --git a/app/src/main/java/com/f0x1d/logfox/database/entity/AppCrash.kt b/app/src/main/java/com/f0x1d/logfox/database/entity/AppCrash.kt index 42dd3d24..5317524f 100644 --- a/app/src/main/java/com/f0x1d/logfox/database/entity/AppCrash.kt +++ b/app/src/main/java/com/f0x1d/logfox/database/entity/AppCrash.kt @@ -19,7 +19,6 @@ data class AppCrash( @ColumnInfo(name = "crash_type") val crashType: CrashType, @ColumnInfo(name = "date_and_time", index = true) val dateAndTime: Long, @ColumnInfo(name = "log") val log: String, - @Deprecated("Use logDumpFile") @ColumnInfo(name = "log_dump") val logDump: String? = null, @ColumnInfo(name = "log_dump_file") val logDumpFile: String? = null, @PrimaryKey(autoGenerate = true) val id: Long = 0 ) { diff --git a/app/src/main/java/com/f0x1d/logfox/viewmodel/crashes/CrashDetailsViewModel.kt b/app/src/main/java/com/f0x1d/logfox/viewmodel/crashes/CrashDetailsViewModel.kt index 87c0a3dd..20ca15b1 100644 --- a/app/src/main/java/com/f0x1d/logfox/viewmodel/crashes/CrashDetailsViewModel.kt +++ b/app/src/main/java/com/f0x1d/logfox/viewmodel/crashes/CrashDetailsViewModel.kt @@ -51,10 +51,6 @@ class CrashDetailsViewModel @Inject constructor( putZipEntry("crash.log", appCrash.log.encodeToByteArray()) - if (!appCrash.logDump.isNullOrEmpty()) putZipEntry( - "dump.log", - appCrash.logDump.encodeToByteArray() - ) if (appCrash.logDumpFile != null) putZipEntry( "dump.log", File(appCrash.logDumpFile)