feat: preserve infrared ownership in schema
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ import androidx.room.RoomDatabase
|
|||||||
VirtualRemoteEntity::class,
|
VirtualRemoteEntity::class,
|
||||||
RemoteKeyBindingEntity::class,
|
RemoteKeyBindingEntity::class,
|
||||||
],
|
],
|
||||||
version = 2,
|
version = 3,
|
||||||
exportSchema = false,
|
exportSchema = false,
|
||||||
)
|
)
|
||||||
abstract class InfraredDatabase : RoomDatabase() {
|
abstract class InfraredDatabase : RoomDatabase() {
|
||||||
|
|||||||
+6
@@ -65,6 +65,11 @@ data class VirtualRemoteEntity(
|
|||||||
indices = [
|
indices = [
|
||||||
Index(value = ["remoteId"]),
|
Index(value = ["remoteId"]),
|
||||||
Index(value = ["profileId"]),
|
Index(value = ["profileId"]),
|
||||||
|
Index(
|
||||||
|
value = ["profileId", "hardwareDeviceName", "assignedSlot"],
|
||||||
|
unique = true,
|
||||||
|
name = "index_remote_key_bindings_hardware_slot",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
data class RemoteKeyBindingEntity(
|
data class RemoteKeyBindingEntity(
|
||||||
@@ -72,6 +77,7 @@ data class RemoteKeyBindingEntity(
|
|||||||
val id: String,
|
val id: String,
|
||||||
val remoteId: String,
|
val remoteId: String,
|
||||||
val profileId: String,
|
val profileId: String,
|
||||||
|
val hardwareDeviceName: String,
|
||||||
val buttonId: String,
|
val buttonId: String,
|
||||||
val displayName: String,
|
val displayName: String,
|
||||||
val assignedSlot: String?,
|
val assignedSlot: String?,
|
||||||
|
|||||||
+20
@@ -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)",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -206,6 +206,7 @@ private fun RemoteKeyBindingEntity.toDomain(): RemoteKeyBinding = RemoteKeyBindi
|
|||||||
id = id,
|
id = id,
|
||||||
remoteId = VirtualRemoteId(remoteId),
|
remoteId = VirtualRemoteId(remoteId),
|
||||||
profileId = ProviderProfileId(profileId),
|
profileId = ProviderProfileId(profileId),
|
||||||
|
hardwareDeviceName = DeviceName(hardwareDeviceName),
|
||||||
buttonId = buttonId,
|
buttonId = buttonId,
|
||||||
displayName = displayName,
|
displayName = displayName,
|
||||||
assignedSlot = assignedSlot,
|
assignedSlot = assignedSlot,
|
||||||
@@ -219,6 +220,7 @@ private fun RemoteKeyBinding.toEntity(): RemoteKeyBindingEntity = RemoteKeyBindi
|
|||||||
id = id,
|
id = id,
|
||||||
remoteId = remoteId.value,
|
remoteId = remoteId.value,
|
||||||
profileId = profileId.value,
|
profileId = profileId.value,
|
||||||
|
hardwareDeviceName = hardwareDeviceName.value,
|
||||||
buttonId = buttonId,
|
buttonId = buttonId,
|
||||||
displayName = displayName,
|
displayName = displayName,
|
||||||
assignedSlot = assignedSlot,
|
assignedSlot = assignedSlot,
|
||||||
|
|||||||
+2
-1
@@ -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.InfraredDatabase
|
||||||
import com.flagship.abox.manager.infrared.data.local.RoomInfraredKeyRepository
|
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.RoomVirtualRemoteRepository
|
||||||
|
import com.flagship.abox.manager.infrared.data.local.MIGRATION_2_3
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -49,7 +50,7 @@ object InfraredFeatureModule {
|
|||||||
context,
|
context,
|
||||||
InfraredDatabase::class.java,
|
InfraredDatabase::class.java,
|
||||||
"abox_infrared.db",
|
"abox_infrared.db",
|
||||||
).fallbackToDestructiveMigration().build()
|
).addMigrations(MIGRATION_2_3).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
+1
@@ -39,6 +39,7 @@ class AddVirtualRemoteKey(
|
|||||||
id = UUID.randomUUID().toString(),
|
id = UUID.randomUUID().toString(),
|
||||||
remoteId = remoteId,
|
remoteId = remoteId,
|
||||||
profileId = profileId,
|
profileId = profileId,
|
||||||
|
hardwareDeviceName = remote.deviceName,
|
||||||
buttonId = buttonId,
|
buttonId = buttonId,
|
||||||
displayName = trimmed,
|
displayName = trimmed,
|
||||||
assignedSlot = assignedSlot,
|
assignedSlot = assignedSlot,
|
||||||
|
|||||||
+2
@@ -64,6 +64,7 @@ class CreateVirtualRemote(
|
|||||||
id = UUID.randomUUID().toString(),
|
id = UUID.randomUUID().toString(),
|
||||||
remoteId = remoteId,
|
remoteId = remoteId,
|
||||||
profileId = profileId,
|
profileId = profileId,
|
||||||
|
hardwareDeviceName = deviceName,
|
||||||
buttonId = template.buttonId,
|
buttonId = template.buttonId,
|
||||||
displayName = template.displayName,
|
displayName = template.displayName,
|
||||||
assignedSlot = (index + 1).toString(),
|
assignedSlot = (index + 1).toString(),
|
||||||
@@ -77,6 +78,7 @@ class CreateVirtualRemote(
|
|||||||
id = UUID.randomUUID().toString(),
|
id = UUID.randomUUID().toString(),
|
||||||
remoteId = remoteId,
|
remoteId = remoteId,
|
||||||
profileId = profileId,
|
profileId = profileId,
|
||||||
|
hardwareDeviceName = deviceName,
|
||||||
buttonId = template.buttonId,
|
buttonId = template.buttonId,
|
||||||
displayName = template.displayName,
|
displayName = template.displayName,
|
||||||
assignedSlot = null,
|
assignedSlot = null,
|
||||||
|
|||||||
+1
@@ -80,6 +80,7 @@ data class RemoteKeyBinding(
|
|||||||
val id: String,
|
val id: String,
|
||||||
val remoteId: VirtualRemoteId,
|
val remoteId: VirtualRemoteId,
|
||||||
val profileId: ProviderProfileId,
|
val profileId: ProviderProfileId,
|
||||||
|
val hardwareDeviceName: DeviceName = DeviceName(""),
|
||||||
val buttonId: String,
|
val buttonId: String,
|
||||||
val displayName: String,
|
val displayName: String,
|
||||||
val assignedSlot: String? = null,
|
val assignedSlot: String? = null,
|
||||||
|
|||||||
Reference in New Issue
Block a user