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:
OxygenCobalt 2021-04-03 11:08:27 -06:00
parent 0305eb0beb
commit eb56068f80
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 11 additions and 7 deletions

View file

@ -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

View file

@ -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)
}
/**

View file

@ -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."
}
}

View file

@ -30,6 +30,10 @@ class PlaybackStateDatabase(context: Context) :
}
}
override fun onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
onUpgrade(db, newVersion, oldVersion)
}
// --- DATABASE CONSTRUCTION FUNCTIONS ---
/**