@ -19,14 +19,14 @@ import io.legado.app.data.entities.*
version = 20 ,
exportSchema = true
)
abstract class AppDatabase : RoomDatabase ( ) {
abstract class AppDatabase : RoomDatabase ( ) {
companion object {
private const val DATABASE _NAME = " legado.db "
fun createDatabase ( context : Context ) : AppDatabase {
return Room . databaseBuilder ( context , AppDatabase :: class . java , DATABASE _NAME )
fun createDatabase ( context : Context ) =
Room . databaseBuilder ( context , AppDatabase :: class . java , DATABASE _NAME )
. fallbackToDestructiveMigration ( )
. addMigrations (
migration _10 _11 ,
@ -41,9 +41,8 @@ abstract class AppDatabase : RoomDatabase() {
)
. allowMainThreadQueries ( )
. build ( )
}
private val migration _10 _11 = object : Migration ( 10 , 11 ) {
private val migration _10 _11 = object : Migration ( 10 , 11 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
database . execSQL ( " DROP TABLE txtTocRules " )
database . execSQL (
@ -56,19 +55,19 @@ 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 ) {
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 ) {
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 ) {
database . execSQL (
"""
@ -87,25 +86,25 @@ abstract class AppDatabase : RoomDatabase() {
}
}
private val migration _14 _15 = object : Migration ( 14 , 15 ) {
private val migration _14 _15 = object : Migration ( 14 , 15 ) {
override fun migrate ( database : SupportSQLiteDatabase ) {
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 ) {
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 ) {
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 ) {
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 " )
@ -113,7 +112,7 @@ abstract class AppDatabase : RoomDatabase() {
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 ) {
database . execSQL ( " ALTER TABLE book_sources ADD bookSourceComment TEXT " )
}