diff --git a/migration/src/lib.rs b/migration/src/lib.rs index df0617d..d811bc7 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -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), ] } } diff --git a/migration/src/m20230618_163416_recipe.rs b/migration/src/m20230618_163416_recipe.rs index 7a3dac9..73ac0c1 100644 --- a/migration/src/m20230618_163416_recipe.rs +++ b/migration/src/m20230618_163416_recipe.rs @@ -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)] diff --git a/migration/src/m20230629_151746_recipe_person_count.rs b/migration/src/m20230629_151746_recipe_person_count.rs new file mode 100644 index 0000000..64e8a2e --- /dev/null +++ b/migration/src/m20230629_151746_recipe_person_count.rs @@ -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 + } +} diff --git a/src/entity/recipe.rs b/src/entity/recipe.rs index c990dd3..03a680d 100644 --- a/src/entity/recipe.rs +++ b/src/entity/recipe.rs @@ -13,6 +13,7 @@ pub struct Model { pub household: Uuid, #[sea_orm(column_type = "Text")] pub steps: String, + pub person_count: i32, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]