trifid/trifid-api/src/models.rs

152 lines
4.3 KiB
Rust

use diesel::{Associations, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
use std::time::SystemTime;
use serde_json::Value;
#[derive(Queryable, Selectable, Insertable, Identifiable, Debug, PartialEq, Clone, Serialize, Deserialize)]
#[diesel(table_name = crate::schema::users)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct User {
pub id: String,
pub email: String,
}
#[derive(
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone, Serialize, Deserialize
)]
#[diesel(belongs_to(User))]
#[diesel(table_name = crate::schema::magic_links)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct MagicLink {
pub id: String,
pub user_id: String,
pub expires: SystemTime,
}
#[derive(
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone, Serialize, Deserialize
)]
#[diesel(belongs_to(User))]
#[diesel(table_name = crate::schema::session_tokens)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct SessionToken {
pub id: String,
pub user_id: String,
pub expires: SystemTime,
}
#[derive(
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone, Serialize, Deserialize
)]
#[diesel(belongs_to(User))]
#[diesel(table_name = crate::schema::totp_authenticators)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct TotpAuthenticator {
pub id: String,
pub user_id: String,
pub secret: String,
pub verified: bool,
pub name: String,
pub created_at: SystemTime,
pub last_seen_at: SystemTime,
}
#[derive(
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone, Serialize, Deserialize
)]
#[diesel(belongs_to(User))]
#[diesel(table_name = crate::schema::auth_tokens)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct AuthToken {
pub id: String,
pub user_id: String,
pub expires: SystemTime,
}
#[derive(
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone, Serialize, Deserialize
)]
#[diesel(belongs_to(User, foreign_key = owner_id))]
#[diesel(table_name = crate::schema::organizations)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Organization {
pub id: String,
pub owner_id: String,
pub name: String
}
/*
id -> Varchar,
pem -> Varchar,
cert -> Jsonb,
expires_at -> Timestamp,
organization_id -> Varchar,
salt -> Bytea,
info -> Bytea,
private_key -> Bytea,
*/
#[derive(
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone, Serialize, Deserialize
)]
#[diesel(belongs_to(Organization))]
#[diesel(table_name = crate::schema::signing_cas)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct SigningCA {
pub id: String,
pub pem: String,
pub cert: Value,
pub expires_at: SystemTime,
pub organization_id: String,
pub salt: Vec<u8>,
pub info: Vec<u8>,
pub private_key: Vec<u8>
}
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
pub struct SigningCANormalized {
pub id: String,
pub pem: String,
pub cert: Value,
pub expires_at: String,
pub organization_id: String,
pub salt: Vec<u8>,
pub info: Vec<u8>,
pub private_key: Vec<u8>
}
/*
id VARCHAR NOT NULL PRIMARY KEY,
cidr VARCHAR NOT NULL,
organization_id VARCHAR NOT NULL REFERENCES organizations(id),
signing_ca_id VARCHAR NOT NULL REFERENCES signing_cas(id),
created_at TIMESTAMP NOT NULL,
name VARCHAR NOT NULL,
lighthouses_as_relays BOOLEAN
*/
#[derive(
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone
)]
#[diesel(belongs_to(Organization))]
#[diesel(belongs_to(SigningCA, foreign_key = signing_ca_id))]
#[diesel(table_name = crate::schema::networks)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Network {
pub id: String,
pub cidr: String,
pub organization_id: String,
pub signing_ca_id: String,
pub created_at: SystemTime,
pub name: String,
pub lighthouses_as_relays: bool
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct NetworkNormalized {
pub id: String,
pub cidr: String,
pub organization_id: String,
pub signing_ca_id: String,
pub created_at: String,
pub name: String,
pub lighthouses_as_relays: bool
}