diff --git a/diesel_cli/src/print_schema.rs b/diesel_cli/src/print_schema.rs index c1dca8a4f893..a64f75c8089b 100644 --- a/diesel_cli/src/print_schema.rs +++ b/diesel_cli/src/print_schema.rs @@ -697,20 +697,11 @@ impl<'a> Display for ColumnDefinitions<'a> { } // Write out attributes - if column.rust_name != column.sql_name || column.ty.max_length.is_some() { - let mut is_first = true; - write!(out, r#"#["#)?; - if column.rust_name != column.sql_name { - write!(out, r#"sql_name = {:?}"#, column.sql_name)?; - is_first = false; - } - if let Some(max_length) = column.ty.max_length { - if !is_first { - write!(out, ", ")?; - } - write!(out, "max_length = {}", max_length)?; - } - writeln!(out, r#"]"#)?; + if column.rust_name != column.sql_name { + writeln!(out, r#"#[sql_name = "{}"]"#, column.sql_name)?; + } + if let Some(max_length) = column.ty.max_length { + writeln!(out, r#"#[max_length = {}]"#, max_length)?; } writeln!(out, "{} -> {},", column.rust_name, column_type)?; diff --git a/diesel_cli/tests/print_schema.rs b/diesel_cli/tests/print_schema.rs index a432ecd6d002..c91cf4a8b989 100644 --- a/diesel_cli/tests/print_schema.rs +++ b/diesel_cli/tests/print_schema.rs @@ -250,6 +250,12 @@ fn print_schema_generated_columns_with_generated_always() { test_print_schema("print_schema_generated_columns_generated_always", vec![]) } +#[test] +#[cfg(feature = "postgres")] +fn print_schema_multiple_annotations() { + test_print_schema("print_schema_multiple_annotations", vec![]) +} + #[test] #[cfg(feature = "postgres")] fn print_schema_array_type() { diff --git a/diesel_cli/tests/print_schema/print_schema_multiple_annotations/diesel.toml b/diesel_cli/tests/print_schema/print_schema_multiple_annotations/diesel.toml new file mode 100644 index 000000000000..3985231b860a --- /dev/null +++ b/diesel_cli/tests/print_schema/print_schema_multiple_annotations/diesel.toml @@ -0,0 +1,3 @@ +[print_schema] +file = "src/schema.rs" +with_docs = false diff --git a/diesel_cli/tests/print_schema/print_schema_multiple_annotations/postgres/expected.snap b/diesel_cli/tests/print_schema/print_schema_multiple_annotations/postgres/expected.snap new file mode 100644 index 000000000000..dacb7bcf46b2 --- /dev/null +++ b/diesel_cli/tests/print_schema/print_schema_multiple_annotations/postgres/expected.snap @@ -0,0 +1,15 @@ +--- +source: diesel_cli/tests/print_schema.rs +description: "Test: print_schema_multiple_annotations" +--- +// @generated automatically by Diesel CLI. + +diesel::table! { + example (id) { + id -> Int4, + #[sql_name = "type"] + #[max_length = 10] + type_ -> Nullable, + } +} + diff --git a/diesel_cli/tests/print_schema/print_schema_multiple_annotations/postgres/schema.sql b/diesel_cli/tests/print_schema/print_schema_multiple_annotations/postgres/schema.sql new file mode 100644 index 000000000000..e7099ebf6626 --- /dev/null +++ b/diesel_cli/tests/print_schema/print_schema_multiple_annotations/postgres/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE example ( + id SERIAL PRIMARY KEY, + "type" VARCHAR(10) +);