diff --git a/Cargo.lock b/Cargo.lock index 6cc9877c..51435518 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3331,6 +3331,7 @@ dependencies = [ name = "migration" version = "0.35.0" dependencies = [ + "chrono", "sea-orm-migration", "tokio", ] diff --git a/migration/Cargo.toml b/migration/Cargo.toml index d9458c70..583aff39 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -10,6 +10,7 @@ path = "src/lib.rs" [dependencies] tokio = { version = "1.29.1", features = ["full", "tracing"] } +chrono = "0.4.26" [dependencies.sea-orm-migration] version = "0.11.3" diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 1d2cd626..28b5de40 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -37,6 +37,7 @@ mod m20230705_214013_type_fixes; mod m20230707_211936_premium_tier_changes; mod m20230708_151756_rpc_accounting_free_usage_credits; mod m20230708_152131_referral_track_one_time_bonus_bonus; +mod m20230713_144446_stripe_default_date_created; pub struct Migrator; @@ -81,6 +82,7 @@ impl MigratorTrait for Migrator { Box::new(m20230707_211936_premium_tier_changes::Migration), Box::new(m20230708_151756_rpc_accounting_free_usage_credits::Migration), Box::new(m20230708_152131_referral_track_one_time_bonus_bonus::Migration), + Box::new(m20230713_144446_stripe_default_date_created::Migration), ] } } diff --git a/migration/src/m20230713_144446_stripe_default_date_created.rs b/migration/src/m20230713_144446_stripe_default_date_created.rs new file mode 100644 index 00000000..29d15f9b --- /dev/null +++ b/migration/src/m20230713_144446_stripe_default_date_created.rs @@ -0,0 +1,54 @@ +// TODO: Try to re-export timestamp from within sea-orm +use chrono; +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 + } + + 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, + Id, + StripePaymentIntendId, + Amount, + Currency, + Status, + DepositToUserId, + Description, + DateCreated, +} diff --git a/scripts/manual-tests/48-balance-downgrade.sh b/scripts/manual-tests/48-balance-downgrade.sh index c18425cd..d3e8e5f7 100644 --- a/scripts/manual-tests/48-balance-downgrade.sh +++ b/scripts/manual-tests/48-balance-downgrade.sh @@ -24,8 +24,8 @@ curl -X POST http://127.0.0.1:8544/user/login \ -H 'Content-Type: application/json' \ -d '{ "address": "0xeb3e928a2e54be013ef8241d4c9eaf4dfae94d5a", - "msg": "0x6c6c616d616e6f6465732e636f6d2077616e747320796f7520746f207369676e20696e207769746820796f757220457468657265756d206163636f756e743a0a3078654233453932384132453534424530313345463832343164344339456146344466414539344435610a0af09fa699f09fa699f09fa699f09fa699f09fa6990a0a5552493a2068747470733a2f2f6c6c616d616e6f6465732e636f6d2f0a56657273696f6e3a20310a436861696e2049443a203133370a4e6f6e63653a2030314834594e564b4b4a4e385737474e4b585643364137505a5a0a4973737565642041743a20323032332d30372d31305430313a31353a30352e3230323638375a0a45787069726174696f6e2054696d653a20323032332d30372d31305430313a33353a30352e3230323638375a", - "sig": "de9a7c024b9fac2b46e01a5397a74b1c479f2c2fd72f674133c3b6b3e5e569981d3f9d5551fe73c52e70173b2ea82c8bc0614b538f5c74179c4cbaa2bdab3f8e1b", + "msg": "0x6c6c616d616e6f6465732e636f6d2077616e747320796f7520746f207369676e20696e207769746820796f757220457468657265756d206163636f756e743a0a3078654233453932384132453534424530313345463832343164344339456146344466414539344435610a0af09fa699f09fa699f09fa699f09fa699f09fa6990a0a5552493a2068747470733a2f2f6c6c616d616e6f6465732e636f6d2f0a56657273696f6e3a20310a436861696e2049443a203133370a4e6f6e63653a203031483538414a5148354a5931594437535252534d5354424d4d0a4973737565642041743a20323032332d30372d31335431393a31303a32342e3239333534325a0a45787069726174696f6e2054696d653a20323032332d30372d31335431393a33303a32342e3239333534325a", + "sig": "9e5816b152b5f5527cd7e9f8f8aa7203cbe0aec6a8cc5e534b1e6e728d79ba1617cb8db1053a28cace8feb87304a00568292b8ee2a887f1956577186ae0988a31b", "version": "3", "signer": "MEW" }'