From 20384e7f2f19c48fd0875060a90419be108f4c47 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 5 Aug 2022 19:47:50 +0000 Subject: [PATCH] use Uuid and bools in our generated types --- Cargo.lock | 2 ++ README.md | 2 ++ entities/Cargo.toml | 2 ++ entities/src/block_list.rs | 8 +++++--- entities/src/main.rs | 3 --- entities/src/sea_orm_active_enums.rs | 3 ++- entities/src/secondary_user.rs | 12 +++++++----- entities/src/user.rs | 8 +++++--- entities/src/user_keys.rs | 16 +++++++++------- migration/src/m20220101_000001_create_table.rs | 14 +++++--------- web3_proxy/src/bin/web3_proxy_cli.rs | 12 +++--------- 11 files changed, 42 insertions(+), 40 deletions(-) delete mode 100644 entities/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index b196f89a..f1356aef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1388,6 +1388,8 @@ name = "entities" version = "0.1.0" dependencies = [ "sea-orm", + "serde", + "uuid 1.1.2", ] [[package]] diff --git a/README.md b/README.md index dc6388e8..9ea908ee 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ Types for database entities are generated from a development database. sea-orm-cli generate entity -u mysql://root:dev_web3_proxy@127.0.0.1:3306/dev_web3_proxy -o entities/src ``` +Then manually fix some columns: `Vec` -> `sea_orm::prelude::Uuid` and `i8` -> `bool`. Related: + ## Flame Graphs Flame graphs make finding slow code painless: diff --git a/entities/Cargo.toml b/entities/Cargo.toml index be40c529..fd24bb99 100644 --- a/entities/Cargo.toml +++ b/entities/Cargo.toml @@ -11,3 +11,5 @@ path = "src/mod.rs" [dependencies] sea-orm = "0.9.1" +serde = "1.0.142" +uuid = "1.1.2" diff --git a/entities/src/block_list.rs b/entities/src/block_list.rs index b000e3d9..600015be 100644 --- a/entities/src/block_list.rs +++ b/entities/src/block_list.rs @@ -1,15 +1,17 @@ //! SeaORM Entity. Generated by sea-orm-codegen 0.9.1 use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; +use sea_orm::prelude::Uuid; -#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] #[sea_orm(table_name = "block_list")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub uuid: Vec, + pub uuid: Uuid, #[sea_orm(unique)] pub address: String, - pub description: String, + pub description: Option, } #[derive(Copy, Clone, Debug, EnumIter)] diff --git a/entities/src/main.rs b/entities/src/main.rs deleted file mode 100644 index e7a11a96..00000000 --- a/entities/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/entities/src/sea_orm_active_enums.rs b/entities/src/sea_orm_active_enums.rs index c10b6d0a..8bb3f269 100644 --- a/entities/src/sea_orm_active_enums.rs +++ b/entities/src/sea_orm_active_enums.rs @@ -1,8 +1,9 @@ //! SeaORM Entity. Generated by sea-orm-codegen 0.9.1 use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "role")] pub enum Role { #[sea_orm(string_value = "owner")] diff --git a/entities/src/secondary_user.rs b/entities/src/secondary_user.rs index 192f5c49..32ce425a 100644 --- a/entities/src/secondary_user.rs +++ b/entities/src/secondary_user.rs @@ -2,16 +2,18 @@ use super::sea_orm_active_enums::Role; use sea_orm::entity::prelude::*; +use sea_orm::prelude::Uuid; +use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] #[sea_orm(table_name = "secondary_user")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub uuid: Vec, - pub user_id: Vec, + pub uuid: Uuid, + pub user_id: Uuid, pub address: String, - pub description: String, - pub email: String, + pub description: Option, + pub email: Option, pub role: Role, } diff --git a/entities/src/user.rs b/entities/src/user.rs index 870d4ac4..0f34e7b7 100644 --- a/entities/src/user.rs +++ b/entities/src/user.rs @@ -1,15 +1,17 @@ //! SeaORM Entity. Generated by sea-orm-codegen 0.9.1 use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; +use sea_orm::prelude::Uuid; -#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] #[sea_orm(table_name = "user")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub uuid: Vec, + pub uuid: Uuid, #[sea_orm(unique)] pub address: String, - pub description: String, + pub description: Option, pub email: Option, } diff --git a/entities/src/user_keys.rs b/entities/src/user_keys.rs index f5e47eaa..48919bbf 100644 --- a/entities/src/user_keys.rs +++ b/entities/src/user_keys.rs @@ -1,18 +1,20 @@ //! SeaORM Entity. Generated by sea-orm-codegen 0.9.1 use sea_orm::entity::prelude::*; +use sea_orm::prelude::Uuid; +use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] #[sea_orm(table_name = "user_keys")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub uuid: Vec, - pub user_uuid: Vec, + pub uuid: Uuid, + pub user_uuid: Uuid, #[sea_orm(unique)] - pub api_key: String, - pub description: String, - pub private_txs: i8, - pub active: i8, + pub api_key: Uuid, + pub description: Option, + pub private_txs: bool, + pub active: bool, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/migration/src/m20220101_000001_create_table.rs b/migration/src/m20220101_000001_create_table.rs index 16d61c76..1a5b7e51 100644 --- a/migration/src/m20220101_000001_create_table.rs +++ b/migration/src/m20220101_000001_create_table.rs @@ -24,7 +24,7 @@ impl MigrationTrait for Migration { .not_null() .unique_key(), ) - .col(ColumnDef::new(User::Description).string().not_null()) + .col(ColumnDef::new(User::Description).string()) .col(ColumnDef::new(User::Email).string()) .to_owned(), ) @@ -48,12 +48,8 @@ impl MigrationTrait for Migration { .string_len(42) .not_null(), ) - .col( - ColumnDef::new(SecondaryUser::Description) - .string() - .not_null(), - ) - .col(ColumnDef::new(SecondaryUser::Email).string().not_null()) + .col(ColumnDef::new(SecondaryUser::Description).string()) + .col(ColumnDef::new(SecondaryUser::Email).string()) .col( ColumnDef::new(SecondaryUser::Role) .enumeration("role", ["owner", "admin", "collaborator"]) @@ -87,7 +83,7 @@ impl MigrationTrait for Migration { .not_null() .unique_key(), ) - .col(ColumnDef::new(BlockList::Description).string().not_null()) + .col(ColumnDef::new(BlockList::Description).string()) .to_owned(), ) .await?; @@ -111,7 +107,7 @@ impl MigrationTrait for Migration { .not_null() .unique_key(), ) - .col(ColumnDef::new(UserKeys::Description).string().not_null()) + .col(ColumnDef::new(UserKeys::Description).string()) .col( ColumnDef::new(UserKeys::PrivateTxs) .boolean() diff --git a/web3_proxy/src/bin/web3_proxy_cli.rs b/web3_proxy/src/bin/web3_proxy_cli.rs index 7cfb619f..1c22c81b 100644 --- a/web3_proxy/src/bin/web3_proxy_cli.rs +++ b/web3_proxy/src/bin/web3_proxy_cli.rs @@ -1,9 +1,7 @@ use argh::FromArgs; use entities::{user, user_keys}; -use ethers::prelude::Bytes; use fstrings::{format_args_f, println_f}; -use rand::prelude::*; -use sea_orm::{prelude::Uuid, ActiveModelTrait}; +use sea_orm::ActiveModelTrait; use web3_proxy::users::new_api_key; #[derive(Debug, FromArgs)] @@ -56,14 +54,10 @@ impl CreateUserSubCommand { println_f!("user: {u:?}"); - // TODO: use chacha20? - let api_key = new_api_key(); - - // TODO: create a key, too - // TODO: why are active and private_txs ints instead of bools? + // create a key for the new user let uk = user_keys::ActiveModel { user_uuid: sea_orm::Set(u.uuid), - // api_key: api_key, + api_key: sea_orm::Set(new_api_key()), ..Default::default() };