add roles and firewall rules

This commit is contained in:
c0repwn3r 2023-04-04 10:14:26 -04:00
parent 05704ffc11
commit b8d2afe5c3
Signed by: core
GPG Key ID: FDBF740DADDCEECF
2 changed files with 42 additions and 38 deletions

View File

@ -1,4 +1,5 @@
use sea_orm_migration::prelude::*; use sea_orm_migration::prelude::*;
use crate::m20230402_232316_create_table_organizations::Organization;
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
pub struct Migration; pub struct Migration;
@ -15,18 +16,16 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Role::Organization).string().not_null()) .col(ColumnDef::new(Role::Organization).string().not_null())
.foreign_key( .foreign_key(
ForeignKey::create() 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> { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts manager.drop_table(Table::drop().table(Role::Table).to_owned()).await
todo!();
manager
.drop_table(Table::drop().table(Post::Table).to_owned())
.await
} }
} }

View File

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