rust-templates-actix-seaorm/src/migrations/m20220804_000001_create_audit_table.rs
2022-08-06 11:56:56 +08:00

53 lines
1.5 KiB
Rust

use sea_orm::sea_query::Table;
use sea_orm_migration::prelude::*;
use sea_orm_migration::{MigrationName, MigrationTrait};
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220804_000001_create_audit_table"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &sea_orm_migration::SchemaManager) -> Result<(), sea_orm::DbErr> {
manager
.create_table(
Table::create()
.table(Audit::Table)
.col(
ColumnDef::new(Audit::Id)
.integer()
.primary_key()
.auto_increment()
.not_null(),
)
.col(ColumnDef::new(Audit::CreatedAt).date_time().not_null())
.col(ColumnDef::new(Audit::Source).string().not_null())
.col(ColumnDef::new(Audit::Type).string().not_null())
.col(ColumnDef::new(Audit::Description).string().not_null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &sea_orm_migration::SchemaManager) -> Result<(), sea_orm::DbErr> {
manager
.drop_table(Table::drop().table(Audit::Table).to_owned())
.await
}
}
#[derive(Iden)]
pub enum Audit {
Table,
CreatedAt,
Id,
Source,
Type,
Description,
}