Skip to content

Commit

Permalink
Merge pull request #4210 from aznszn/diesel_cli_enhancement
Browse files Browse the repository at this point in the history
print diff if print-schema fails due to mismatch with --locked-schema flag
  • Loading branch information
weiznich authored Aug 28, 2024
2 parents e741ce5 + e091edd commit c4bde4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions diesel_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions diesel_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -282,6 +283,14 @@ 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(&old_buf, &schema, label, "new schema")
);
return Err(crate::errors::Error::SchemaWouldChange(
path.display().to_string(),
));
Expand Down

0 comments on commit c4bde4c

Please sign in to comment.