From a7485a17157d2c066473de70d4dc630d18f3d294 Mon Sep 17 00:00:00 2001 From: soryu Date: Thu, 29 Jan 2026 14:34:52 +0000 Subject: Fix phase config in DB --- makima/src/db/models.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'makima/src/db/models.rs') diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs index 2236ad5..91564c8 100644 --- a/makima/src/db/models.rs +++ b/makima/src/db/models.rs @@ -1457,11 +1457,11 @@ pub struct Contract { /// when evaluating task outputs. #[serde(skip_serializing_if = "Option::is_none")] pub red_team_prompt: Option, - /// Phase configuration copied from template at contract creation. + /// Phase configuration copied from template at contract creation (raw JSON). /// When present, this overrides the built-in contract type phases. - #[sqlx(json, default)] + /// Use `get_phase_config()` to get the parsed PhaseConfig. #[serde(skip_serializing_if = "Option::is_none")] - pub phase_config: Option, + pub phase_config: Option, pub version: i32, pub created_at: DateTime, pub updated_at: DateTime, @@ -1486,7 +1486,7 @@ impl Contract { /// Get valid phase IDs for this contract (as strings) pub fn valid_phase_ids(&self) -> Vec { // Check phase_config first (for custom templates) - if let Some(ref config) = self.phase_config { + if let Some(config) = self.get_phase_config() { let mut phases: Vec<_> = config.phases.iter().collect(); phases.sort_by_key(|p| p.order); return phases.iter().map(|p| p.id.clone()).collect(); @@ -1520,7 +1520,7 @@ impl Contract { /// Get the initial phase ID for this contract type (as string) pub fn initial_phase_id(&self) -> String { // Check phase_config first (for custom templates) - if let Some(ref config) = self.phase_config { + if let Some(config) = self.get_phase_config() { return config.default_phase.clone(); } @@ -1542,7 +1542,7 @@ impl Contract { /// Get the terminal phase ID for this contract type (as string) pub fn terminal_phase_id(&self) -> String { // Check phase_config first (for custom templates) - if let Some(ref config) = self.phase_config { + if let Some(config) = self.get_phase_config() { // Last phase in sorted order is the terminal phase let mut phases: Vec<_> = config.phases.iter().collect(); phases.sort_by_key(|p| p.order); @@ -1571,8 +1571,10 @@ impl Contract { } /// Get the phase configuration for custom templates - pub fn get_phase_config(&self) -> Option<&PhaseConfig> { - self.phase_config.as_ref() + pub fn get_phase_config(&self) -> Option { + self.phase_config + .as_ref() + .and_then(|v| serde_json::from_value(v.clone()).ok()) } /// Get completed deliverable IDs for a specific phase -- cgit v1.2.3