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 m20230529_184433_ingredients;
mod m20230618_163416_recipe;
mod m20230629_151746_recipe_person_count;
pub struct Migrator;
@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230520_203638_household::Migration),
Box::new(m20230529_184433_ingredients::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;
#[derive(Iden)]
enum Recipe {
pub enum Recipe {
Table,
Id,
Household,
Name,
Ranking,
Steps,
PersonCount,
}
#[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
}
}