Skip to content

Commit

Permalink
feat: 룸 엔티티의 스키마가 바뀌었을 때만 감지해서 DB 재생성 (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
sh1mj1 authored Oct 14, 2024
1 parent 61aa1a4 commit bdb9600
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface PokemonDao {

companion object {
fun instance(context: Context): PokemonDao {
PokeRogueDatabase.dropDatabase(context)
return PokeRogueDatabase.instance(context).pokemonDao()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import poke.rogue.helper.local.entity.PokemonEntity

@Database(
entities = [PokemonEntity::class],
version = 1,
version = 2,
)
@androidx.room.TypeConverters(PokemonTypeConverters::class)
abstract class PokeRogueDatabase : RoomDatabase() {
Expand All @@ -28,15 +28,10 @@ abstract class PokeRogueDatabase : RoomDatabase() {
context,
PokeRogueDatabase::class.java,
DATABASE_NAME,
).build().also { instance = it }
)
.fallbackToDestructiveMigration()
.build().also { instance = it }
}
}

fun dropDatabase(context: Context) =
synchronized(this) {
instance?.close()
instance = null
context.deleteDatabase(DATABASE_NAME)
}
}
}

0 comments on commit bdb9600

Please sign in to comment.