49 lines
1.8 KiB
Rust
49 lines
1.8 KiB
Rust
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(RequestLogs::Table)
|
|
.if_not_exists()
|
|
.col(ColumnDef::new(RequestLogs::Id).big_integer().not_null().auto_increment().primary_key())
|
|
.col(ColumnDef::new(RequestLogs::Path).string().not_null())
|
|
.col(ColumnDef::new(RequestLogs::Method).string().not_null())
|
|
.col(ColumnDef::new(RequestLogs::RequestParams).text().null())
|
|
.col(ColumnDef::new(RequestLogs::ResponseParams).text().null())
|
|
.col(ColumnDef::new(RequestLogs::StatusCode).integer().not_null().default(200))
|
|
.col(ColumnDef::new(RequestLogs::UserId).big_integer().null())
|
|
.col(ColumnDef::new(RequestLogs::Username).string().null())
|
|
.col(ColumnDef::new(RequestLogs::RequestTime).timestamp().not_null().default(Expr::current_timestamp()))
|
|
.col(ColumnDef::new(RequestLogs::DurationMs).big_integer().not_null().default(0))
|
|
.col(ColumnDef::new(RequestLogs::CreatedAt).timestamp().not_null().default(Expr::current_timestamp()))
|
|
.to_owned()
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager.drop_table(Table::drop().table(RequestLogs::Table).to_owned()).await
|
|
}
|
|
}
|
|
|
|
#[derive(Iden)]
|
|
enum RequestLogs {
|
|
Table,
|
|
Id,
|
|
Path,
|
|
Method,
|
|
RequestParams,
|
|
ResponseParams,
|
|
StatusCode,
|
|
UserId,
|
|
Username,
|
|
RequestTime,
|
|
DurationMs,
|
|
CreatedAt,
|
|
} |