From 03af6f4dc52fd1c8bf7e1c6d63e6128d2e3164fb Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 11 Dec 2022 20:50:07 -0800 Subject: [PATCH] forgot to git add this --- ...m20221211_124002_request_method_privacy.rs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 migration/src/m20221211_124002_request_method_privacy.rs diff --git a/migration/src/m20221211_124002_request_method_privacy.rs b/migration/src/m20221211_124002_request_method_privacy.rs new file mode 100644 index 00000000..dd1be314 --- /dev/null +++ b/migration/src/m20221211_124002_request_method_privacy.rs @@ -0,0 +1,85 @@ +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> { + // allow null method + manager + .alter_table( + Table::alter() + .table(Alias::new("rpc_accounting")) + .modify_column(ColumnDef::new(Alias::new("method")).string().null()) + .to_owned(), + ) + .await?; + + // existing keys get set to detailed logging + manager + .alter_table( + Table::alter() + .table(RpcKey::Table) + .add_column( + ColumnDef::new(RpcKey::LogLevel) + .enumeration( + Alias::new("log_level"), + [ + Alias::new("none"), + Alias::new("aggregated"), + Alias::new("detailed"), + ], + ) + .not_null() + .default("detailed"), + ) + .to_owned(), + ) + .await?; + + // new keys get set to no logging + manager + .alter_table( + Table::alter() + .table(RpcKey::Table) + .modify_column( + ColumnDef::new(RpcKey::LogLevel) + .enumeration( + Alias::new("log_level"), + [ + Alias::new("none"), + Alias::new("aggregated"), + Alias::new("detailed"), + ], + ) + .not_null() + .default("none"), + ) + .to_owned(), + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(RpcKey::Table) + .drop_column(RpcKey::LogLevel) + .to_owned(), + ) + .await?; + + Ok(()) + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum RpcKey { + Table, + LogLevel, +}