@ -19,14 +19,14 @@ import io.legado.app.data.entities.*
version = 20 ,
version = 20 ,
exportSchema = true
exportSchema = true
)
)
abstract class AppDatabase : RoomDatabase ( ) {
abstract class AppDatabase : RoomDatabase ( ) {
companion object {
companion object {
private const val DATABASE _NAME = " legado.db "
private const val DATABASE _NAME = " legado.db "
fun createDatabase ( context : Context ) : AppDatabase {
fun createDatabase ( context : Context ) =
return Room . databaseBuilder ( context , AppDatabase :: class . java , DATABASE _NAME )
Room . databaseBuilder ( context , AppDatabase :: class . java , DATABASE _NAME )
. fallbackToDestructiveMigration ( )
. fallbackToDestructiveMigration ( )
. addMigrations (
. addMigrations (
migration _10 _11 ,
migration _10 _11 ,
@ -41,9 +41,8 @@ abstract class AppDatabase : RoomDatabase() {
)
)
. allowMainThreadQueries ( )
. allowMainThreadQueries ( )
. build ( )
. build ( )
}
private val migration _10 _11 = object : Migration ( 10 , 11 ) {
private val migration _10 _11 = object : Migration ( 10 , 11 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " DROP TABLE txtTocRules " )
database . execSQL ( " DROP TABLE txtTocRules " )
database . execSQL (
database . execSQL (
@ -55,20 +54,20 @@ abstract class AppDatabase : RoomDatabase() {
)
)
}
}
}
}
private val migration _11 _12 = object : Migration ( 11 , 12 ) {
private val migration _11 _12 = object : Migration ( 11 , 12 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " ALTER TABLE rssSources ADD style TEXT " )
database . execSQL ( " ALTER TABLE rssSources ADD style TEXT " )
}
}
}
}
private val migration _12 _13 = object : Migration ( 12 , 13 ) {
private val migration _12 _13 = object : Migration ( 12 , 13 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " ALTER TABLE rssSources ADD articleStyle INTEGER NOT NULL DEFAULT 0 " )
database . execSQL ( " ALTER TABLE rssSources ADD articleStyle INTEGER NOT NULL DEFAULT 0 " )
}
}
}
}
private val migration _13 _14 = object : Migration ( 13 , 14 ) {
private val migration _13 _14 = object : Migration ( 13 , 14 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL (
database . execSQL (
"""
"""
@ -86,26 +85,26 @@ abstract class AppDatabase : RoomDatabase() {
database . execSQL ( " ALTER TABLE books_new RENAME TO books " )
database . execSQL ( " ALTER TABLE books_new RENAME TO books " )
}
}
}
}
private val migration _14 _15 = object : Migration ( 14 , 15 ) {
private val migration _14 _15 = object : Migration ( 14 , 15 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " ALTER TABLE bookmarks ADD bookAuthor TEXT NOT NULL DEFAULT '' " )
database . execSQL ( " ALTER TABLE bookmarks ADD bookAuthor TEXT NOT NULL DEFAULT '' " )
}
}
}
}
private val migration _15 _17 = object : Migration ( 15 , 17 ) {
private val migration _15 _17 = object : Migration ( 15 , 17 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " CREATE TABLE IF NOT EXISTS `readRecord` (`bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, PRIMARY KEY(`bookName`)) " )
database . execSQL ( " CREATE TABLE IF NOT EXISTS `readRecord` (`bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, PRIMARY KEY(`bookName`)) " )
}
}
}
}
private val migration _17 _18 = object : Migration ( 17 , 18 ) {
private val migration _17 _18 = object : Migration ( 17 , 18 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " CREATE TABLE IF NOT EXISTS `httpTTS` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, PRIMARY KEY(`id`)) " )
database . execSQL ( " CREATE TABLE IF NOT EXISTS `httpTTS` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, PRIMARY KEY(`id`)) " )
}
}
}
}
private val migration _18 _19 = object : Migration ( 18 , 19 ) {
private val migration _18 _19 = object : Migration ( 18 , 19 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " CREATE TABLE IF NOT EXISTS `readRecordNew` (`androidId` TEXT NOT NULL, `bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, PRIMARY KEY(`androidId`, `bookName`)) " )
database . execSQL ( " CREATE TABLE IF NOT EXISTS `readRecordNew` (`androidId` TEXT NOT NULL, `bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, PRIMARY KEY(`androidId`, `bookName`)) " )
database . execSQL ( " INSERT INTO readRecordNew(androidId, bookName, readTime) select ' ${App.androidId} ' as androidId, bookName, readTime from readRecord " )
database . execSQL ( " INSERT INTO readRecordNew(androidId, bookName, readTime) select ' ${App.androidId} ' as androidId, bookName, readTime from readRecord " )
@ -113,13 +112,13 @@ abstract class AppDatabase : RoomDatabase() {
database . execSQL ( " ALTER TABLE readRecordNew RENAME TO readRecord " )
database . execSQL ( " ALTER TABLE readRecordNew RENAME TO readRecord " )
}
}
}
}
private val migration _19 _20 = object : Migration ( 19 , 20 ) {
private val migration _19 _20 = object : Migration ( 19 , 20 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " ALTER TABLE book_sources ADD bookSourceComment TEXT " )
database . execSQL ( " ALTER TABLE book_sources ADD bookSourceComment TEXT " )
}
}
}
}
}
}
abstract fun bookDao ( ) : BookDao
abstract fun bookDao ( ) : BookDao
abstract fun bookGroupDao ( ) : BookGroupDao
abstract fun bookGroupDao ( ) : BookGroupDao
abstract fun bookSourceDao ( ) : BookSourceDao
abstract fun bookSourceDao ( ) : BookSourceDao