114 lines
2.8 KiB
Rust
114 lines
2.8 KiB
Rust
//! Cot ORM models. UUIDs and typed documents use portable string storage in Cot 0.7.
|
|||
|
|
use chrono::{DateTime, Utc};
|
||
|
|
use cot::db::{Auto, model};
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "users")]
|
||
|
|
pub struct UserRow {
|
||
|
|
pub language: Option<String>,
|
||
|
|
pub demo_deleted_at: Option<DateTime<Utc>>,
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub id: String,
|
||
|
|
#[model(unique)]
|
||
|
|
pub username: String,
|
||
|
|
pub display_name: String,
|
||
|
|
pub country: String,
|
||
|
|
pub timezone: Option<String>,
|
||
|
|
pub password_hash: String,
|
||
|
|
pub created_at: DateTime<Utc>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "external_identities")]
|
||
|
|
pub struct ExternalIdentityRow {
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub id: String,
|
||
|
|
pub issuer: String,
|
||
|
|
pub subject: String,
|
||
|
|
pub user_id: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "sessions")]
|
||
|
|
pub struct SessionRow {
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub token_hash: String,
|
||
|
|
pub user_id: String,
|
||
|
|
pub csrf: String,
|
||
|
|
pub expires_at: DateTime<Utc>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "workspaces")]
|
||
|
|
pub struct WorkspaceRow {
|
||
|
|
pub demo_deleted_at: Option<DateTime<Utc>>,
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub id: String,
|
||
|
|
pub document: String,
|
||
|
|
pub revision: i64,
|
||
|
|
pub created_at: DateTime<Utc>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "workspace_members")]
|
||
|
|
pub struct WorkspaceMemberRow {
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub id: String,
|
||
|
|
pub workspace_id: String,
|
||
|
|
pub user_id: String,
|
||
|
|
pub permissions: String,
|
||
|
|
pub is_owner: bool,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "workspace_history")]
|
||
|
|
pub struct HistoryRow {
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub id: String,
|
||
|
|
pub workspace_id: String,
|
||
|
|
pub revision: i64,
|
||
|
|
pub document: String,
|
||
|
|
pub effective_at: DateTime<Utc>,
|
||
|
|
pub actor_id: Option<String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "audit_events")]
|
||
|
|
pub struct AuditRow {
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub id: Auto<i64>,
|
||
|
|
pub workspace_id: String,
|
||
|
|
pub actor_id: Option<String>,
|
||
|
|
pub action: String,
|
||
|
|
pub details: String,
|
||
|
|
pub created_at: DateTime<Utc>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "sync_jobs")]
|
||
|
|
pub struct SyncJobRow {
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub workspace_id: String,
|
||
|
|
pub requested_revision: i64,
|
||
|
|
pub published_revision: Option<i64>,
|
||
|
|
pub state: String,
|
||
|
|
pub attempts: i32,
|
||
|
|
pub next_attempt: DateTime<Utc>,
|
||
|
|
pub last_error: Option<String>,
|
||
|
|
pub last_success: Option<DateTime<Utc>>,
|
||
|
|
pub window_end: Option<DateTime<Utc>>,
|
||
|
|
pub lease_token: Option<String>,
|
||
|
|
pub lease_until: Option<DateTime<Utc>>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
#[model(table_name = "provider_objects")]
|
||
|
|
pub struct ProviderObjectRow {
|
||
|
|
#[model(primary_key)]
|
||
|
|
pub id: String,
|
||
|
|
pub workspace_id: String,
|
||
|
|
pub object_key: String,
|
||
|
|
pub remote_id: String,
|
||
|
|
pub content: String,
|
||
|
|
pub updated_at: DateTime<Utc>,
|
||
|
|
}
|