From 99a8df545e4e5aa32cf27c3a0702fe3fc5a900f7 Mon Sep 17 00:00:00 2001 From: Cris Barreiro Date: Tue, 25 Nov 2025 16:57:39 +0100 Subject: [PATCH] Migrate element-hiding to DatabaseProvicer --- .../element-hiding-impl/build.gradle | 1 + .../impl/di/ElementHidingModule.kt | 20 +++++++++++-------- .../store/ElementHidingDatabase.kt | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/element-hiding/element-hiding-impl/build.gradle b/element-hiding/element-hiding-impl/build.gradle index ac9f5ec537a1..ac6e3842a40f 100644 --- a/element-hiding/element-hiding-impl/build.gradle +++ b/element-hiding/element-hiding-impl/build.gradle @@ -39,6 +39,7 @@ dependencies { implementation project(path: ':app-build-config-api') implementation project(path: ':element-hiding-store') implementation project(path: ':content-scope-scripts-api') + implementation project(path: ':data-store-api') implementation AndroidX.core.ktx diff --git a/element-hiding/element-hiding-impl/src/main/java/com/duckduckgo/elementhiding/impl/di/ElementHidingModule.kt b/element-hiding/element-hiding-impl/src/main/java/com/duckduckgo/elementhiding/impl/di/ElementHidingModule.kt index ad58c04198fc..5a5c151016ab 100644 --- a/element-hiding/element-hiding-impl/src/main/java/com/duckduckgo/elementhiding/impl/di/ElementHidingModule.kt +++ b/element-hiding/element-hiding-impl/src/main/java/com/duckduckgo/elementhiding/impl/di/ElementHidingModule.kt @@ -16,11 +16,11 @@ package com.duckduckgo.elementhiding.impl.di -import android.content.Context -import androidx.room.Room import com.duckduckgo.app.di.AppCoroutineScope import com.duckduckgo.app.di.IsMainProcess import com.duckduckgo.common.utils.DispatcherProvider +import com.duckduckgo.data.store.api.DatabaseProvider +import com.duckduckgo.data.store.api.RoomDatabaseConfig import com.duckduckgo.di.scopes.AppScope import com.duckduckgo.elementhiding.store.ALL_MIGRATIONS import com.duckduckgo.elementhiding.store.ElementHidingDatabase @@ -38,12 +38,16 @@ object ElementHidingModule { @SingleInstanceIn(AppScope::class) @Provides - fun provideElementHidingDatabase(context: Context): ElementHidingDatabase { - return Room.databaseBuilder(context, ElementHidingDatabase::class.java, "element_hiding.db") - .enableMultiInstanceInvalidation() - .fallbackToDestructiveMigration() - .addMigrations(*ALL_MIGRATIONS) - .build() + fun provideElementHidingDatabase(databaseProvider: DatabaseProvider): ElementHidingDatabase { + return databaseProvider.buildRoomDatabase( + ElementHidingDatabase::class.java, + "element_hiding.db", + config = RoomDatabaseConfig( + fallbackToDestructiveMigration = true, + enableMultiInstanceInvalidation = true, + migrations = ALL_MIGRATIONS, + ), + ) } @SingleInstanceIn(AppScope::class) diff --git a/element-hiding/element-hiding-store/src/main/java/com/duckduckgo/elementhiding/store/ElementHidingDatabase.kt b/element-hiding/element-hiding-store/src/main/java/com/duckduckgo/elementhiding/store/ElementHidingDatabase.kt index e204e0cf42c7..c57718c7cc98 100644 --- a/element-hiding/element-hiding-store/src/main/java/com/duckduckgo/elementhiding/store/ElementHidingDatabase.kt +++ b/element-hiding/element-hiding-store/src/main/java/com/duckduckgo/elementhiding/store/ElementHidingDatabase.kt @@ -31,4 +31,4 @@ abstract class ElementHidingDatabase : RoomDatabase() { abstract fun elementHidingDao(): ElementHidingDao } -val ALL_MIGRATIONS = emptyArray() +val ALL_MIGRATIONS = emptyList()