From 10573f5d1977ab3cb8b73bc5d9e3b6e248ac0df7 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 19 Jan 2023 21:29:33 -0800 Subject: [PATCH] actually add the migration. derp --- .../src/m20230119_204135_better_free_tier.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 migration/src/m20230119_204135_better_free_tier.rs diff --git a/migration/src/m20230119_204135_better_free_tier.rs b/migration/src/m20230119_204135_better_free_tier.rs new file mode 100644 index 00000000..aef9e5f8 --- /dev/null +++ b/migration/src/m20230119_204135_better_free_tier.rs @@ -0,0 +1,39 @@ +//! Increase requests per minute for the free tier to be better than our public tier (which has 3900/min) +use sea_orm_migration::{prelude::*, sea_orm::ConnectionTrait}; + +#[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 update_free = Query::update() + .table(UserTier::Table) + .value(UserTier::MaxRequestsPerPeriod, 6000) + .and_where(Expr::col(UserTier::Title).eq("Free")) + .limit(1) + .to_owned(); + + let x = db_backend.build(&update_free); + + let rows_affected = db_conn.execute(x).await?.rows_affected(); + + assert_eq!(rows_affected, 1, "unable to update free tier"); + + Ok(()) + } + + async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> { + todo!(); + } +} + +#[derive(Iden)] +enum UserTier { + Table, + Title, + MaxRequestsPerPeriod, +}