server: Add a person count to recipes

This commit is contained in:
traxys 2023-06-29 17:24:21 +02:00
parent 96a9907f7a
commit 614ff07552
4 changed files with 41 additions and 1 deletions

View file

@ -4,6 +4,7 @@ mod m20220101_000001_account;
mod m20230520_203638_household; mod m20230520_203638_household;
mod m20230529_184433_ingredients; mod m20230529_184433_ingredients;
mod m20230618_163416_recipe; mod m20230618_163416_recipe;
mod m20230629_151746_recipe_person_count;
pub struct Migrator; pub struct Migrator;
@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230520_203638_household::Migration), Box::new(m20230520_203638_household::Migration),
Box::new(m20230529_184433_ingredients::Migration), Box::new(m20230529_184433_ingredients::Migration),
Box::new(m20230618_163416_recipe::Migration), Box::new(m20230618_163416_recipe::Migration),
Box::new(m20230629_151746_recipe_person_count::Migration),
] ]
} }
} }

View file

@ -6,13 +6,14 @@ use crate::{m20230520_203638_household::Household, m20230529_184433_ingredients:
pub struct Migration; pub struct Migration;
#[derive(Iden)] #[derive(Iden)]
enum Recipe { pub enum Recipe {
Table, Table,
Id, Id,
Household, Household,
Name, Name,
Ranking, Ranking,
Steps, Steps,
PersonCount,
} }
#[derive(Iden)] #[derive(Iden)]

View file

@ -0,0 +1,36 @@
use sea_orm_migration::prelude::*;
use crate::m20230618_163416_recipe::Recipe;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Recipe::Table)
.add_column(
ColumnDef::new(Recipe::PersonCount)
.integer()
.not_null()
.default(1),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Recipe::Table)
.drop_column(Recipe::PersonCount)
.to_owned(),
)
.await
}
}

View file

@ -13,6 +13,7 @@ pub struct Model {
pub household: Uuid, pub household: Uuid,
#[sea_orm(column_type = "Text")] #[sea_orm(column_type = "Text")]
pub steps: String, pub steps: String,
pub person_count: i32,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]