diff --git a/migration/src/lib.rs b/migration/src/lib.rs index cd4cbff6..0ada6ac7 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -18,6 +18,7 @@ mod m20230130_124740_read_only_login_logic; mod m20230130_165144_prepare_admin_imitation_pre_login; mod m20230215_152254_admin_trail; mod m20230125_204810_stats_v2; +mod m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2; pub struct Migrator; @@ -43,6 +44,7 @@ impl MigratorTrait for Migrator { Box::new(m20230130_165144_prepare_admin_imitation_pre_login::Migration), Box::new(m20230215_152254_admin_trail::Migration), Box::new(m20230125_204810_stats_v2::Migration), + Box::new(m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2::Migration), ] } } diff --git a/migration/src/m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2.rs b/migration/src/m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2.rs new file mode 100644 index 00000000..129fa4b3 --- /dev/null +++ b/migration/src/m20230307_002623_migrate_rpc_accounting_to_rpc_accounting_v2.rs @@ -0,0 +1,81 @@ +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 a nullable timestamp column to check if things were migrated in the rpc_accounting table .. + manager + .alter_table( + Table::alter() + .table(RpcAccounting::Table) + .to_owned() + .add_column( + ColumnDef::new(RpcAccounting::Migrated) + .timestamp() + ) + .to_owned() + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(RpcAccounting::Table) + .drop_column(RpcAccounting::Migrated) + .to_owned() + ) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +pub enum UserKeys { + Table, + Id, +} + +#[derive(Iden)] +enum RpcAccounting { + Table, + Id, + UserKeyId, + ChainId, + Method, + ErrorResponse, + PeriodDatetime, + FrontendRequests, + BackendRequests, + BackendRetries, + NoServers, + CacheMisses, + CacheHits, + SumRequestBytes, + MinRequestBytes, + MeanRequestBytes, + P50RequestBytes, + P90RequestBytes, + P99RequestBytes, + MaxRequestBytes, + SumResponseMillis, + MinResponseMillis, + MeanResponseMillis, + P50ResponseMillis, + P90ResponseMillis, + P99ResponseMillis, + MaxResponseMillis, + SumResponseBytes, + MinResponseBytes, + MeanResponseBytes, + P50ResponseBytes, + P90ResponseBytes, + P99ResponseBytes, + MaxResponseBytes, + Migrated +} +