forked from github/wulkanowy-mirror
Clear Semesters table (#535)
This commit is contained in:

committed by
Rafał Borcz

parent
f9474af39e
commit
5b0901e311
@ -6,6 +6,7 @@ import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.RoomDatabase.JournalMode.TRUNCATE
|
||||
import androidx.room.TypeConverters
|
||||
import androidx.room.migration.Migration
|
||||
import io.github.wulkanowy.data.db.dao.AttendanceDao
|
||||
import io.github.wulkanowy.data.db.dao.AttendanceSummaryDao
|
||||
import io.github.wulkanowy.data.db.dao.CompletedLessonsDao
|
||||
@ -97,29 +98,33 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
companion object {
|
||||
const val VERSION_SCHEMA = 17
|
||||
|
||||
fun getMigrations(): Array<Migration> {
|
||||
return arrayOf(
|
||||
Migration2(),
|
||||
Migration3(),
|
||||
Migration4(),
|
||||
Migration5(),
|
||||
Migration6(),
|
||||
Migration7(),
|
||||
Migration8(),
|
||||
Migration9(),
|
||||
Migration10(),
|
||||
Migration11(),
|
||||
Migration12(),
|
||||
Migration13(),
|
||||
Migration14(),
|
||||
Migration15(),
|
||||
Migration16(),
|
||||
Migration17()
|
||||
)
|
||||
}
|
||||
|
||||
fun newInstance(context: Context): AppDatabase {
|
||||
return Room.databaseBuilder(context, AppDatabase::class.java, "wulkanowy_database")
|
||||
.setJournalMode(TRUNCATE)
|
||||
.fallbackToDestructiveMigrationFrom(VERSION_SCHEMA + 1)
|
||||
.fallbackToDestructiveMigrationOnDowngrade()
|
||||
.addMigrations(
|
||||
Migration2(),
|
||||
Migration3(),
|
||||
Migration4(),
|
||||
Migration5(),
|
||||
Migration6(),
|
||||
Migration7(),
|
||||
Migration8(),
|
||||
Migration9(),
|
||||
Migration10(),
|
||||
Migration11(),
|
||||
Migration12(),
|
||||
Migration13(),
|
||||
Migration14(),
|
||||
Migration15(),
|
||||
Migration16(),
|
||||
Migration17()
|
||||
)
|
||||
.addMigrations(*getMigrations())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,11 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
class Migration17 : Migration(16, 17) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
createGradesPointsStatisticsTable(database)
|
||||
truncateSemestersTable(database)
|
||||
}
|
||||
|
||||
private fun createGradesPointsStatisticsTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
CREATE TABLE IF NOT EXISTS GradesPointsStatistics(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
@ -17,4 +22,8 @@ class Migration17 : Migration(16, 17) {
|
||||
)
|
||||
""")
|
||||
}
|
||||
|
||||
private fun truncateSemestersTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM Semesters")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user