added admin trail table
This commit is contained in:
parent
46f715d3cc
commit
499610add7
37
entities/src/admin_trail.rs
Normal file
37
entities/src/admin_trail.rs
Normal file
@ -0,0 +1,37 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.6
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "admin_trail")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub caller: u64,
|
||||
pub imitating_user: Option<u64>,
|
||||
pub endpoint: String,
|
||||
pub payload: String,
|
||||
pub timestamp: DateTimeUtc,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::Caller",
|
||||
to = "super::user::Column::Id",
|
||||
on_update = "NoAction",
|
||||
on_delete = "NoAction"
|
||||
)]
|
||||
User2,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::ImitatingUser",
|
||||
to = "super::user::Column::Id",
|
||||
on_update = "NoAction",
|
||||
on_delete = "NoAction"
|
||||
)]
|
||||
User1,
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
@ -3,6 +3,7 @@
|
||||
pub mod prelude;
|
||||
|
||||
pub mod admin;
|
||||
pub mod admin_trail;
|
||||
pub mod login;
|
||||
pub mod pending_login;
|
||||
pub mod revert_log;
|
||||
|
@ -1,5 +1,7 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.5
|
||||
|
||||
pub use super::admin::Entity as Admin;
|
||||
pub use super::admin_trail::Entity as AdminTrail;
|
||||
pub use super::login::Entity as Login;
|
||||
pub use super::pending_login::Entity as PendingLogin;
|
||||
pub use super::revert_log::Entity as RevertLog;
|
||||
|
93
migration/src/m20230215_152254_admin_trail.rs
Normal file
93
migration/src/m20230215_152254_admin_trail.rs
Normal file
@ -0,0 +1,93 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(AdminTrail::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(AdminTrail::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AdminTrail::Caller)
|
||||
.big_unsigned()
|
||||
.not_null()
|
||||
// TODO: Add Foreign Key
|
||||
)
|
||||
.foreign_key(
|
||||
sea_query::ForeignKey::create()
|
||||
.from(AdminTrail::Table, AdminTrail::Caller)
|
||||
.to(User::Table, User::Id),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AdminTrail::ImitatingUser)
|
||||
.big_unsigned()
|
||||
// Can be null bcs maybe we're just logging in / using endpoints that don't imitate a user
|
||||
// TODO: Add Foreign Key
|
||||
)
|
||||
.foreign_key(
|
||||
sea_query::ForeignKey::create()
|
||||
.from(AdminTrail::Table, AdminTrail::ImitatingUser)
|
||||
.to(User::Table, User::Id),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AdminTrail::Endpoint)
|
||||
.string()
|
||||
.not_null()
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AdminTrail::Payload)
|
||||
.string()
|
||||
.not_null()
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AdminTrail::Timestamp)
|
||||
.timestamp()
|
||||
.not_null()
|
||||
.extra("DEFAULT CURRENT_TIMESTAMP".to_string())
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Replace the sample below with your own migration scripts
|
||||
manager
|
||||
.drop_table(Table::drop().table(AdminTrail::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
enum AdminTrail {
|
||||
Table,
|
||||
Id,
|
||||
Caller,
|
||||
ImitatingUser,
|
||||
Endpoint,
|
||||
Payload,
|
||||
Timestamp
|
||||
}
|
||||
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
enum User {
|
||||
Table,
|
||||
Id,
|
||||
Address,
|
||||
Description,
|
||||
Email,
|
||||
}
|
Loading…
Reference in New Issue
Block a user