Initialize v1 support
This commit is contained in:
@@ -8,7 +8,7 @@ import gq.kirmanak.mealient.database.recipe.RecipeDao
|
||||
import gq.kirmanak.mealient.database.recipe.entity.*
|
||||
|
||||
@Database(
|
||||
version = 2,
|
||||
version = 3,
|
||||
entities = [
|
||||
CategoryEntity::class,
|
||||
CategoryRecipeEntity::class,
|
||||
@@ -21,7 +21,7 @@ import gq.kirmanak.mealient.database.recipe.entity.*
|
||||
],
|
||||
exportSchema = true,
|
||||
autoMigrations = [
|
||||
AutoMigration(from = 1, to = 2)
|
||||
AutoMigration(from = 1, to = 2),
|
||||
]
|
||||
)
|
||||
@TypeConverters(RoomTypeConverters::class)
|
||||
|
||||
@@ -17,6 +17,8 @@ interface DatabaseModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun createDb(@ApplicationContext context: Context): AppDb =
|
||||
Room.databaseBuilder(context, AppDb::class.java, "app.db").build()
|
||||
Room.databaseBuilder(context, AppDb::class.java, "app.db")
|
||||
.fallbackToDestructiveMigrationFrom(2)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
@@ -66,11 +66,11 @@ interface RecipeDao {
|
||||
@Transaction
|
||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) // The lint is wrong, the columns are actually used
|
||||
@Query("SELECT * FROM recipe JOIN recipe_summaries ON recipe.remote_id = recipe_summaries.remote_id JOIN recipe_ingredient ON recipe_ingredient.recipe_id = recipe.remote_id JOIN recipe_instruction ON recipe_instruction.recipe_id = recipe.remote_id WHERE recipe.remote_id = :recipeId")
|
||||
suspend fun queryFullRecipeInfo(recipeId: Long): FullRecipeInfo?
|
||||
suspend fun queryFullRecipeInfo(recipeId: String): FullRecipeInfo?
|
||||
|
||||
@Query("DELETE FROM recipe_ingredient WHERE recipe_id = :recipeId")
|
||||
suspend fun deleteRecipeIngredients(recipeId: Long)
|
||||
suspend fun deleteRecipeIngredients(recipeId: String)
|
||||
|
||||
@Query("DELETE FROM recipe_instruction WHERE recipe_id = :recipeId")
|
||||
suspend fun deleteRecipeInstructions(recipeId: Long)
|
||||
suspend fun deleteRecipeInstructions(recipeId: String)
|
||||
}
|
||||
@@ -25,5 +25,5 @@ import androidx.room.Index
|
||||
)
|
||||
data class CategoryRecipeEntity(
|
||||
@ColumnInfo(name = "category_id") val categoryId: Long,
|
||||
@ColumnInfo(name = "recipe_id", index = true) val recipeId: Long
|
||||
@ColumnInfo(name = "recipe_id", index = true) val recipeId: String,
|
||||
)
|
||||
@@ -6,6 +6,6 @@ import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "recipe")
|
||||
data class RecipeEntity(
|
||||
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: Long,
|
||||
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: String,
|
||||
@ColumnInfo(name = "recipe_yield") val recipeYield: String,
|
||||
)
|
||||
|
||||
@@ -7,11 +7,11 @@ import androidx.room.PrimaryKey
|
||||
@Entity(tableName = "recipe_ingredient")
|
||||
data class RecipeIngredientEntity(
|
||||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0,
|
||||
@ColumnInfo(name = "recipe_id") val recipeId: Long,
|
||||
@ColumnInfo(name = "recipe_id") val recipeId: String,
|
||||
@ColumnInfo(name = "title") val title: String,
|
||||
@ColumnInfo(name = "note") val note: String,
|
||||
@ColumnInfo(name = "unit") val unit: String,
|
||||
@ColumnInfo(name = "food") val food: String,
|
||||
@ColumnInfo(name = "disable_amount") val disableAmount: Boolean,
|
||||
@ColumnInfo(name = "quantity") val quantity: Int,
|
||||
@ColumnInfo(name = "quantity") val quantity: Double,
|
||||
)
|
||||
@@ -7,7 +7,7 @@ import androidx.room.PrimaryKey
|
||||
@Entity(tableName = "recipe_instruction")
|
||||
data class RecipeInstructionEntity(
|
||||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0,
|
||||
@ColumnInfo(name = "recipe_id") val recipeId: Long,
|
||||
@ColumnInfo(name = "recipe_id") val recipeId: String,
|
||||
@ColumnInfo(name = "title") val title: String,
|
||||
@ColumnInfo(name = "text") val text: String,
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ import kotlinx.datetime.LocalDateTime
|
||||
|
||||
@Entity(tableName = "recipe_summaries")
|
||||
data class RecipeSummaryEntity(
|
||||
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: Long,
|
||||
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: String,
|
||||
@ColumnInfo(name = "name") val name: String,
|
||||
@ColumnInfo(name = "slug") val slug: String,
|
||||
@ColumnInfo(name = "image") val image: String?,
|
||||
|
||||
@@ -23,5 +23,5 @@ import androidx.room.ForeignKey
|
||||
)
|
||||
data class TagRecipeEntity(
|
||||
@ColumnInfo(name = "tag_id") val tagId: Long,
|
||||
@ColumnInfo(name = "recipe_id", index = true) val recipeId: Long
|
||||
@ColumnInfo(name = "recipe_id", index = true) val recipeId: String,
|
||||
)
|
||||
Reference in New Issue
Block a user