Fix database issues
Fix some problems where PlaybackStateDatabase wouldn't downgrade [Problem when hopping between dev builds with db changes] and with assertBackgroundThread being public.
This commit is contained in:
parent
0305eb0beb
commit
eb56068f80
4 changed files with 11 additions and 7 deletions
|
@ -9,8 +9,8 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "org.oxycblt.auxio"
|
||||
versionName "1.4.0"
|
||||
versionCode 6
|
||||
versionName "1.3.3"
|
||||
versionCode 5
|
||||
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
|
|
|
@ -24,8 +24,7 @@ class BlacklistDatabase(context: Context) : SQLiteOpenHelper(context, DB_NAME, n
|
|||
}
|
||||
|
||||
override fun onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("DROP TABLE IF EXISTS $TABLE_NAME")
|
||||
onCreate(db)
|
||||
onUpgrade(db, newVersion, oldVersion)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.oxycblt.auxio.database
|
|||
|
||||
import android.database.Cursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import android.os.Looper
|
||||
|
||||
/**
|
||||
|
@ -14,8 +15,8 @@ fun <R> SQLiteDatabase.queryAll(tableName: String, block: (Cursor) -> R) =
|
|||
/**
|
||||
* Assert that we are on a background thread.
|
||||
*/
|
||||
fun assertBackgroundThread() {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
error("Not on a background thread.")
|
||||
fun SQLiteOpenHelper.assertBackgroundThread() {
|
||||
check(Looper.myLooper() != Looper.getMainLooper()) {
|
||||
"Database operations must be ran on a background thread."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ class PlaybackStateDatabase(context: Context) :
|
|||
}
|
||||
}
|
||||
|
||||
override fun onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
onUpgrade(db, newVersion, oldVersion)
|
||||
}
|
||||
|
||||
// --- DATABASE CONSTRUCTION FUNCTIONS ---
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue