85 lines
2.8 KiB
Rust
85 lines
2.8 KiB
Rust
|
|
use sea_orm_migration::prelude::*;
|
||
|
|
|
||
|
|
pub struct Migration;
|
||
|
|
|
||
|
|
impl MigrationName for Migration {
|
||
|
|
fn name(&self) -> &str {
|
||
|
|
"m20250525_000005_create_ledger_table_transaction" // Make sure this matches with the file name
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[async_trait::async_trait]
|
||
|
|
impl MigrationTrait for Migration {
|
||
|
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||
|
|
manager
|
||
|
|
.create_table(
|
||
|
|
Table::create()
|
||
|
|
.table(Transaction::Table)
|
||
|
|
.col(
|
||
|
|
ColumnDef::new(Transaction::Id)
|
||
|
|
.big_integer()
|
||
|
|
.not_null()
|
||
|
|
.auto_increment()
|
||
|
|
.primary_key(),
|
||
|
|
)
|
||
|
|
.col(ColumnDef::new(Transaction::Uid).big_integer().not_null())
|
||
|
|
.col(ColumnDef::new(Transaction::Type).integer().not_null())
|
||
|
|
.col(ColumnDef::new(Transaction::BookId).big_integer().not_null())
|
||
|
|
.col(
|
||
|
|
ColumnDef::new(Transaction::CategoryId)
|
||
|
|
.big_integer()
|
||
|
|
.not_null(),
|
||
|
|
)
|
||
|
|
.col(ColumnDef::new(Transaction::Description).string().not_null())
|
||
|
|
.col(
|
||
|
|
ColumnDef::new(Transaction::TransactionTime)
|
||
|
|
.timestamp_with_time_zone()
|
||
|
|
.default(Expr::current_timestamp())
|
||
|
|
.not_null(),
|
||
|
|
)
|
||
|
|
.col(
|
||
|
|
ColumnDef::new(Transaction::IsDeleted)
|
||
|
|
.boolean()
|
||
|
|
.default(false)
|
||
|
|
.not_null(),
|
||
|
|
)
|
||
|
|
.col(
|
||
|
|
ColumnDef::new(Transaction::CreatedAt)
|
||
|
|
.date_time()
|
||
|
|
.default(Expr::current_timestamp())
|
||
|
|
.not_null(),
|
||
|
|
)
|
||
|
|
.col(
|
||
|
|
ColumnDef::new(Transaction::UpdatedAt)
|
||
|
|
.date_time()
|
||
|
|
.default(Expr::current_timestamp())
|
||
|
|
.not_null(),
|
||
|
|
)
|
||
|
|
.to_owned(),
|
||
|
|
)
|
||
|
|
.await
|
||
|
|
}
|
||
|
|
|
||
|
|
// Define how to rollback this migration: Drop the Bakery table.
|
||
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||
|
|
manager
|
||
|
|
.drop_table(Table::drop().table(Transaction::Table).to_owned())
|
||
|
|
.await
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Iden)]
|
||
|
|
pub enum Transaction {
|
||
|
|
Table,
|
||
|
|
Id,
|
||
|
|
Uid,
|
||
|
|
Type,
|
||
|
|
BookId,
|
||
|
|
CategoryId,
|
||
|
|
Description,
|
||
|
|
TransactionTime,
|
||
|
|
IsDeleted,
|
||
|
|
CreatedAt,
|
||
|
|
UpdatedAt,
|
||
|
|
}
|