Repository: diesel-rs/diesel
File: diesel_cli/src/print_schema.rs (Rust)

Code before:
                    writeln!(f, "///")?;
                    writeln!(f, "/// (Automatically generated by Diesel.)")?;
                }
                let mut out = PadAdapter::new(f);
                writeln!(out, "pub mod sql_types {{")?;

                for (idx, t) in self.types_sorted.iter().enumerate() {
                    if idx != 0 {
                        writeln!(out)?;
                    }
                    if self.with_docs {
                        if let Some(ref schema) = t.schema {
                            writeln!(out, "/// The `{}.{}` SQL type", schema, t.sql_name)?;
                        } else {
                            writeln!(out, "/// The `{}` SQL type", t.sql_name)?;
                        }
                        writeln!(out, "///")?;
                        writeln!(out, "/// (Automatically generated by Diesel.)")?;
                    }
                    if self.derives.is_empty() {
                        writeln!(
                            out,
                            "#[derive(diesel::sql_types::SqlType, diesel::query_builder::QueryId)]"
                        )?;
                    } else {
                        writeln!(out, "#[derive({})]", self.derives.join(", "))?;
                    }
                    if let Some(ref schema) = t.schema {
                        writeln!(
                            out,
                            "#[diesel(postgres_type(name = \"{}\", schema = \"{}\"))]",
                            t.sql_name, schema
                        )?;
                    } else {
                        writeln!(out, "#[diesel(postgres_type(name = \"{}\"))]", t.sql_name)?;
                    }
                    writeln!(out, "pub struct {};", t.rust_name)?;
                }

                writeln!(f, "}}\n")?;
                Ok(())
            }
            #[cfg(feature = "sqlite")]
            Backend::Sqlite => {
                let _ = (&f, self.with_docs);
                for t in &self.types_sorted {
                    eprintln!("Encountered unknown type for Sqlite: {}", t.sql_name);
                }
                unreachable!(
                    "Diesel only support a closed set of types for Sqlite. \
                     If you ever see this error message please open an \

Review comment (suggestion):
I think it would be reasonable to always put the `SqlType` derive by default. I can't think of a scenario where people would want to not put it.

Code after:
                    writeln!(f, "///")?;
                    writeln!(f, "/// (Automatically generated by Diesel.)")?;
                }
                let mut out = PadAdapter::new(f);
                writeln!(out, "pub mod sql_types {{")?;

                for (idx, t) in self.types_sorted.iter().enumerate() {
                    if idx != 0 {
                        writeln!(out)?;
                    }
                    if self.with_docs {
                        if let Some(ref schema) = t.schema {
                            writeln!(out, "/// The `{}.{}` SQL type", schema, t.sql_name)?;
                        } else {
                            writeln!(out, "/// The `{}` SQL type", t.sql_name)?;
                        }
                        writeln!(out, "///")?;
                        writeln!(out, "/// (Automatically generated by Diesel.)")?;
                    }
                    writeln!(out, "#[derive({})]", self.derives.join(", "))?;
                    if let Some(ref schema) = t.schema {
                        writeln!(
                            out,
                            "#[diesel(postgres_type(name = \"{}\", schema = \"{}\"))]",
                            t.sql_name, schema
                        )?;
                    } else {
                        writeln!(out, "#[diesel(postgres_type(name = \"{}\"))]", t.sql_name)?;
                    }
                    writeln!(out, "pub struct {};", t.rust_name)?;
                }

                writeln!(f, "}}\n")?;
                Ok(())
            }
            #[cfg(feature = "sqlite")]
            Backend::Sqlite => {
                let _ = (&f, self.with_docs);
                for t in &self.types_sorted {
                    eprintln!("Encountered unknown type for Sqlite: {}", t.sql_name);
                }
                unreachable!(
                    "Diesel only support a closed set of types for Sqlite. \
                     If you ever see this error message please open an \
                     issue at https://github.com/diesel-rs/diesel containing \
                     a dump of your schema definition."
                )
            }
            #[cfg(feature = "mysql")]
            Backend::Mysql => {
                let _ = (&f, self.with_docs);