This is a simple example to demonstrate the Room migration in case in which we want to
- Change the datatype of a column in table
- Make fields either nullable or non-nullable
- Rename the column name
- Add or remove columns from the table
First build the project with the commit : 05204801051367f1796d74e98dbc7982ad9af7e5
In this commit we have customer model as:
data class Customer(
@PrimaryKey @ColumnInfo(name = "id") @Json(name = "id") val id: Long = 0,
@ColumnInfo(name = "name") val name: String,
@ColumnInfo(name = "gender") val gender: String,
@ColumnInfo(name = "mobile") val mobile: String,
@ColumnInfo(name = "landline") val landLine: String,
@ColumnInfo(name = "email") val email: String,
@ColumnInfo(name = "user_name") val userName: String,
@ColumnInfo(name = "language") val languagePreference: String,
@ColumnInfo(name = "wallet_amount") val walletAmount: Long,
@ColumnInfo(name = "profile_image_url") val profileImageUrl: String,
@ColumnInfo(name = "current_location") val currentLocation: String
)
Then over this commit build this commit : 4835eb2b26a7e8e27ed266d487f8acf6e41034ef
Which has customer model as:
data class Customer(
@PrimaryKey @ColumnInfo(name = "id") val id: Long = 0,
@ColumnInfo(name = "name") val name: String,
@ColumnInfo(name = "gender") val gender: String,
@ColumnInfo(name = "mobile") val mobile: String,
@ColumnInfo(name = "landline") val landLine: String?,
@ColumnInfo(name = "email") val email: String?,
@ColumnInfo(name = "user_name") val userName: String,
@ColumnInfo(name = "language") val languagePreference: String,
@ColumnInfo(name = "wallet_amount") val walletAmount: Double?,
@ColumnInfo(name = "profile_image_url") val profileImageUrl: String?,
@ColumnInfo(name = "current_location") val currentLocation: String?,
@ColumnInfo(name = "source") val source: String?
)