server: Switch to steps a single blob of text
This commit is contained in:
parent
27f9295aa3
commit
b01f08ba2f
4 changed files with 14 additions and 61 deletions
|
|
@ -12,24 +12,17 @@ enum Recipe {
|
||||||
Household,
|
Household,
|
||||||
Name,
|
Name,
|
||||||
Ranking,
|
Ranking,
|
||||||
|
Steps,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum RecipeIngerdients {
|
enum RecipeIngredients {
|
||||||
Table,
|
Table,
|
||||||
RecipeId,
|
RecipeId,
|
||||||
IngredientId,
|
IngredientId,
|
||||||
Amount,
|
Amount,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
enum RecipeSteps {
|
|
||||||
Table,
|
|
||||||
RecipeId,
|
|
||||||
Num,
|
|
||||||
Text,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
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::Name).text().not_null())
|
||||||
.col(ColumnDef::new(Recipe::Ranking).integer().not_null())
|
.col(ColumnDef::new(Recipe::Ranking).integer().not_null())
|
||||||
.col(ColumnDef::new(Recipe::Household).uuid().not_null())
|
.col(ColumnDef::new(Recipe::Household).uuid().not_null())
|
||||||
|
.col(ColumnDef::new(Recipe::Steps).text().not_null())
|
||||||
.foreign_key(
|
.foreign_key(
|
||||||
ForeignKey::create()
|
ForeignKey::create()
|
||||||
.name("FK_recipe_household")
|
.name("FK_recipe_household")
|
||||||
|
|
@ -63,61 +57,32 @@ impl MigrationTrait for Migration {
|
||||||
manager
|
manager
|
||||||
.create_table(
|
.create_table(
|
||||||
Table::create()
|
Table::create()
|
||||||
.table(RecipeSteps::Table)
|
.table(RecipeIngredients::Table)
|
||||||
.if_not_exists()
|
.if_not_exists()
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(RecipeSteps::RecipeId)
|
ColumnDef::new(RecipeIngredients::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)
|
|
||||||
.big_integer()
|
.big_integer()
|
||||||
.not_null(),
|
.not_null(),
|
||||||
)
|
)
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(RecipeIngerdients::IngredientId)
|
ColumnDef::new(RecipeIngredients::IngredientId)
|
||||||
.big_integer()
|
.big_integer()
|
||||||
.not_null(),
|
.not_null(),
|
||||||
)
|
)
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(RecipeIngerdients::Amount)
|
ColumnDef::new(RecipeIngredients::Amount)
|
||||||
.double()
|
.double()
|
||||||
.not_null(),
|
.not_null(),
|
||||||
)
|
)
|
||||||
.primary_key(
|
.primary_key(
|
||||||
Index::create()
|
Index::create()
|
||||||
.col(RecipeIngerdients::IngredientId)
|
.col(RecipeIngredients::IngredientId)
|
||||||
.col(RecipeIngerdients::RecipeId),
|
.col(RecipeIngredients::RecipeId),
|
||||||
)
|
)
|
||||||
.foreign_key(
|
.foreign_key(
|
||||||
ForeignKey::create()
|
ForeignKey::create()
|
||||||
.name("FK_recipe_ingredients_recipe")
|
.name("FK_recipe_ingredients_recipe")
|
||||||
.from(RecipeIngerdients::Table, RecipeIngerdients::RecipeId)
|
.from(RecipeIngredients::Table, RecipeIngredients::RecipeId)
|
||||||
.to(Recipe::Table, Recipe::Id)
|
.to(Recipe::Table, Recipe::Id)
|
||||||
.on_delete(ForeignKeyAction::Restrict)
|
.on_delete(ForeignKeyAction::Restrict)
|
||||||
.on_update(ForeignKeyAction::Restrict),
|
.on_update(ForeignKeyAction::Restrict),
|
||||||
|
|
@ -125,7 +90,7 @@ impl MigrationTrait for Migration {
|
||||||
.foreign_key(
|
.foreign_key(
|
||||||
ForeignKey::create()
|
ForeignKey::create()
|
||||||
.name("FK_recipe_ingredients_ingredient")
|
.name("FK_recipe_ingredients_ingredient")
|
||||||
.from(RecipeIngerdients::Table, RecipeIngerdients::IngredientId)
|
.from(RecipeIngredients::Table, RecipeIngredients::IngredientId)
|
||||||
.to(Ingredient::Table, Ingredient::Id)
|
.to(Ingredient::Table, Ingredient::Id)
|
||||||
.on_delete(ForeignKeyAction::Restrict)
|
.on_delete(ForeignKeyAction::Restrict)
|
||||||
.on_update(ForeignKeyAction::Restrict),
|
.on_update(ForeignKeyAction::Restrict),
|
||||||
|
|
@ -139,11 +104,7 @@ impl MigrationTrait for Migration {
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.drop_table(Table::drop().table(RecipeIngerdients::Table).to_owned())
|
.drop_table(Table::drop().table(RecipeIngredients::Table).to_owned())
|
||||||
.await?;
|
|
||||||
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(RecipeSteps::Table).to_owned())
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
manager
|
manager
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,4 @@ pub mod household_members;
|
||||||
pub mod ingredient;
|
pub mod ingredient;
|
||||||
pub mod recipe;
|
pub mod recipe;
|
||||||
pub mod recipe_ingerdients;
|
pub mod recipe_ingerdients;
|
||||||
pub mod recipe_steps;
|
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,4 @@ pub use super::household_members::Entity as HouseholdMembers;
|
||||||
pub use super::ingredient::Entity as Ingredient;
|
pub use super::ingredient::Entity as Ingredient;
|
||||||
pub use super::recipe::Entity as Recipe;
|
pub use super::recipe::Entity as Recipe;
|
||||||
pub use super::recipe_ingerdients::Entity as RecipeIngerdients;
|
pub use super::recipe_ingerdients::Entity as RecipeIngerdients;
|
||||||
pub use super::recipe_steps::Entity as RecipeSteps;
|
|
||||||
pub use super::user::Entity as User;
|
pub use super::user::Entity as User;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ pub struct Model {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub ranking: i32,
|
pub ranking: i32,
|
||||||
pub household: Uuid,
|
pub household: Uuid,
|
||||||
|
#[sea_orm(column_type = "Text")]
|
||||||
|
pub steps: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
|
@ -23,8 +25,6 @@ pub enum Relation {
|
||||||
on_delete = "Restrict"
|
on_delete = "Restrict"
|
||||||
)]
|
)]
|
||||||
Household,
|
Household,
|
||||||
#[sea_orm(has_many = "super::recipe_steps::Entity")]
|
|
||||||
RecipeSteps,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Related<super::household::Entity> for Entity {
|
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 {
|
impl Related<super::ingredient::Entity> for Entity {
|
||||||
fn to() -> RelationDef {
|
fn to() -> RelationDef {
|
||||||
super::recipe_ingerdients::Relation::Ingredient.def()
|
super::recipe_ingerdients::Relation::Ingredient.def()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue