Skip to content

Commit 8e4d8d2

Browse files
committed
- Refactor Embedding Model Download to use WorkManager
- Move LLM service binding to MainActivity to comply with Android 14+ requirements. - Remove the explicit embedding model setup screen, initiating the download in the background instead. - Update the RAG creation screen to check for and notify the user about the ongoing download status. - Add a database migration to include new fields in the `installed_rags` table.
1 parent 3d3d33c commit 8e4d8d2

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

app/src/main/java/com/dark/tool_neuron/database/AppDatabase.kt

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import com.dark.tool_neuron.models.table_schema.ModelConfig
1717

1818
@Database(
1919
entities = [Model::class, ModelConfig::class, InstalledRag::class],
20-
version = 3,
20+
version = 4,
2121
exportSchema = false
2222
)
2323
@TypeConverters(Converters::class)
@@ -67,14 +67,61 @@ abstract class AppDatabase : RoomDatabase() {
6767
}
6868
}
6969

70+
private val MIGRATION_3_4 = object : Migration(3, 4) {
71+
override fun migrate(db: SupportSQLiteDatabase) {
72+
// Recreate installed_rags table without DEFAULT constraints in SQL
73+
// Room expects defaults to be handled at the application level, not database level
74+
75+
// Create new table with correct schema (no DEFAULT clauses)
76+
db.execSQL("""
77+
CREATE TABLE IF NOT EXISTS installed_rags_new (
78+
id TEXT PRIMARY KEY NOT NULL,
79+
name TEXT NOT NULL,
80+
description TEXT NOT NULL,
81+
source_type TEXT NOT NULL,
82+
file_path TEXT,
83+
node_count INTEGER NOT NULL,
84+
embedding_dimension INTEGER NOT NULL,
85+
embedding_model TEXT NOT NULL,
86+
domain TEXT NOT NULL,
87+
language TEXT NOT NULL,
88+
version TEXT NOT NULL,
89+
tags TEXT NOT NULL,
90+
status TEXT NOT NULL,
91+
is_enabled INTEGER NOT NULL,
92+
created_at INTEGER NOT NULL,
93+
updated_at INTEGER NOT NULL,
94+
last_loaded_at INTEGER,
95+
size_bytes INTEGER NOT NULL,
96+
metadata_json TEXT,
97+
is_encrypted INTEGER NOT NULL,
98+
loading_mode INTEGER NOT NULL,
99+
has_admin_access INTEGER NOT NULL
100+
)
101+
""".trimIndent())
102+
103+
// Copy data from old table to new table
104+
db.execSQL("""
105+
INSERT INTO installed_rags_new
106+
SELECT * FROM installed_rags
107+
""".trimIndent())
108+
109+
// Drop old table
110+
db.execSQL("DROP TABLE installed_rags")
111+
112+
// Rename new table to original name
113+
db.execSQL("ALTER TABLE installed_rags_new RENAME TO installed_rags")
114+
}
115+
}
116+
70117
fun getDatabase(context: Context): AppDatabase {
71118
return INSTANCE ?: synchronized(this) {
72119
val instance = Room.databaseBuilder(
73120
context.applicationContext,
74121
AppDatabase::class.java,
75122
"llm_models_database"
76123
)
77-
.addMigrations(MIGRATION_1_2, MIGRATION_2_3)
124+
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4)
78125
.fallbackToDestructiveMigration()
79126
.build()
80127
INSTANCE = instance

0 commit comments

Comments
 (0)