add high concurrency tier

This commit is contained in:
Bryan Stitt 2023-09-11 11:32:24 -07:00
parent d34f884f1c
commit 5913064809
4 changed files with 66 additions and 5 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "entities"
version = "0.42.0"
version = "0.43.0"
edition = "2021"
[lib]
@ -10,7 +10,7 @@ path = "src/mod.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ethers = { version = "2.0.9", default-features = false }
ethers = { version = "2.0.10", default-features = false }
sea-orm = "0.12.2"
serde = "1.0.188"
ulid = "1.0.1"
ulid = "1.1.0"

View File

@ -1,6 +1,6 @@
[package]
name = "migration"
version = "0.42.0"
version = "0.43.0"
edition = "2021"
publish = false
@ -10,7 +10,7 @@ path = "src/lib.rs"
[dependencies]
tokio = { version = "1.32.0", features = ["full", "tracing"] }
chrono = "0.4.29"
chrono = "0.4.30"
sea-orm = { version = "0.12.2", features = ["with-chrono"]}
[dependencies.sea-orm-migration]

View File

@ -42,6 +42,7 @@ mod m20230713_210511_deposit_add_date_created;
mod m20230726_072845_default_premium_user_tier;
mod m20230726_162138_drop_rpc_accounting_v2_fk;
mod m20230726_225124_reduce_out_of_funds_tier_limits;
mod m20230911_180520_high_concurrency_tier;
pub struct Migrator;
@ -91,6 +92,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230726_072845_default_premium_user_tier::Migration),
Box::new(m20230726_162138_drop_rpc_accounting_v2_fk::Migration),
Box::new(m20230726_225124_reduce_out_of_funds_tier_limits::Migration),
Box::new(m20230911_180520_high_concurrency_tier::Migration),
]
}
}

View File

@ -0,0 +1,59 @@
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> {
let db_conn = manager.get_connection();
let db_backend = manager.get_database_backend();
let select_free_id = Query::select()
.column(UserTier::Id)
.column(UserTier::Title)
.from(UserTier::Table)
.and_having(Expr::col(UserTier::Title).eq("Free"))
.to_owned();
let free_id: u64 = db_conn
.query_one(db_backend.build(&select_free_id))
.await?
.expect("Free tier should always exist")
.try_get("", &UserTier::Id.to_string())?;
let user_tiers = Query::insert()
.into_table(UserTier::Table)
.columns([
UserTier::Title,
UserTier::MaxRequestsPerPeriod,
UserTier::MaxConcurrentRequests,
UserTier::DowngradeTierId,
])
.values_panic([
"High Concurrency".into(),
None::<u64>.into(),
Some(300).into(),
Some(free_id).into(),
])
.to_owned();
manager.exec_stmt(user_tiers).await?;
Ok(())
}
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}
#[derive(Iden)]
enum UserTier {
Table,
Id,
Title,
MaxRequestsPerPeriod,
MaxConcurrentRequests,
DowngradeTierId,
}