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

Code before:
        match self.backend {
            #[cfg(feature = "postgres")]
            Backend::Pg => {
                if self.with_docs {
                    writeln!(f, "/// A module containing custom SQL type definitions")?;
                    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)]")?;
                    } else {
                        writeln!(
                            out,
                            "#[derive(diesel::sql_types::SqlType, {})]",
                            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);

Review comment (suggestion):
I think, it would be cleaner if `self.derives` would be augmented with `diesel::sql_types::SqlType` if that type not already presented there

Code after:
        match self.backend {
            #[cfg(feature = "postgres")]
            Backend::Pg => {
                if self.with_docs {
                    writeln!(f, "/// A module containing custom SQL type definitions")?;
                    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."