29 lines
878 B
Kotlin
29 lines
878 B
Kotlin
package com.example.shiftalarm
|
|
|
|
import android.content.Context
|
|
import androidx.room.*
|
|
|
|
@Database(entities = [ShiftOverride::class, DailyMemo::class, CustomAlarm::class], version = 3, exportSchema = false)
|
|
abstract class AppDatabase : RoomDatabase() {
|
|
abstract fun shiftDao(): ShiftDao
|
|
|
|
companion object {
|
|
@Volatile
|
|
private var INSTANCE: AppDatabase? = null
|
|
|
|
fun getDatabase(context: Context): AppDatabase {
|
|
return INSTANCE ?: synchronized(this) {
|
|
val instance = Room.databaseBuilder(
|
|
context.applicationContext,
|
|
AppDatabase::class.java,
|
|
"shift_database"
|
|
)
|
|
.fallbackToDestructiveMigration() // Simple for now
|
|
.build()
|
|
INSTANCE = instance
|
|
instance
|
|
}
|
|
}
|
|
}
|
|
}
|