add roles and firewall rules
This commit is contained in:
parent
05704ffc11
commit
b8d2afe5c3
|
@ -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;
|
||||||
|
@ -16,17 +17,15 @@ impl MigrationTrait for Migration {
|
||||||
.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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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!();
|
|
||||||
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
Table::create()
|
||||||
.table(Post::Table)
|
.table(FirewallRule::Table)
|
||||||
.if_not_exists()
|
.col(ColumnDef::new(FirewallRule::Id).string().not_null().primary_key())
|
||||||
.col(
|
.col(ColumnDef::new(FirewallRule::Role).string().not_null())
|
||||||
ColumnDef::new(Post::Id)
|
.col(ColumnDef::new(FirewallRule::Protocol).string().not_null())
|
||||||
.integer()
|
.col(ColumnDef::new(FirewallRule::Description).string().not_null())
|
||||||
.not_null()
|
.col(ColumnDef::new(FirewallRule::AllowedRoleID).string().null())
|
||||||
.auto_increment()
|
.col(ColumnDef::new(FirewallRule::PortRangeFrom).integer().not_null())
|
||||||
.primary_key(),
|
.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())
|
.foreign_key(
|
||||||
.col(ColumnDef::new(Post::Text).string().not_null())
|
ForeignKey::create()
|
||||||
.to_owned(),
|
.from(FirewallRule::Table, FirewallRule::AllowedRoleID)
|
||||||
)
|
.to(Role::Table, Role::Id)
|
||||||
.await
|
.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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue