Add DateCreated fields to admin and on-chain deposit (#190)

* tests seem to be passing

* bump version

* bump version
This commit is contained in:
David 2023-07-13 22:25:14 -04:00 committed by GitHub
parent 3c2d06324e
commit 31f840432d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 109 additions and 6 deletions

6
Cargo.lock generated

@ -1678,7 +1678,7 @@ dependencies = [
[[package]]
name = "entities"
version = "0.35.0"
version = "0.36.0"
dependencies = [
"ethers",
"sea-orm",
@ -3329,7 +3329,7 @@ dependencies = [
[[package]]
name = "migration"
version = "0.35.0"
version = "0.36.0"
dependencies = [
"chrono",
"sea-orm-migration",
@ -7033,7 +7033,7 @@ dependencies = [
[[package]]
name = "web3_proxy"
version = "0.35.0"
version = "0.36.0"
dependencies = [
"anyhow",
"arc-swap",

@ -1,6 +1,6 @@
[package]
name = "entities"
version = "0.35.0"
version = "0.36.0"
edition = "2021"
[lib]

@ -13,6 +13,7 @@ pub struct Model {
pub admin_id: u64,
pub deposit_to_user_id: u64,
pub note: String,
pub date_created: DateTimeUtc,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

@ -16,6 +16,7 @@ pub struct Model {
pub block_hash: String,
pub log_index: u64,
pub token_address: String,
pub date_created: DateTimeUtc,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

@ -1,6 +1,6 @@
[package]
name = "migration"
version = "0.35.0"
version = "0.36.0"
edition = "2021"
publish = false

@ -38,6 +38,7 @@ 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;
mod m20230713_210511_deposit_add_date_created;
pub struct Migrator;
@ -83,6 +84,7 @@ impl MigratorTrait for Migrator {
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),
Box::new(m20230713_210511_deposit_add_date_created::Migration),
]
}
}

@ -0,0 +1,96 @@
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> {
// Add column to both tables
manager
.alter_table(
Table::alter()
.table(AdminIncreaseBalanceReceipt::Table)
.add_column(
ColumnDef::new(AdminIncreaseBalanceReceipt::DateCreated)
.timestamp()
.extra("DEFAULT CURRENT_TIMESTAMP".to_string())
.not_null(),
)
.to_owned(),
)
.await?;
// Add column to both tables
manager
.alter_table(
Table::alter()
.table(IncreaseOnChainBalanceReceipt::Table)
.add_column(
ColumnDef::new(IncreaseOnChainBalanceReceipt::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(AdminIncreaseBalanceReceipt::Table)
.values([(AdminIncreaseBalanceReceipt::DateCreated, Some(now).into())])
.to_owned();
manager.exec_stmt(update_to_current_timestamp).await?;
// Then change all columns to "now"
let update_to_current_timestamp = Query::update()
.table(IncreaseOnChainBalanceReceipt::Table)
.values([(IncreaseOnChainBalanceReceipt::DateCreated, Some(now).into())])
.to_owned();
manager.exec_stmt(update_to_current_timestamp).await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager
.alter_table(
Table::alter()
.table(AdminIncreaseBalanceReceipt::Table)
.drop_column(AdminIncreaseBalanceReceipt::DateCreated)
.to_owned(),
)
.await?;
// Add column to both tables
manager
.alter_table(
Table::alter()
.table(IncreaseOnChainBalanceReceipt::Table)
.drop_column(IncreaseOnChainBalanceReceipt::DateCreated)
.to_owned(),
)
.await
}
}
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum AdminIncreaseBalanceReceipt {
Table,
Id,
Amount,
AdminId,
DepositToUserId,
Note,
DateCreated,
}
#[derive(Iden)]
enum IncreaseOnChainBalanceReceipt {
Table,
Id,
TxHash,
ChainId,
Amount,
DepositToUserId,
DateCreated,
}

@ -1,6 +1,6 @@
[package]
name = "web3_proxy"
version = "0.35.0"
version = "0.36.0"
edition = "2021"
default-run = "web3_proxy_cli"

@ -81,6 +81,7 @@ pub async fn user_chain_deposits_get(
"amount": x.amount,
"chain_id": x.chain_id,
"tx_hash": x.tx_hash,
"date_created": x.date_created
})
})
.collect::<Vec<_>>();
@ -163,6 +164,7 @@ pub async fn user_admin_deposits_get(
"amount": x.amount,
"deposit_to_user_id": x.deposit_to_user_id,
"note": x.note,
"date_created": x.date_created
})
})
.collect::<Vec<_>>();
@ -383,6 +385,7 @@ pub async fn user_balance_post(
log_index: sea_orm::ActiveValue::Set(log_index),
token_address: sea_orm::ActiveValue::Set(payment_token_address.encode_hex()),
tx_hash: sea_orm::ActiveValue::Set(tx_hash.encode_hex()),
date_created: sea_orm::ActiveValue::NotSet,
};
trace!("Trying to insert receipt {:?}", receipt);