parent
188e9efefb
commit
6a52f3c2d1
@ -0,0 +1,52 @@
|
||||
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
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Transaction::Table)
|
||||
.add_column(
|
||||
ColumnDef::new(Transaction::CreatedAt)
|
||||
.date_time()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let query = Query::update()
|
||||
.table(Transaction::Table)
|
||||
.value(
|
||||
Transaction::CreatedAt,
|
||||
Expr::col(Transaction::DatePublished),
|
||||
)
|
||||
.to_owned();
|
||||
|
||||
manager.exec_stmt(query).await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Transaction::Table)
|
||||
.drop_column(Transaction::CreatedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
enum Transaction {
|
||||
Table,
|
||||
DatePublished,
|
||||
CreatedAt,
|
||||
}
|
||||
Loading…
Reference in new issue