web3-proxy/migration/src/m20230215_152254_admin_trail.rs

80 lines
2.7 KiB
Rust
Raw Normal View History

2023-02-15 18:29:30 +03:00
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(
2023-04-05 22:19:03 +03:00
ColumnDef::new(AdminTrail::Caller).big_unsigned().not_null(), // TODO: Add Foreign Key
2023-02-15 18:29:30 +03:00
)
.foreign_key(
sea_query::ForeignKey::create()
.from(AdminTrail::Table, AdminTrail::Caller)
.to(User::Table, User::Id),
)
.col(
2023-04-05 22:19:03 +03:00
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
2023-02-15 18:29:30 +03:00
)
.foreign_key(
sea_query::ForeignKey::create()
.from(AdminTrail::Table, AdminTrail::ImitatingUser)
.to(User::Table, User::Id),
)
2023-04-05 22:19:03 +03:00
.col(ColumnDef::new(AdminTrail::Endpoint).string().not_null())
.col(ColumnDef::new(AdminTrail::Payload).string().not_null())
2023-02-15 18:29:30 +03:00
.col(
ColumnDef::new(AdminTrail::Timestamp)
.timestamp()
.not_null()
2023-04-05 22:19:03 +03:00
.extra("DEFAULT CURRENT_TIMESTAMP".to_string()),
2023-02-15 18:29:30 +03:00
)
.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,
2023-04-05 22:19:03 +03:00
Timestamp,
2023-02-15 18:29:30 +03:00
}
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum User {
Table,
Id,
2023-03-01 22:23:59 +03:00
// Address,
// Description,
// Email,
2023-04-05 22:19:03 +03:00
}