provideRoomDatabase

@Singleton
@Provides
fun provideRoomDatabase(appContext: Context): JetpackDatabase

Provides the singleton Room database instance.

This database:

  • Is created once and shared across the entire application

  • Uses destructive migration (development-only - see class KDoc)

  • Lives in the app's private storage directory

  • Is automatically closed when the app is killed

Development Configuration

  • Destructive Migration Enabled: Schema changes delete and recreate the database

  • Safe for Development: Firebase sync allows data to be re-fetched

Production Configuration Required

Before production release:

  1. Remove .fallbackToDestructiveMigration(true)

  2. Add explicit migrations with .addMigrations(MIGRATION_X_Y)

  3. Test migrations thoroughly with MigrationTestHelper

Example Migration (for production)

val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE jetpack ADD COLUMN is_favorite INTEGER NOT NULL DEFAULT 0")
}
}

Return

The singleton JetpackDatabase instance

Parameters

appContext

The application context for database creation