Coding Challenge: Manual Room Migration

Test your understanding of manual Room migrations with a coding challenge.

Problem definition

We learned about manual data migrations in the "Handling Room Database Migrations" lesson. Let’s apply what we learned to add a new city field in the User entity and use it for read and write operations.

Instructions to follow:

  1. Add the city field in the User entity by updating the User.kt file.

  2. Add a manual migration script to the MyDatabase class by updating the MyDatabase.kt file.

  3. Similar to other fields, add an EditText to let the user enter the city and a TextView to display it in the activity_main.xml file.

  4. Update the writeTestData method in the MainActivity.kt to read the user input and write it to the database.

  5. Update the readTestData method in the MainActivity.kt to display the city from the database.

  6. Run the app and ensure we can write and read all the values.

Complete the challenge

The example app contains a fully working app with Room integration. Follow the instructions for this task to complete this coding exercise.

Get hands-on with 1200+ tech skills courses.