2023-11-19 16:31:30 +00:00
|
|
|
use diesel::{Associations, Identifiable, Insertable, Queryable, Selectable};
|
2023-11-21 01:07:02 +00:00
|
|
|
use std::time::SystemTime;
|
2023-11-25 20:08:57 +00:00
|
|
|
use serde_json::Value;
|
2023-11-19 15:49:08 +00:00
|
|
|
|
2023-11-21 01:07:02 +00:00
|
|
|
#[derive(Queryable, Selectable, Insertable, Identifiable, Debug, PartialEq, Clone)]
|
2023-11-19 15:49:08 +00:00
|
|
|
#[diesel(table_name = crate::schema::users)]
|
|
|
|
#[diesel(check_for_backend(diesel::pg::Pg))]
|
|
|
|
pub struct User {
|
|
|
|
pub id: String,
|
2023-11-21 01:07:02 +00:00
|
|
|
pub email: String,
|
2023-11-19 16:31:30 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 01:07:02 +00:00
|
|
|
#[derive(
|
|
|
|
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
|
|
|
)]
|
2023-11-19 16:31:30 +00:00
|
|
|
#[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,
|
2023-11-21 01:07:02 +00:00
|
|
|
pub expires: SystemTime,
|
2023-11-20 01:58:46 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 01:07:02 +00:00
|
|
|
#[derive(
|
|
|
|
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
|
|
|
)]
|
2023-11-20 01:58:46 +00:00
|
|
|
#[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,
|
2023-11-21 01:07:02 +00:00
|
|
|
pub expires: SystemTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(
|
|
|
|
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
|
|
|
)]
|
|
|
|
#[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,
|
2023-11-23 03:50:20 +00:00
|
|
|
pub name: String,
|
|
|
|
pub created_at: SystemTime,
|
2023-11-23 20:23:52 +00:00
|
|
|
pub last_seen_at: SystemTime,
|
2023-11-21 01:07:02 +00:00
|
|
|
}
|
2023-11-22 15:59:21 +00:00
|
|
|
|
|
|
|
#[derive(
|
2023-11-23 20:23:52 +00:00
|
|
|
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
2023-11-22 15:59:21 +00:00
|
|
|
)]
|
|
|
|
#[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,
|
2023-11-23 20:23:52 +00:00
|
|
|
}
|
2023-11-25 20:08:57 +00:00
|
|
|
|
|
|
|
#[derive(
|
|
|
|
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
|
|
|
)]
|
|
|
|
#[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,
|
|
|
|
)]
|
|
|
|
#[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>
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
}
|