From be3a392abb0f61e7a6eabd67de6cf015cfcbd722 Mon Sep 17 00:00:00 2001 From: Azan Ali Date: Tue, 27 Aug 2024 22:44:45 +0500 Subject: [PATCH 1/2] print diff if print-schema fails due to mismatch with --locked-schema flag --- diesel_cli/Cargo.toml | 1 + diesel_cli/src/main.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/diesel_cli/Cargo.toml b/diesel_cli/Cargo.toml index 842db31c4892..1452b299de9a 100644 --- a/diesel_cli/Cargo.toml +++ b/diesel_cli/Cargo.toml @@ -56,6 +56,7 @@ syn = { version = "2", features = ["visit"] } tracing = "0.1" tracing-subscriber = { version = "0.3.10", features = ["env-filter"] } thiserror = "1.0.10" +similar-asserts = "1.5.0" [dependencies.diesel] version = "~2.2.0" diff --git a/diesel_cli/src/main.rs b/diesel_cli/src/main.rs index 140dfffdfe08..5f1357d9ab0b 100644 --- a/diesel_cli/src/main.rs +++ b/diesel_cli/src/main.rs @@ -30,6 +30,7 @@ use database::InferConnection; use diesel::backend::Backend; use diesel::Connection; use diesel_migrations::{FileBasedMigrations, HarnessWithOutput, MigrationHarness}; +use similar_asserts::SimpleDiff; use std::error::Error; use std::io::stdout; use std::path::{Path, PathBuf}; @@ -282,6 +283,10 @@ fn regenerate_schema_if_file_specified(matches: &ArgMatches) -> Result<(), crate .map_err(|e| crate::errors::Error::IoError(e, Some(path.to_owned())))?; if schema.lines().ne(old_buf.lines()) { + println!( + "{}", + SimpleDiff::from_str(&schema, &old_buf, "new schema", "schema in file") + ); return Err(crate::errors::Error::SchemaWouldChange( path.display().to_string(), )); From e091edde41dc1fd970ef647e4e51fca01f881570 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Wed, 28 Aug 2024 21:29:30 +0200 Subject: [PATCH 2/2] Tweak output --- diesel_cli/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/diesel_cli/src/main.rs b/diesel_cli/src/main.rs index 5f1357d9ab0b..fc571ea9b65b 100644 --- a/diesel_cli/src/main.rs +++ b/diesel_cli/src/main.rs @@ -283,9 +283,13 @@ fn regenerate_schema_if_file_specified(matches: &ArgMatches) -> Result<(), crate .map_err(|e| crate::errors::Error::IoError(e, Some(path.to_owned())))?; if schema.lines().ne(old_buf.lines()) { + // it's fine to leak here, we will + // exit the application anyway soon + let label = path.file_name().expect("We have a file name here"); + let label = label.to_string_lossy().into_owned().leak(); println!( "{}", - SimpleDiff::from_str(&schema, &old_buf, "new schema", "schema in file") + SimpleDiff::from_str(&old_buf, &schema, label, "new schema") ); return Err(crate::errors::Error::SchemaWouldChange( path.display().to_string(),