feat(db): migrate to androidx.room3 3.0.2 with SQLCipherDriver (#994)

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-08-27 13:47:32 +03:00
1 parent 680b4082ca
commit 4d9dfb99db
6 files changed
+153 -77

No files matched your search

@@ -0,0 +1,73 @@
package com.m57.hermescontrol.data.local
import androidx.sqlite.SQLiteConnection
import androidx.sqlite.execSQL
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
class HermesDatabaseMigrationsTest {
@Before
fun setUp() {
mockkStatic("androidx.sqlite.SQLite")
}
@After
fun tearDown() {
unmockkStatic("androidx.sqlite.SQLite")
}
@Test
fun migration2to3_executesIndexCreationOnSQLiteConnection() =
runBlocking {
val connection = mockk<SQLiteConnection>(relaxed = true)
HermesDatabase.MIGRATION_2_3.migrate(connection)
verify(exactly = 1) {
connection.execSQL(
"CREATE INDEX IF NOT EXISTS `index_chat_messages_session_id_timestamp` " +
"ON `chat_messages` (`session_id`, `timestamp`)",
)
}
}
@Test
fun migration3to4_executesReasoningColumnAdditionOnSQLiteConnection() =
runBlocking {
val connection = mockk<SQLiteConnection>(relaxed = true)
HermesDatabase.MIGRATION_3_4.migrate(connection)
verify(exactly = 1) {
connection.execSQL(
"ALTER TABLE `chat_messages` ADD COLUMN `reasoning_text` TEXT NOT NULL DEFAULT ''",
)
}
}
@Test
fun migration4to5_executesToolCallIdColumnAdditionOnSQLiteConnection() =
runBlocking {
val connection = mockk<SQLiteConnection>(relaxed = true)
HermesDatabase.MIGRATION_4_5.migrate(connection)
verify(exactly = 1) {
connection.execSQL(
"ALTER TABLE `chat_messages` ADD COLUMN `tool_call_id` TEXT NOT NULL DEFAULT ''",
)
}
}
@Test
fun migration5to6_executesDisplayKindColumnAdditionOnSQLiteConnection() =
runBlocking {
val connection = mockk<SQLiteConnection>(relaxed = true)
HermesDatabase.MIGRATION_5_6.migrate(connection)
verify(exactly = 1) {
connection.execSQL(
"ALTER TABLE `chat_messages` ADD COLUMN `display_kind` TEXT",
)
}
}
}