From f1f34fbcb0e4eda16f4519a6106905cf6bc56700 Mon Sep 17 00:00:00 2001 From: yenicelik Date: Tue, 7 Mar 2023 22:40:34 +0100 Subject: [PATCH] will get back to this after fixing admin db issues --- web3_proxy/src/bin/web3_proxy_cli/main.rs | 1 + .../bin/web3_proxy_cli/migrate_stats_to_v2.rs | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs diff --git a/web3_proxy/src/bin/web3_proxy_cli/main.rs b/web3_proxy/src/bin/web3_proxy_cli/main.rs index 7d1d2b5d..5364d5e6 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/main.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/main.rs @@ -77,6 +77,7 @@ enum SubCommand { CreateKey(create_key::CreateKeySubCommand), CreateUser(create_user::CreateUserSubCommand), DropMigrationLock(drop_migration_lock::DropMigrationLockSubCommand), + MigrateStatsToV2(migrate_stats_to_v2::MigrateStatsToV2), Pagerduty(pagerduty::PagerdutySubCommand), PopularityContest(popularity_contest::PopularityContestSubCommand), Proxyd(proxyd::ProxydSubCommand), diff --git a/web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs b/web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs new file mode 100644 index 00000000..525536aa --- /dev/null +++ b/web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs @@ -0,0 +1,59 @@ +use anyhow::Context; +use argh::FromArgs; +use entities::user; +use ethers::types::Address; +use log::{debug, info}; +use migration::sea_orm::{ + self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, + QueryFilter, +}; + +/// change a user's address. +#[derive(FromArgs, PartialEq, Eq, Debug)] +#[argh(subcommand, name = "migrate_stats_to_v2")] +pub struct MigrateStatsToV2 {} + +impl MigrateStatsToV2 { + pub async fn main(self, db_conn: &DatabaseConnection) -> anyhow::Result<()> { + + // (1) Load a batch of rows out of the old table + + // (2) Create request metadata objects to match the old data + + // (3) Update the batch in the old table with the current timestamp + + // (4) Send through a channel to a stat emitter + + + + // let old_address: Address = self.old_address.parse()?; + // let new_address: Address = self.new_address.parse()?; + // + // let old_address: Vec = old_address.to_fixed_bytes().into(); + // let new_address: Vec = new_address.to_fixed_bytes().into(); + // + // let u = user::Entity::find() + // .filter(user::Column::Address.eq(old_address)) + // .one(db_conn) + // .await? + // .context("No user found with that address")?; + // + // debug!("initial user: {:#?}", u); + // + // if u.address == new_address { + // info!("user already has this address"); + // } else { + // let mut u = u.into_active_model(); + // + // u.address = sea_orm::Set(new_address); + // + // let u = u.save(db_conn).await?; + // + // info!("changed user address"); + // + // debug!("updated user: {:#?}", u); + // } + + Ok(()) + } +}