From ef67dbdf79c9fadfafcf0837058079b587fc65f3 Mon Sep 17 00:00:00 2001 From: adz Date: Thu, 27 Jul 2023 14:27:48 +0200 Subject: [PATCH] Compare schema ids to really be sure that schema changed --- src/commands/build/print.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/commands/build/print.rs b/src/commands/build/print.rs index 83a1679..6eaed28 100644 --- a/src/commands/build/print.rs +++ b/src/commands/build/print.rs @@ -9,7 +9,7 @@ use comfy_table::{Cell, Color, Table}; use console::style; use p2panda_rs::identity::PublicKey; use p2panda_rs::schema::{ - FieldName, FieldType as PandaFieldType, SchemaDescription, SchemaId, SchemaName, + FieldName, FieldType as PandaFieldType, SchemaDescription, SchemaId, SchemaName, SchemaVersion, }; use crate::schema_file::{ @@ -240,6 +240,19 @@ pub fn print_plan( .apply_modifier(UTF8_ROUND_CORNERS) .set_header(vec!["#", "Field Name", "Field Type"]); + let did_schema_change = |name: &SchemaName| -> bool { + match plans.iter().find(|plan| &plan.schema_id().name() == name) { + Some(plan) => match plan.schema_diff().previous_schema_view { + Some(previous_view) => match plan.schema_id().version() { + SchemaVersion::Application(view_id) => previous_view.view_id() != &view_id, + _ => false, + }, + None => false, + }, + None => false, + } + }; + for (index, (field_name, (current_field, previous_field))) in fields.iter().enumerate() { let color = match (current_field, previous_field) { (None, Some(_)) => Color::Red, @@ -248,7 +261,7 @@ pub fn print_plan( // Was the schema changed this field refers to? let schema_changed = if let SchemaField::Relation { schema, .. } = current { if let RelationId::Name(name) = &schema.id { - plans.iter().any(|plan| &plan.schema_id().name() == name) + did_schema_change(name) } else { false }