diff options
| author | soryu <soryu@soryu.co> | 2025-12-24 05:45:22 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2025-12-24 05:45:22 +0000 |
| commit | 2faba0388f93d8e4fb86219eba7883b331d501ff (patch) | |
| tree | 92b83b8d558a652d3777627b2ac95ded250faa48 /makima/src/db/models.rs | |
| parent | 8f016a0e9d14badc39dffd67ed6fb862f9d08496 (diff) | |
| download | soryu-2faba0388f93d8e4fb86219eba7883b331d501ff.tar.gz soryu-2faba0388f93d8e4fb86219eba7883b331d501ff.zip | |
Add versioning to files
Diffstat (limited to 'makima/src/db/models.rs')
| -rw-r--r-- | makima/src/db/models.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs index 8204b86..617e590 100644 --- a/makima/src/db/models.rs +++ b/makima/src/db/models.rs @@ -149,3 +149,99 @@ impl From<File> for FileSummary { } } } + +// ============================================================================= +// Version History Types +// ============================================================================= + +/// Source of a version change +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, sqlx::Type)] +#[sqlx(type_name = "varchar")] +#[serde(rename_all = "lowercase")] +pub enum VersionSource { + #[sqlx(rename = "user")] + User, + #[sqlx(rename = "llm")] + Llm, + #[sqlx(rename = "system")] + System, +} + +impl std::fmt::Display for VersionSource { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + VersionSource::User => write!(f, "user"), + VersionSource::Llm => write!(f, "llm"), + VersionSource::System => write!(f, "system"), + } + } +} + +impl std::str::FromStr for VersionSource { + type Err = String; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s.to_lowercase().as_str() { + "user" => Ok(VersionSource::User), + "llm" => Ok(VersionSource::Llm), + "system" => Ok(VersionSource::System), + _ => Err(format!("Unknown version source: {}", s)), + } + } +} + +/// Full version record from the database +#[derive(Debug, Clone, FromRow, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct FileVersion { + pub id: Uuid, + pub file_id: Uuid, + pub version: i32, + pub name: String, + pub description: Option<String>, + pub summary: Option<String>, + #[sqlx(json)] + pub body: Vec<BodyElement>, + pub source: String, + pub change_description: Option<String>, + pub created_at: DateTime<Utc>, +} + +/// Summary of a version for list views +#[derive(Debug, Clone, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct FileVersionSummary { + pub version: i32, + pub source: String, + pub created_at: DateTime<Utc>, + pub change_description: Option<String>, +} + +impl From<FileVersion> for FileVersionSummary { + fn from(v: FileVersion) -> Self { + Self { + version: v.version, + source: v.source, + created_at: v.created_at, + change_description: v.change_description, + } + } +} + +/// Response for version list endpoint +#[derive(Debug, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct FileVersionListResponse { + pub versions: Vec<FileVersionSummary>, + pub total: i64, +} + +/// Request to restore a file to a previous version +#[derive(Debug, Deserialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct RestoreVersionRequest { + /// The version to restore to + pub target_version: i32, + /// The current version (for optimistic locking) + pub current_version: i32, +} |
