use Uuid and bools in our generated types

This commit is contained in:
Bryan Stitt 2022-08-05 19:47:50 +00:00
parent e295307afc
commit 20384e7f2f
11 changed files with 42 additions and 40 deletions

2
Cargo.lock generated

@ -1388,6 +1388,8 @@ name = "entities"
version = "0.1.0"
dependencies = [
"sea-orm",
"serde",
"uuid 1.1.2",
]
[[package]]

@ -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<u8>` -> `sea_orm::prelude::Uuid` and `i8` -> `bool`. Related: <https://github.com/SeaQL/sea-query/issues/375> <https://github.com/SeaQL/sea-orm/issues/924>
## Flame Graphs
Flame graphs make finding slow code painless:

@ -11,3 +11,5 @@ path = "src/mod.rs"
[dependencies]
sea-orm = "0.9.1"
serde = "1.0.142"
uuid = "1.1.2"

@ -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<u8>,
pub uuid: Uuid,
#[sea_orm(unique)]
pub address: String,
pub description: String,
pub description: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter)]

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

@ -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")]

@ -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<u8>,
pub user_id: Vec<u8>,
pub uuid: Uuid,
pub user_id: Uuid,
pub address: String,
pub description: String,
pub email: String,
pub description: Option<String>,
pub email: Option<String>,
pub role: Role,
}

@ -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<u8>,
pub uuid: Uuid,
#[sea_orm(unique)]
pub address: String,
pub description: String,
pub description: Option<String>,
pub email: Option<String>,
}

@ -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<u8>,
pub user_uuid: Vec<u8>,
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<String>,
pub private_txs: bool,
pub active: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

@ -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()

@ -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()
};