server: Switch to steps a single blob of text

This commit is contained in:
traxys 2023-06-25 21:10:44 +02:00
parent 27f9295aa3
commit b01f08ba2f
4 changed files with 14 additions and 61 deletions

View file

@ -12,24 +12,17 @@ enum Recipe {
Household,
Name,
Ranking,
Steps,
}
#[derive(Iden)]
enum RecipeIngerdients {
enum RecipeIngredients {
Table,
RecipeId,
IngredientId,
Amount,
}
#[derive(Iden)]
enum RecipeSteps {
Table,
RecipeId,
Num,
Text,
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
@ -48,6 +41,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Recipe::Name).text().not_null())
.col(ColumnDef::new(Recipe::Ranking).integer().not_null())
.col(ColumnDef::new(Recipe::Household).uuid().not_null())
.col(ColumnDef::new(Recipe::Steps).text().not_null())
.foreign_key(
ForeignKey::create()
.name("FK_recipe_household")
@ -63,61 +57,32 @@ impl MigrationTrait for Migration {
manager
.create_table(
Table::create()
.table(RecipeSteps::Table)
.table(RecipeIngredients::Table)
.if_not_exists()
.col(
ColumnDef::new(RecipeSteps::RecipeId)
.big_integer()
.not_null(),
)
.col(ColumnDef::new(RecipeSteps::Num).integer().not_null())
.col(ColumnDef::new(RecipeSteps::Text).text().not_null())
.primary_key(
Index::create()
.col(RecipeSteps::Num)
.col(RecipeSteps::RecipeId),
)
.foreign_key(
ForeignKey::create()
.name("FK_recipe_steps")
.from(RecipeSteps::Table, RecipeSteps::RecipeId)
.to(Recipe::Table, Recipe::Id)
.on_delete(ForeignKeyAction::Restrict)
.on_update(ForeignKeyAction::Restrict),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(RecipeIngerdients::Table)
.if_not_exists()
.col(
ColumnDef::new(RecipeIngerdients::RecipeId)
ColumnDef::new(RecipeIngredients::RecipeId)
.big_integer()
.not_null(),
)
.col(
ColumnDef::new(RecipeIngerdients::IngredientId)
ColumnDef::new(RecipeIngredients::IngredientId)
.big_integer()
.not_null(),
)
.col(
ColumnDef::new(RecipeIngerdients::Amount)
ColumnDef::new(RecipeIngredients::Amount)
.double()
.not_null(),
)
.primary_key(
Index::create()
.col(RecipeIngerdients::IngredientId)
.col(RecipeIngerdients::RecipeId),
.col(RecipeIngredients::IngredientId)
.col(RecipeIngredients::RecipeId),
)
.foreign_key(
ForeignKey::create()
.name("FK_recipe_ingredients_recipe")
.from(RecipeIngerdients::Table, RecipeIngerdients::RecipeId)
.from(RecipeIngredients::Table, RecipeIngredients::RecipeId)
.to(Recipe::Table, Recipe::Id)
.on_delete(ForeignKeyAction::Restrict)
.on_update(ForeignKeyAction::Restrict),
@ -125,7 +90,7 @@ impl MigrationTrait for Migration {
.foreign_key(
ForeignKey::create()
.name("FK_recipe_ingredients_ingredient")
.from(RecipeIngerdients::Table, RecipeIngerdients::IngredientId)
.from(RecipeIngredients::Table, RecipeIngredients::IngredientId)
.to(Ingredient::Table, Ingredient::Id)
.on_delete(ForeignKeyAction::Restrict)
.on_update(ForeignKeyAction::Restrict),
@ -139,11 +104,7 @@ impl MigrationTrait for Migration {
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(RecipeIngerdients::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(RecipeSteps::Table).to_owned())
.drop_table(Table::drop().table(RecipeIngredients::Table).to_owned())
.await?;
manager