From d765355397944a12eac56917275b6329ae4f01e5 Mon Sep 17 00:00:00 2001 From: Cris Barreiro Date: Wed, 26 Nov 2025 12:18:05 +0100 Subject: [PATCH] Migrate web-compat to DatabaseProvider --- web-compat/web-compat-impl/build.gradle | 1 + .../webcompat/impl/di/WebCompatModule.kt | 19 +++++++++++-------- .../webcompat/store/WebCompatDatabase.kt | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/web-compat/web-compat-impl/build.gradle b/web-compat/web-compat-impl/build.gradle index 9b04d6feaaaa..f723ec700388 100644 --- a/web-compat/web-compat-impl/build.gradle +++ b/web-compat/web-compat-impl/build.gradle @@ -40,6 +40,7 @@ dependencies { implementation project(path: ':web-compat-store') implementation project(path: ':content-scope-scripts-api') implementation project(path: ':js-messaging-api') + implementation project(path: ':data-store-api') // Room implementation AndroidX.room.runtime diff --git a/web-compat/web-compat-impl/src/main/java/com/duckduckgo/webcompat/impl/di/WebCompatModule.kt b/web-compat/web-compat-impl/src/main/java/com/duckduckgo/webcompat/impl/di/WebCompatModule.kt index bb8a12a1da68..166448fe8187 100644 --- a/web-compat/web-compat-impl/src/main/java/com/duckduckgo/webcompat/impl/di/WebCompatModule.kt +++ b/web-compat/web-compat-impl/src/main/java/com/duckduckgo/webcompat/impl/di/WebCompatModule.kt @@ -16,11 +16,11 @@ package com.duckduckgo.webcompat.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.webcompat.store.ALL_MIGRATIONS import com.duckduckgo.webcompat.store.RealWebCompatRepository @@ -38,12 +38,15 @@ object WebCompatModule { @SingleInstanceIn(AppScope::class) @Provides - fun provideWebCompatDatabase(context: Context): WebCompatDatabase { - return Room.databaseBuilder(context, WebCompatDatabase::class.java, "web_compat.db") - .enableMultiInstanceInvalidation() - .fallbackToDestructiveMigration() - .addMigrations(*ALL_MIGRATIONS) - .build() + fun provideWebCompatDatabase(databaseProvider: DatabaseProvider): WebCompatDatabase { + return databaseProvider.buildRoomDatabase( + WebCompatDatabase::class.java, + "web_compat.db", + config = RoomDatabaseConfig( + fallbackToDestructiveMigration = true, + migrations = ALL_MIGRATIONS, + ), + ) } @SingleInstanceIn(AppScope::class) diff --git a/web-compat/web-compat-store/src/main/java/com/duckduckgo/webcompat/store/WebCompatDatabase.kt b/web-compat/web-compat-store/src/main/java/com/duckduckgo/webcompat/store/WebCompatDatabase.kt index 29d081f7ae96..df5362289d6d 100644 --- a/web-compat/web-compat-store/src/main/java/com/duckduckgo/webcompat/store/WebCompatDatabase.kt +++ b/web-compat/web-compat-store/src/main/java/com/duckduckgo/webcompat/store/WebCompatDatabase.kt @@ -31,4 +31,4 @@ abstract class WebCompatDatabase : RoomDatabase() { abstract fun webCompatDao(): WebCompatDao } -val ALL_MIGRATIONS = emptyArray() +val ALL_MIGRATIONS = emptyList()