feat: add database indices and testing

This commit is contained in:
2026-06-08 15:01:06 +02:00
parent 2574a6e1e6
commit a232d4bfde
11 changed files with 289 additions and 7 deletions
+2
View File
@@ -10,6 +10,8 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.nfc" android:required="false" />
@@ -14,7 +14,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
LnurlCacheEntity::class,
NodeAliasCacheEntity::class,
],
version = 5, // ← bumped
version = 6,
exportSchema = false
)
@TypeConverters(PaymentConverters::class)
@@ -70,13 +70,22 @@ abstract class AppDatabase : RoomDatabase() {
}
}
val MIGRATION_4_5 = object : Migration(4, 5) {
private val MIGRATION_4_5 = object : Migration(4, 5) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE payment_records ADD COLUMN pubkey TEXT")
db.execSQL("ALTER TABLE payment_records ADD COLUMN alias TEXT")
}
}
private val MIGRATION_5_6 = object : Migration(5, 6) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("CREATE INDEX IF NOT EXISTS `index_payment_record_status` ON `payment_records` (`status`)")
db.execSQL("CREATE INDEX IF NOT EXISTS `index_payment_record_created_at` ON `payment_records` (`createdAt`)")
db.execSQL("CREATE INDEX IF NOT EXISTS `index_payment_record_amount_msat` ON `payment_records` (`amountMsat`)")
db.execSQL("CREATE INDEX IF NOT EXISTS `index_payment_record_status_created_at` ON `payment_records` (`status`, `createdAt`)")
}
}
fun getInstance(context: Context): AppDatabase =
INSTANCE ?: synchronized(this) {
INSTANCE ?: Room.databaseBuilder(
@@ -84,7 +93,7 @@ abstract class AppDatabase : RoomDatabase() {
AppDatabase::class.java,
"gudari_wallet.db"
)
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4) // ← added
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6)
.build()
.also { INSTANCE = it }
}
@@ -2,10 +2,19 @@ package com.bitcointxoko.gudariwallet.data.db
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
@Entity(tableName = "payment_records")
@Entity(
tableName = "payment_records",
indices = [
Index(value = ["status"]), // WHERE status LIKE ?
Index(value = ["createdAt"]), // WHERE created_at BETWEEN ? AND ?
Index(value = ["amountMsat"]), // WHERE amount_msat BETWEEN ? AND ?
Index(value = ["status", "createdAt"]) // composite: common combined filter
]
)
@TypeConverters(PaymentConverters::class)
data class PaymentRecordEntity(
@PrimaryKey