diff --git a/entities/Cargo.toml b/entities/Cargo.toml index 416a4af2..724ec2a1 100644 --- a/entities/Cargo.toml +++ b/entities/Cargo.toml @@ -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" diff --git a/migration/Cargo.toml b/migration/Cargo.toml index 92af3533..99cdda72 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -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] diff --git a/migration/src/lib.rs b/migration/src/lib.rs index fdf55e82..508a5142 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -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), ] } } diff --git a/migration/src/m20230911_180520_high_concurrency_tier.rs b/migration/src/m20230911_180520_high_concurrency_tier.rs new file mode 100644 index 00000000..ee5369b5 --- /dev/null +++ b/migration/src/m20230911_180520_high_concurrency_tier.rs @@ -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::.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, +}