From 3a9b4751be5d24b7159fdac89be7874f498b5933 Mon Sep 17 00:00:00 2001 From: Cris Barreiro Date: Wed, 26 Nov 2025 09:54:59 +0100 Subject: [PATCH] Migrate history to DatabaseProvider --- history/history-impl/build.gradle | 1 + .../duckduckgo/history/impl/HistoryModule.kt | 17 +++++++++++------ .../history/impl/store/HistoryDatabase.kt | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/history/history-impl/build.gradle b/history/history-impl/build.gradle index 7c7fb27c1f77..4edcac0251e8 100644 --- a/history/history-impl/build.gradle +++ b/history/history-impl/build.gradle @@ -33,6 +33,7 @@ dependencies { implementation project(path: ':common-utils') implementation project(path: ':browser-api') + implementation project(path: ':data-store-api') implementation project(path: ':feature-toggles-api') implementation project(path: ':privacy-config-api') implementation project(path: ':app-build-config-api') diff --git a/history/history-impl/src/main/java/com/duckduckgo/history/impl/HistoryModule.kt b/history/history-impl/src/main/java/com/duckduckgo/history/impl/HistoryModule.kt index 20037baa407e..b796f91ed685 100644 --- a/history/history-impl/src/main/java/com/duckduckgo/history/impl/HistoryModule.kt +++ b/history/history-impl/src/main/java/com/duckduckgo/history/impl/HistoryModule.kt @@ -17,9 +17,10 @@ package com.duckduckgo.history.impl import android.content.Context -import androidx.room.Room import com.duckduckgo.app.di.AppCoroutineScope 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.history.impl.store.ALL_MIGRATIONS import com.duckduckgo.history.impl.store.HistoryDataStore @@ -48,11 +49,15 @@ class HistoryModule { @SingleInstanceIn(AppScope::class) @Provides - fun provideDatabase(context: Context): HistoryDatabase { - return Room.databaseBuilder(context, HistoryDatabase::class.java, "history.db") - .fallbackToDestructiveMigration() - .addMigrations(*ALL_MIGRATIONS) - .build() + fun provideDatabase(databaseProvider: DatabaseProvider): HistoryDatabase { + return databaseProvider.buildRoomDatabase( + HistoryDatabase::class.java, + "history.db", + config = RoomDatabaseConfig( + fallbackToDestructiveMigration = true, + migrations = ALL_MIGRATIONS, + ), + ) } @SingleInstanceIn(AppScope::class) diff --git a/history/history-impl/src/main/java/com/duckduckgo/history/impl/store/HistoryDatabase.kt b/history/history-impl/src/main/java/com/duckduckgo/history/impl/store/HistoryDatabase.kt index a97b12123948..19c149c1eee0 100644 --- a/history/history-impl/src/main/java/com/duckduckgo/history/impl/store/HistoryDatabase.kt +++ b/history/history-impl/src/main/java/com/duckduckgo/history/impl/store/HistoryDatabase.kt @@ -32,4 +32,4 @@ abstract class HistoryDatabase : RoomDatabase() { abstract fun historyDao(): HistoryDao } -val ALL_MIGRATIONS = emptyArray() +val ALL_MIGRATIONS = emptyList()