web3-proxy/migration/src/m20230713_144446_stripe_default_date_created.rs

47 lines
1.4 KiB
Rust
Raw Normal View History

// TODO: Try to re-export timestamp from within sea-orm
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(StripeIncreaseBalanceReceipt::Table)
.modify_column(
ColumnDef::new(StripeIncreaseBalanceReceipt::DateCreated)
.timestamp()
.extra("DEFAULT CURRENT_TIMESTAMP".to_string())
.not_null(),
)
.to_owned(),
)
.await?;
let now = chrono::offset::Utc::now();
// Then change all columns to "now"
let update_to_current_timestamp = Query::update()
.table(StripeIncreaseBalanceReceipt::Table)
.values([(StripeIncreaseBalanceReceipt::DateCreated, Some(now).into())])
.to_owned();
manager.exec_stmt(update_to_current_timestamp).await
}
2023-07-14 04:12:07 +03:00
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
// Do nothing ...
Ok(())
}
}
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum StripeIncreaseBalanceReceipt {
Table,
DateCreated,
}