feat: preserve infrared ownership in schema

This commit is contained in:
2026-08-26 19:49:39 +08:00
parent b537cd1824
commit 4798ae32ba
8 changed files with 35 additions and 2 deletions
@@ -10,7 +10,7 @@ import androidx.room.RoomDatabase
VirtualRemoteEntity::class,
RemoteKeyBindingEntity::class,
],
version = 2,
version = 3,
exportSchema = false,
)
abstract class InfraredDatabase : RoomDatabase() {
@@ -65,6 +65,11 @@ data class VirtualRemoteEntity(
indices = [
Index(value = ["remoteId"]),
Index(value = ["profileId"]),
Index(
value = ["profileId", "hardwareDeviceName", "assignedSlot"],
unique = true,
name = "index_remote_key_bindings_hardware_slot",
),
],
)
data class RemoteKeyBindingEntity(
@@ -72,6 +77,7 @@ data class RemoteKeyBindingEntity(
val id: String,
val remoteId: String,
val profileId: String,
val hardwareDeviceName: String,
val buttonId: String,
val displayName: String,
val assignedSlot: String?,
@@ -0,0 +1,20 @@
package com.flagship.abox.manager.infrared.data.local
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"ALTER TABLE remote_key_bindings ADD COLUMN hardwareDeviceName TEXT NOT NULL DEFAULT ''",
)
db.execSQL(
"UPDATE remote_key_bindings SET hardwareDeviceName = " +
"(SELECT deviceName FROM virtual_remotes WHERE virtual_remotes.id = remote_key_bindings.remoteId)",
)
db.execSQL(
"CREATE UNIQUE INDEX IF NOT EXISTS index_remote_key_bindings_hardware_slot " +
"ON remote_key_bindings(profileId, hardwareDeviceName, assignedSlot)",
)
}
}
@@ -206,6 +206,7 @@ private fun RemoteKeyBindingEntity.toDomain(): RemoteKeyBinding = RemoteKeyBindi
id = id,
remoteId = VirtualRemoteId(remoteId),
profileId = ProviderProfileId(profileId),
hardwareDeviceName = DeviceName(hardwareDeviceName),
buttonId = buttonId,
displayName = displayName,
assignedSlot = assignedSlot,
@@ -219,6 +220,7 @@ private fun RemoteKeyBinding.toEntity(): RemoteKeyBindingEntity = RemoteKeyBindi
id = id,
remoteId = remoteId.value,
profileId = profileId.value,
hardwareDeviceName = hardwareDeviceName.value,
buttonId = buttonId,
displayName = displayName,
assignedSlot = assignedSlot,
@@ -20,6 +20,7 @@ import com.flagship.abox.manager.infrared.data.local.InfraredDao
import com.flagship.abox.manager.infrared.data.local.InfraredDatabase
import com.flagship.abox.manager.infrared.data.local.RoomInfraredKeyRepository
import com.flagship.abox.manager.infrared.data.local.RoomVirtualRemoteRepository
import com.flagship.abox.manager.infrared.data.local.MIGRATION_2_3
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -49,7 +50,7 @@ object InfraredFeatureModule {
context,
InfraredDatabase::class.java,
"abox_infrared.db",
).fallbackToDestructiveMigration().build()
).addMigrations(MIGRATION_2_3).build()
}
@Provides