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

View file

@ -7,5 +7,4 @@ pub mod household_members;
pub mod ingredient;
pub mod recipe;
pub mod recipe_ingerdients;
pub mod recipe_steps;
pub mod user;

View file

@ -5,5 +5,4 @@ pub use super::household_members::Entity as HouseholdMembers;
pub use super::ingredient::Entity as Ingredient;
pub use super::recipe::Entity as Recipe;
pub use super::recipe_ingerdients::Entity as RecipeIngerdients;
pub use super::recipe_steps::Entity as RecipeSteps;
pub use super::user::Entity as User;

View file

@ -11,6 +11,8 @@ pub struct Model {
pub name: String,
pub ranking: i32,
pub household: Uuid,
#[sea_orm(column_type = "Text")]
pub steps: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
@ -23,8 +25,6 @@ pub enum Relation {
on_delete = "Restrict"
)]
Household,
#[sea_orm(has_many = "super::recipe_steps::Entity")]
RecipeSteps,
}
impl Related<super::household::Entity> for Entity {
@ -33,12 +33,6 @@ impl Related<super::household::Entity> for Entity {
}
}
impl Related<super::recipe_steps::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecipeSteps.def()
}
}
impl Related<super::ingredient::Entity> for Entity {
fn to() -> RelationDef {
super::recipe_ingerdients::Relation::Ingredient.def()