Skip to content

Commit 607c2e4

Browse files
committed
GL feedback
1 parent b7e5d26 commit 607c2e4

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

apps/framework-cli/src/framework/core/infrastructure/materialized_view.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ impl TableReference {
8787
}
8888
}
8989

90-
/// Deserializes a `LifeCycle` field that may be present as `null` in JSON.
90+
/// Deserializes a field that may be present as `null` in JSON, falling back to `T::default()`.
9191
///
9292
/// `MaterializedView` uses `#[serde(rename_all = "camelCase")]`, so the Python SDK's
9393
/// `"lifeCycle": null` is recognized as the field (unlike `Table` where the camelCase key is
9494
/// simply ignored as unknown). A plain `#[serde(default)]` only applies when the field is
9595
/// *absent*; when it's present as `null`, serde would attempt to deserialize `null` as
96-
/// `LifeCycle` and fail. This deserializer treats `null` the same as a missing field.
97-
fn deserialize_nullable_life_cycle<'de, D>(d: D) -> Result<LifeCycle, D::Error>
96+
/// the target type and fail. This deserializer treats `null` the same as a missing field.
97+
fn deserialize_nullable_as_default<'de, D, T>(d: D) -> Result<T, D::Error>
9898
where
9999
D: Deserializer<'de>,
100+
T: Default + Deserialize<'de>,
100101
{
101-
Option::<LifeCycle>::deserialize(d)
102-
.map(|opt| opt.unwrap_or_else(LifeCycle::default_for_deserialization))
102+
Option::<T>::deserialize(d).map(|opt| opt.unwrap_or_default())
103103
}
104104

105105
/// Represents a ClickHouse Materialized View.
@@ -141,10 +141,7 @@ pub struct MaterializedView {
141141

142142
/// Lifecycle management policy for the materialized view.
143143
/// Controls whether Moose can drop or modify the MV automatically.
144-
#[serde(
145-
default = "LifeCycle::default_for_deserialization",
146-
deserialize_with = "deserialize_nullable_life_cycle"
147-
)]
144+
#[serde(default, deserialize_with = "deserialize_nullable_as_default")]
148145
pub life_cycle: LifeCycle,
149146
}
150147

@@ -485,7 +482,7 @@ mod tests {
485482

486483
let mv_with_db = MaterializedView {
487484
database: Some("other_db".to_string()),
488-
..mv.clone()
485+
..mv
489486
};
490487
assert_eq!(mv_with_db.id("default_db"), "other_db_my_mv");
491488
}

apps/framework-cli/src/framework/core/partial_infrastructure_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ use crate::{
7272
///
7373
/// This enum controls the behavior when there are differences between code definitions
7474
/// and the actual database schema or structure.
75-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
75+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7676
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
7777
pub enum LifeCycle {
7878
/// Full automatic management (default behavior).
7979
/// Moose will automatically modify database resources to match code definitions,
8080
/// including potentially destructive operations like dropping columns or tables.
81+
#[default]
8182
FullyManaged,
8283

8384
/// Deletion-protected automatic management.
@@ -92,9 +93,8 @@ pub enum LifeCycle {
9293
}
9394

9495
impl LifeCycle {
95-
// not implementing the Default trait to avoid accidentally setting this value
9696
pub fn default_for_deserialization() -> LifeCycle {
97-
LifeCycle::FullyManaged
97+
LifeCycle::default()
9898
}
9999

100100
/// Returns true if this lifecycle protects the table from being dropped.

0 commit comments

Comments
 (0)