server: Add a table for ingredients
This commit is contained in:
parent
f88aecd306
commit
d5f3edc33f
7 changed files with 101 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;
|
|||
|
||||
mod m20220101_000001_account;
|
||||
mod m20230520_203638_household;
|
||||
mod m20230529_184433_ingredients;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ impl MigratorTrait for Migrator {
|
|||
vec![
|
||||
Box::new(m20220101_000001_account::Migration),
|
||||
Box::new(m20230520_203638_household::Migration),
|
||||
Box::new(m20230529_184433_ingredients::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use super::m20220101_000001_account::User;
|
|||
pub struct Migration;
|
||||
|
||||
#[derive(Iden)]
|
||||
enum Household {
|
||||
pub enum Household {
|
||||
Table,
|
||||
Name,
|
||||
Id,
|
||||
|
|
|
|||
53
migration/src/m20230529_184433_ingredients.rs
Normal file
53
migration/src/m20230529_184433_ingredients.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use crate::m20230520_203638_household::Household;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(Iden)]
|
||||
enum Ingredient {
|
||||
Table,
|
||||
Household,
|
||||
Id,
|
||||
Name,
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Ingredient::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Ingredient::Id)
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.big_integer()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Ingredient::Household).uuid().not_null())
|
||||
.col(ColumnDef::new(Ingredient::Name).string().not_null())
|
||||
.col(ColumnDef::new(Ingredient::Unit).string())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("FK_ingredients_household")
|
||||
.from(Ingredient::Table, Ingredient::Household)
|
||||
.to(Household::Table, Household::Id)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Ingredient::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue