1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Database record models matching table schemas.
//!
//! This module contains struct definitions that directly correspond to database
//! table rows. These models are used by repositories to return query results
//! and accept insertion/update data.
//!
//! # Design Principles
//!
//! - **Schema Mapping**: Each model struct matches a database table schema
//! - **SQLx Integration**: Models derive `sqlx::FromRow` for query results
//! - **Separation**: Database models are distinct from API models to allow
//! independent evolution of storage and API representations
//! - **Type Safety**: Uses newtype wrappers for IDs (UserId, GroupId, etc.)
//!
//! # Model Categories
//!
//! ## Core Resources
//!
//! - [`users`]: User accounts, authentication, and profiles
//! - [`groups`]: Group definitions and user-group memberships
//! - [`deployments`]: Model deployment configurations and routing
//! - [`inference_endpoints`]: Backend inference service endpoints
//!
//! ## Access Control
//!
//! - [`api_keys`]: API keys for programmatic access
//! - [`password_reset_tokens`]: Time-limited password reset tokens
//!
//! ## Operations
//!
//! - [`credits`]: Credit balance tracking and transaction history
//! - [`probes`]: Health probe definitions and execution results
//!
//! # Conversion to API Models
//!
//! Database models typically implement `From` or `Into` conversions to API models:
//!
//! ```ignore
//! use dwctl::db::models::users::User as DbUser;
//! use dwctl::api::models::users::UserResponse;
//!
//! let db_user: DbUser = /* ... */;
//! let api_response: UserResponse = db_user.into();
//! ```
//!
//! # Example
//!
//! ```ignore
//! use dwctl::db::models::users::User;
//! use sqlx::PgPool;
//!
//! async fn fetch_user(pool: &PgPool, email: &str) -> Result<Option<User>, sqlx::Error> {
//! sqlx::query_as!(
//! User,
//! "SELECT * FROM users WHERE email = $1",
//! email
//! )
//! .fetch_optional(pool)
//! .await
//! }
//! ```