From 305a8aff9ec3874a9fca449dae5cd98ac4465a20 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 28 Sep 2022 16:10:00 +0000 Subject: [PATCH] actually add the file --- .../m20220928_015108_concurrency_limits.rs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 migration/src/m20220928_015108_concurrency_limits.rs diff --git a/migration/src/m20220928_015108_concurrency_limits.rs b/migration/src/m20220928_015108_concurrency_limits.rs new file mode 100644 index 00000000..28394257 --- /dev/null +++ b/migration/src/m20220928_015108_concurrency_limits.rs @@ -0,0 +1,58 @@ +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 field to the UserKeys table + manager + .alter_table( + sea_query::Table::alter() + .table(UserKeys::Table) + // add column for a better version of rate limiting + .add_column( + ColumnDef::new(UserKeys::MaxConcurrentRequests) + .big_unsigned() + .null() + .default(200), + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // put the UserKeys back to how it was before our migrations + manager + .alter_table( + sea_query::Table::alter() + .table(UserKeys::Table) + .to_owned() + .drop_column(UserKeys::MaxConcurrentRequests) + .to_owned(), + ) + .await + } +} + +// copied from *_log_reverts.rs, but added new columns +#[derive(Iden)] +pub enum UserKeys { + Table, + // we don't touch some of the columns + // Id, + // UserId, + // ApiKey, + // Description, + // PrivateTxs, + // Active, + // RequestsPerMinute, + // LogRevertChance, + // AllowedIps, + // AllowedOrigins, + // AllowedReferers, + // AllowedUserAgents, + MaxConcurrentRequests, +}