diff --git a/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs b/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs index b478620..93dc9ad 100644 --- a/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs +++ b/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs @@ -1,4 +1,5 @@ use sea_orm_migration::prelude::*; +use crate::m20230402_232316_create_table_organizations::Organization; #[derive(DeriveMigrationName)] pub struct Migration; @@ -15,18 +16,16 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Role::Organization).string().not_null()) .foreign_key( ForeignKey::create() - .from(Role::Table, Role::Organization ) - ) - ) + .from(Role::Table, Role::Organization) + .to(Organization::Table, Organization::Id) + .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) + ).to_owned() + ).await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - // Replace the sample below with your own migration scripts - todo!(); - - manager - .drop_table(Table::drop().table(Post::Table).to_owned()) - .await + manager.drop_table(Table::drop().table(Role::Table).to_owned()).await } } diff --git a/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs b/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs index b058244..a44f3b2 100644 --- a/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs +++ b/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs @@ -1,4 +1,5 @@ use sea_orm_migration::prelude::*; +use crate::m20230404_133809_create_table_roles::Role; #[derive(DeriveMigrationName)] pub struct Migration; @@ -6,43 +7,47 @@ pub struct Migration; #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - // Replace the sample below with your own migration scripts - todo!(); - - manager - .create_table( - Table::create() - .table(Post::Table) - .if_not_exists() - .col( - ColumnDef::new(Post::Id) - .integer() - .not_null() - .auto_increment() - .primary_key(), - ) - .col(ColumnDef::new(Post::Title).string().not_null()) - .col(ColumnDef::new(Post::Text).string().not_null()) - .to_owned(), - ) - .await + manager.create_table( + Table::create() + .table(FirewallRule::Table) + .col(ColumnDef::new(FirewallRule::Id).string().not_null().primary_key()) + .col(ColumnDef::new(FirewallRule::Role).string().not_null()) + .col(ColumnDef::new(FirewallRule::Protocol).string().not_null()) + .col(ColumnDef::new(FirewallRule::Description).string().not_null()) + .col(ColumnDef::new(FirewallRule::AllowedRoleID).string().null()) + .col(ColumnDef::new(FirewallRule::PortRangeFrom).integer().not_null()) + .col(ColumnDef::new(FirewallRule::PortRangeTo).integer().not_null()) + .foreign_key( + ForeignKey::create() + .from(FirewallRule::Table, FirewallRule::Role) + .to(Role::Table, Role::Id) + .on_delete(ForeignKeyAction::Cascade) + .on_update(ForeignKeyAction::Cascade) + ) + .foreign_key( + ForeignKey::create() + .from(FirewallRule::Table, FirewallRule::AllowedRoleID) + .to(Role::Table, Role::Id) + .on_delete(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) + ).to_owned() + ).await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - // Replace the sample below with your own migration scripts - todo!(); - - manager - .drop_table(Table::drop().table(Post::Table).to_owned()) - .await + manager.drop_table(Table::drop().table(FirewallRule::Table).to_owned()).await } } /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] -enum Post { +pub enum FirewallRule { Table, Id, - Title, - Text, + Role, + Protocol, + Description, + AllowedRoleID, + PortRangeFrom, + PortRangeTo }