use serde::{Deserialize, Serialize};
use sqlx::{FromRow, Type};
use uuid::Uuid;
use chrono::{DateTime, Utc};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbModel {
pub id: Uuid,
pub name: String,
pub display_name: String,
pub description: Option<String>,
pub version: String,
pub model_type: String, pub size_category: String, pub file_size: i64,
pub provider: String,
pub license: Option<String>,
pub tags: sqlx::types::Json<Vec<String>>,
pub languages: sqlx::types::Json<Vec<String>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub file_path: Option<String>,
pub checksum: Option<String>,
pub download_url: Option<String>,
pub config: sqlx::types::Json<HashMap<String, serde_json::Value>>,
pub rating: Option<f32>,
pub download_count: i64,
pub is_official: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbInstalledModel {
pub id: Uuid,
pub model_id: Uuid,
pub install_path: String,
pub installed_at: DateTime<Utc>,
pub status: String, pub port: Option<i32>,
pub process_id: Option<i32>,
pub last_used: Option<DateTime<Utc>>,
pub usage_count: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbAvailableModel {
pub id: Uuid,
pub model_id: Uuid,
pub is_installed: bool,
pub published_at: DateTime<Utc>,
pub last_updated: DateTime<Utc>,
pub system_requirements: sqlx::types::Json<DbSystemRequirements>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DbSystemRequirements {
pub min_memory_gb: f32,
pub recommended_memory_gb: f32,
pub min_disk_space_gb: f32,
pub requires_gpu: bool,
pub supported_os: Vec<String>,
pub supported_architectures: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbRuntimeConfig {
pub id: Uuid,
pub name: String,
pub max_context_length: Option<i32>,
pub temperature: Option<f32>,
pub top_p: Option<f32>,
pub top_k: Option<i32>,
pub max_tokens: Option<i32>,
pub stop_sequences: sqlx::types::Json<Vec<String>>,
pub batch_size: Option<i32>,
pub max_concurrent_requests: Option<i32>,
pub gpu_device_ids: sqlx::types::Json<Vec<i32>>,
pub memory_limit_mb: Option<i64>,
pub enable_streaming: bool,
pub custom_params: sqlx::types::Json<HashMap<String, serde_json::Value>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbModelRuntime {
pub id: Uuid,
pub model_id: Uuid,
pub runtime_config_id: Uuid,
pub name: String,
pub port: i32,
pub process_id: Option<i32>,
pub started_at: Option<DateTime<Utc>>,
pub stopped_at: Option<DateTime<Utc>>,
pub status: String, pub health_endpoint: String,
pub api_endpoint: String,
pub log_file: Option<String>,
pub environment: sqlx::types::Json<HashMap<String, String>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbRuntimeMetrics {
pub id: Uuid,
pub runtime_id: Uuid,
pub timestamp: DateTime<Utc>,
pub cpu_usage_percent: f32,
pub memory_usage_mb: i64,
pub gpu_usage_percent: Option<f32>,
pub gpu_memory_usage_mb: Option<i64>,
pub active_connections: i32,
pub total_requests: i64,
pub successful_requests: i64,
pub failed_requests: i64,
pub avg_response_time_ms: f32,
pub throughput_rps: f32,
pub queue_length: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbRuntimeEvent {
pub id: Uuid,
pub runtime_id: Uuid,
pub event_type: String, pub timestamp: DateTime<Utc>,
pub message: String,
pub details: Option<sqlx::types::Json<serde_json::Value>>,
pub severity: String, }
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbModelRepository {
pub id: Uuid,
pub name: String,
pub url: String,
pub repo_type: String, pub enabled: bool,
pub auth_config: Option<sqlx::types::Json<DbRepositoryAuth>>,
pub last_sync: Option<DateTime<Utc>>,
pub sync_status: String, pub description: Option<String>,
pub tags: sqlx::types::Json<Vec<String>>,
pub priority: i32,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DbRepositoryAuth {
pub auth_type: String, pub username: Option<String>,
pub token: Option<String>,
pub api_key: Option<String>,
pub extra_params: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbRepositoryIndex {
pub id: Uuid,
pub repository_id: Uuid,
pub version: String,
pub updated_at: DateTime<Utc>,
pub checksum: Option<String>,
pub metadata: sqlx::types::Json<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbRepositoryModel {
pub id: Uuid,
pub repository_id: Uuid,
pub model_id: Uuid,
pub repo_model_id: String,
pub repo_path: String,
pub download_urls: sqlx::types::Json<Vec<DbDownloadUrl>>,
pub files: sqlx::types::Json<Vec<DbModelFile>>,
pub dependencies: sqlx::types::Json<Vec<String>>,
pub installation_notes: Option<String>,
pub usage_examples: sqlx::types::Json<Vec<String>>,
pub license_text: Option<String>,
pub model_card: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DbDownloadUrl {
pub filename: String,
pub url: String,
pub size: i64,
pub checksum: Option<String>,
pub checksum_algorithm: Option<String>,
pub is_primary: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DbModelFile {
pub filename: String,
pub size: i64,
pub file_type: String, pub checksum: Option<String>,
pub required: bool,
pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbGlobalConfig {
pub id: Uuid,
pub version: String,
pub config_data: sqlx::types::Json<serde_json::Value>, pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbSystemMetrics {
pub id: Uuid,
pub timestamp: DateTime<Utc>,
pub cpu_usage_percent: f32,
pub cpu_cores: i32,
pub memory_total_bytes: i64,
pub memory_used_bytes: i64,
pub memory_usage_percent: f32,
pub disk_total_bytes: i64,
pub disk_used_bytes: i64,
pub disk_usage_percent: f32,
pub network_rx_bytes_per_sec: i64,
pub network_tx_bytes_per_sec: i64,
pub gpu_usage_percent: Option<f32>,
pub gpu_memory_usage_mb: Option<i64>,
pub load_1m: f32,
pub load_5m: f32,
pub load_15m: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbApplicationMetrics {
pub id: Uuid,
pub timestamp: DateTime<Utc>,
pub uptime_seconds: i64,
pub total_requests: i64,
pub successful_requests: i64,
pub failed_requests: i64,
pub active_connections: i32,
pub avg_response_time_ms: f32,
pub p95_response_time_ms: f32,
pub p99_response_time_ms: f32,
pub current_qps: f32,
pub peak_qps: f32,
pub error_rate_percent: f32,
pub health_status: String, }
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbModelMetrics {
pub id: Uuid,
pub model_id: Uuid,
pub runtime_id: Option<Uuid>,
pub timestamp: DateTime<Utc>,
pub status: String, pub total_requests: i64,
pub successful_requests: i64,
pub failed_requests: i64,
pub avg_inference_time_ms: f32,
pub tokens_per_second: f32,
pub memory_usage_bytes: i64,
pub gpu_memory_usage_bytes: Option<i64>,
pub cpu_usage_percent: f32,
pub gpu_usage_percent: Option<f32>,
pub queue_length: i32,
pub last_request_time: Option<DateTime<Utc>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbAlertEvent {
pub id: Uuid,
pub alert_type: String, pub severity: String, pub title: String,
pub description: String,
pub triggered_at: DateTime<Utc>,
pub resolved_at: Option<DateTime<Utc>>,
pub status: String, pub resource_type: String,
pub resource_id: String,
pub resource_name: String,
pub value: f32,
pub threshold: f32,
pub labels: sqlx::types::Json<HashMap<String, String>>,
pub metadata: sqlx::types::Json<HashMap<String, String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbSyncResult {
pub id: Uuid,
pub repository_id: Uuid,
pub started_at: DateTime<Utc>,
pub completed_at: Option<DateTime<Utc>>,
pub status: String, pub models_added: i32,
pub models_updated: i32,
pub models_removed: i32,
pub error_message: Option<String>,
pub log_entries: sqlx::types::Json<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbUserSession {
pub id: Uuid,
pub user_id: String,
pub session_token: String,
pub created_at: DateTime<Utc>,
pub expires_at: DateTime<Utc>,
pub last_accessed: DateTime<Utc>,
pub ip_address: String,
pub user_agent: Option<String>,
pub is_active: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbApiUsage {
pub id: Uuid,
pub api_key_id: Option<Uuid>,
pub endpoint: String,
pub method: String,
pub timestamp: DateTime<Utc>,
pub response_time_ms: i32,
pub status_code: i32,
pub request_size_bytes: i64,
pub response_size_bytes: i64,
pub ip_address: String,
pub user_agent: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbTask {
pub id: Uuid,
pub task_type: String,
pub payload: sqlx::types::Json<serde_json::Value>,
pub status: String, pub priority: i32,
pub created_at: DateTime<Utc>,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
pub error_message: Option<String>,
pub retry_count: i32,
pub max_retries: i32,
pub scheduled_at: Option<DateTime<Utc>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct DbDownloadTask {
pub id: Uuid,
pub model_id: Uuid,
pub url: String,
pub file_path: String,
pub total_size: i64,
pub downloaded_size: i64,
pub status: String, pub progress_percent: f32,
pub download_speed_bps: i64,
pub estimated_time_remaining: Option<i32>, pub created_at: DateTime<Utc>,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
pub error_message: Option<String>,
}