provideRoomDatabase
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:
Remove
.fallbackToDestructiveMigration(true)Add explicit migrations with
.addMigrations(MIGRATION_X_Y)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")
}
}Content copied to clipboard
Return
The singleton JetpackDatabase instance
Parameters
appContext
The application context for database creation