|
|
|
@ -11,21 +11,23 @@ import io.legado.app.help.storage.Restore |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Database( |
|
|
|
|
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, |
|
|
|
|
SearchBook::class, SearchKeyword::class, Cookie::class, RssSource::class, Bookmark::class, |
|
|
|
|
RssArticle::class], |
|
|
|
|
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, |
|
|
|
|
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, |
|
|
|
|
RssSource::class, Bookmark::class, RssArticle::class], |
|
|
|
|
version = 3, |
|
|
|
|
exportSchema = true |
|
|
|
|
) |
|
|
|
|
abstract class AppDatabase : RoomDatabase() { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
var DestructiveMigration = false |
|
|
|
|
private const val DATABASE_NAME = "legado.db" |
|
|
|
|
fun createDatabase(context: Context): AppDatabase { |
|
|
|
|
return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME) |
|
|
|
|
.fallbackToDestructiveMigration() |
|
|
|
|
.addCallback(object : Callback() { |
|
|
|
|
override fun onDestructiveMigration(db: SupportSQLiteDatabase) { |
|
|
|
|
DestructiveMigration = true |
|
|
|
|
Restore.restore() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|