add roles and firewall rules
This commit is contained in:
parent
05704ffc11
commit
b8d2afe5c3
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
manager.create_table(
|
||||
Table::create()
|
||||
.table(Post::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Post::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
.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)
|
||||
)
|
||||
.col(ColumnDef::new(Post::Title).string().not_null())
|
||||
.col(ColumnDef::new(Post::Text).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
.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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue