server: Link recipe to households

This commit is contained in:
traxys 2023-06-22 23:03:50 +02:00
parent cec3ef214e
commit 69197a3852
4 changed files with 35 additions and 1 deletions

View file

@ -1,6 +1,6 @@
use sea_orm_migration::prelude::*;
use crate::m20230529_184433_ingredients::Ingredient;
use crate::{m20230520_203638_household::Household, m20230529_184433_ingredients::Ingredient};
#[derive(DeriveMigrationName)]
pub struct Migration;
@ -9,6 +9,7 @@ pub struct Migration;
enum Recipe {
Table,
Id,
Household,
Name,
Ranking,
}
@ -46,6 +47,15 @@ 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())
.foreign_key(
ForeignKey::create()
.name("FK_recipe_household")
.from(Recipe::Table, Recipe::Household)
.to(Household::Table, Household::Id)
.on_delete(ForeignKeyAction::Restrict)
.on_update(ForeignKeyAction::Restrict),
)
.to_owned(),
)
.await?;