update entitites

This commit is contained in:
Bryan Stitt 2022-09-24 00:14:35 +00:00
parent dbd8ea2429
commit 8035ee5a0c
9 changed files with 68 additions and 4 deletions

2
Cargo.lock generated

@ -1498,7 +1498,7 @@ dependencies = [
[[package]]
name = "entities"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"sea-orm",
"serde",

@ -72,7 +72,7 @@ This command only needs to be run during development. Production should use the
When developing new database migrations, **after you migrate**, run this command to generate updated entity files. It's best to keep the migration and entity changes in the same commit.
```
sea-orm-cli generate entity -u mysql://root:dev_web3_proxy@127.0.0.1:13306/dev_web3_proxy -o entities/src
sea-orm-cli generate entity -u mysql://root:dev_web3_proxy@127.0.0.1:13306/dev_web3_proxy -o entities/src --with-serde both
```
After running the above, you will need to 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>

@ -1,6 +1,6 @@
[package]
name = "entities"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
[lib]

@ -2,6 +2,7 @@
pub mod prelude;
pub mod revert_logs;
pub mod sea_orm_active_enums;
pub mod secondary_user;
pub mod user;

@ -1,5 +1,6 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.1
pub use super::revert_logs::Entity as RevertLogs;
pub use super::secondary_user::Entity as SecondaryUser;
pub use super::user::Entity as User;
pub use super::user_keys::Entity as UserKeys;

@ -0,0 +1,38 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.1
use super::sea_orm_active_enums::Method;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "revert_logs")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u64,
pub user_key_id: u64,
pub timestamp: DateTimeUtc,
pub method: Method,
pub to: Vec<u8>,
#[sea_orm(column_type = "Text")]
pub call_data: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user_keys::Entity",
from = "Column::UserKeyId",
to = "super::user_keys::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
UserKeys,
}
impl Related<super::user_keys::Entity> for Entity {
fn to() -> RelationDef {
Relation::UserKeys.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -13,3 +13,13 @@ pub enum Role {
#[sea_orm(string_value = "collaborator")]
Collaborator,
}
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "method")]
pub enum Method {
#[sea_orm(string_value = "eth_call")]
EthCall,
#[sea_orm(string_value = "eth_estimateGas")]
EthEstimateGas,
#[sea_orm(string_value = "eth_sendRawTransaction")]
EthSendRawTransaction,
}

@ -4,7 +4,7 @@ use super::sea_orm_active_enums::Role;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "secondary_user")]
pub struct Model {
#[sea_orm(primary_key)]

@ -16,9 +16,15 @@ pub struct Model {
pub private_txs: bool,
pub active: bool,
pub requests_per_minute: Option<u64>,
#[sea_orm(column_type = "Decimal(Some((5, 4)))")]
pub log_reverts: Decimal,
#[sea_orm(column_type = "Text", nullable)]
pub allowed_ips: Option<String>,
#[sea_orm(column_type = "Text", nullable)]
pub allowed_origins: Option<String>,
#[sea_orm(column_type = "Text", nullable)]
pub allowed_referers: Option<String>,
#[sea_orm(column_type = "Text", nullable)]
pub allowed_user_agents: Option<String>,
}
@ -32,6 +38,8 @@ pub enum Relation {
on_delete = "NoAction"
)]
User,
#[sea_orm(has_many = "super::revert_logs::Entity")]
RevertLogs,
}
impl Related<super::user::Entity> for Entity {
@ -40,4 +48,10 @@ impl Related<super::user::Entity> for Entity {
}
}
impl Related<super::revert_logs::Entity> for Entity {
fn to() -> RelationDef {
Relation::RevertLogs.def()
}
}
impl ActiveModelBehavior for ActiveModel {}