Search code examples
androidkotlinandroid-roomdatabase-migration

When does room start applying migrations?


I have an android app which uses Room Persistence library to store data locally. I recently changed schema for my table, updated the database version and added necessary migrations to the database builder.

I am using Dagger Hilt to provide RoomDatabase instance to my ViewModels. I need to do some setup before room actually starts applying migrations.

So I was wondering when does Room start migrating database?

  • Is it when the Database instance is built?
  • Or when I call some Dao's function the first time.
  • Or at some other point?

Please help.


Solution

  • Whenever that Room database instance is built. Like when calling "Room.databaseBuilder" method. https://developer.android.com/training/data-storage/room/migrating-db-versions