Skip to content

Commit

Permalink
Migrate from Sugar ORM to Room
Browse files Browse the repository at this point in the history
- table not altered so migration from db version 3 to 4 is simple
- bug fixes

Signed-off-by: Arka Prava Basu <[email protected]>
  • Loading branch information
archie94 committed Aug 28, 2018
1 parent a1454c7 commit 108f388
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/havenapp/main/database/HavenEventDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import android.content.Context
import org.havenapp.main.dao.EventDAO
import org.havenapp.main.dao.EventTriggerDAO
import org.havenapp.main.database.converter.HavenEventDBConverters
import org.havenapp.main.database.migration.RoomMigration
import org.havenapp.main.model.Event
import org.havenapp.main.model.EventTrigger

/**
* Created by Arka Prava Basu <[email protected]> on 23/5/18.
*/
@Database(entities = [(Event::class), (EventTrigger::class)], version = 3)
@Database(entities = [(Event::class), (EventTrigger::class)], version = 4)
@TypeConverters(HavenEventDBConverters::class)
abstract class HavenEventDB: RoomDatabase() {

Expand All @@ -34,6 +35,7 @@ abstract class HavenEventDB: RoomDatabase() {
INSTANCE = Room.databaseBuilder(context.applicationContext,
HavenEventDB::class.java, "haven.db")
.allowMainThreadQueries() // todo remove this
.addMigrations(RoomMigration())
.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.havenapp.main.database.migration

import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.room.migration.Migration

/**
* [Migration] for the transition from Sugar ORM (database version = 3)
* to Room database (database version = 4).
* <p>
* Created by Arka Prava Basu <[email protected]> on 28/8/18.
*/
class RoomMigration: Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
// Since we did not alter table, nothing to do here.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public synchronized void alert(int alertType, String path) {
mLastEvent.setId(eventId);
doNotification = true;
// set current event start date in prefs
mPrefs.setCurrentSession(mLastEvent.getStartTime());
mPrefs.setCurrentSession(mLastEvent.getMStartTime());
}
else if (mPrefs.getNotificationTimeMs() == 0)
{
Expand Down

0 comments on commit 108f388

Please sign in to comment.