Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.1.0/AN-FEAT] 룸 엔티티 수정 대응(destructive-recreation) #355

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallbackToDestructiveMigration()를 사용하는 방식은, 파괴적 마이그레이션.
기존 데이터베이스를 제거하고 새로 생성하는 방법입니당.
이 방식은 기본적으로 앱의 데이터베이스 스키마가 변경되면, 데이터베이스를 삭제하고 새롭게 생성하는 방식입니다~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db의 버전만 바꿔주면 기존에 있던 데이터베이스를 삭제하고 새롭게 생성하는건가유??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔티티가 변경되었을 때만 기존 DB 를 삭제하고 새로 생성합니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 신기하네요! 근데 scheme 바뀌면 version 을 매번 올려줘야하는건 동일할까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 scheme 바뀌면 version 을 매번 올려줘야하는건 동일할까요?

네 맞아요~

.build().also { instance = it }
}
}

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