-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events-collector: events-collector-server: create unaugmented event s…
…chema & models
- Loading branch information
Showing
15 changed files
with
472 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# For documentation on how to configure this file, | ||
# see https://diesel.rs/guides/configuring-diesel-cli | ||
|
||
[print_schema] | ||
file = "events-collector-server/src/db/schema.rs" | ||
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"] | ||
|
||
[migrations_directory] | ||
dir = "./migrations" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "events-collector-server" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# === Database === # | ||
diesel = { workspace = true, features = ["postgres", "numeric", "uuid"] } | ||
diesel-async = { workspace = true, features = ["postgres", "bb8"] } | ||
|
||
# === Misc === # | ||
uuid = { workspace = true } | ||
bigdecimal = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Database code | ||
|
||
pub mod models; | ||
|
||
#[allow(missing_docs)] | ||
#[allow(clippy::missing_docs_in_private_items)] | ||
pub mod schema; |
173 changes: 173 additions & 0 deletions
173
events-collector/events-collector-server/src/db/models.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
//! Events collector database models | ||
|
||
use std::time::SystemTime; | ||
|
||
use bigdecimal::BigDecimal; | ||
use diesel::prelude::*; | ||
use uuid::Uuid; | ||
|
||
/// A wallet creation record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::wallet_creations)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct WalletCreation { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the wallet that was created | ||
pub wallet_id: Uuid, | ||
} | ||
|
||
/// A deposit record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::deposits)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct Deposit { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the wallet that made the deposit | ||
pub wallet_id: Uuid, | ||
/// The mint of the asset that was deposited | ||
pub mint: String, | ||
/// The amount of the deposit | ||
pub amount: BigDecimal, | ||
} | ||
|
||
/// A withdrawal record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::withdrawals)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct Withdrawal { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the wallet that made the withdrawal | ||
pub wallet_id: Uuid, | ||
/// The mint of the asset that was withdrawn | ||
pub mint: String, | ||
/// The amount of the withdrawal | ||
pub amount: BigDecimal, | ||
} | ||
|
||
/// An order placement record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::order_placements)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct OrderPlacement { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the wallet that placed the order | ||
pub wallet_id: Uuid, | ||
/// The ID of the order that was placed | ||
pub order_id: Uuid, | ||
/// The mint of the base asset in the order | ||
pub base_mint: String, | ||
/// The mint of the quote asset in the order | ||
pub quote_mint: String, | ||
/// The amount of the base asset in the order | ||
pub amount: BigDecimal, | ||
/// Whether or not the order is to sell the base asset | ||
pub is_sell: bool, | ||
} | ||
|
||
/// An order cancellation record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::order_cancellations)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct OrderCancellation { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the wallet that cancelled the order | ||
pub wallet_id: Uuid, | ||
/// The ID of the order that was cancelled | ||
pub order_id: Uuid, | ||
/// The mint of the base asset in the order | ||
pub base_mint: String, | ||
/// The mint of the quote asset in the order | ||
pub quote_mint: String, | ||
/// The remaining amount of the base asset in the order | ||
pub amount_remaining: BigDecimal, | ||
/// The filled amount of the base asset in the order | ||
pub amount_filled: BigDecimal, | ||
/// Whether or not the order is to sell the base asset | ||
pub is_sell: bool, | ||
} | ||
|
||
/// A match record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::matches)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct Match { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the first wallet in the match | ||
pub wallet_id_0: Uuid, | ||
/// The ID of the second wallet in the match | ||
pub wallet_id_1: Uuid, | ||
/// The ID of the first order in the match | ||
pub order_id_0: Uuid, | ||
/// The ID of the second order in the match | ||
pub order_id_1: Uuid, | ||
/// Whether party 0 sold or bought the base asset | ||
pub party_0_sells: bool, | ||
/// The mint of the base asset in the match | ||
pub base_mint: String, | ||
/// The mint of the quote asset in the match | ||
pub quote_mint: String, | ||
/// The amount of the base asset exchanged in the match | ||
pub base_amount: BigDecimal, | ||
/// The amount of the quote asset exchanged in the match | ||
pub quote_amount: BigDecimal, | ||
} | ||
|
||
/// A fee payment record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::fee_payments)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct FeePayment { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the wallet that paid the fee | ||
pub wallet_id: Uuid, | ||
/// The mint of the asset that was paid | ||
pub mint: String, | ||
/// The amount of the fee | ||
pub amount: BigDecimal, | ||
} | ||
|
||
/// A fee collection record | ||
#[derive(Insertable)] | ||
#[diesel(table_name = crate::db::schema::fee_collections)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct FeeCollection { | ||
/// The event ID | ||
pub event_id: Uuid, | ||
/// The event timestamp | ||
pub event_timestamp: SystemTime, | ||
|
||
/// The ID of the wallet that collected the fee | ||
pub wallet_id: Uuid, | ||
/// The mint of the asset that was collected | ||
pub mint: String, | ||
/// The amount of the fee | ||
pub amount: BigDecimal, | ||
} |
Oops, something went wrong.