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

Code before:
                    writeln!(out, "{} -> {},", column.rust_name, column_type)?;
                }
            }
        }
        writeln!(f, "}}")?;
        Ok(())
    }
}

struct Joinable<'a>(&'a ForeignKeyConstraint);

impl<'a> Display for Joinable<'a> {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        let child_table_name = &self.0.child_table.rust_name;

        let parent_table_name = &self.0.parent_table.rust_name;

        write!(
            f,
            "diesel::joinable!({} -> {} ({}));",
            child_table_name, parent_table_name, self.0.foreign_key_columns_rust[0],
        )
    }
}

/// Lifted directly from libcore/fmt/builders.rs
struct PadAdapter<'a, 'b: 'a> {
    fmt: &'a mut Formatter<'b>,
    on_newline: bool,
}

impl<'a, 'b: 'a> PadAdapter<'a, 'b> {
    fn new(fmt: &'a mut Formatter<'b>) -> PadAdapter<'a, 'b> {
        PadAdapter {
            fmt,
            on_newline: false,
        }
    }
}

impl<'a, 'b: 'a> Write for PadAdapter<'a, 'b> {
    fn write_str(&mut self, mut s: &str) -> fmt::Result {
        while !s.is_empty() {
            let on_newline = self.on_newline;

            let split = match s.find('\n') {
                Some(pos) => {
                    self.on_newline = true;
                    pos + 1
                }
                None => {

Review comment (bug):
This change is causing the CI failures. The old code was calling the `Display` implementation of the `ColumnType` type here: https://github.com/diesel-rs/diesel/blob/8d64a4011bed57851e3cd747df6d855d44ab9993/diesel_cli/src/infer_schema_internals/data_structures.rs#L74-L97

That generates some important wrapper-types depending on the nullability (and other conditions) for the type. By just using the the type name itself we loose that information. It's likely a better idea to just modify the stored values for `ColumnType::rust_name` at some stage for all custom mysql type fields and leave that code here unchanged

Code after:
                #[cfg(feature = "mysql")]
                let mut column_type = column.ty.clone();

                #[cfg(not(feature = "mysql"))]
                let column_type = column.ty.clone();

                #[cfg(feature = "mysql")]
                {
                    if let Some(custom_type) = self
                        .custom_type_defs
                        .types_sorted
                        .iter()
                        .find(|t| t.column_name == column.rust_name)
                    {
                        column_type = custom_type.column_type.clone();
                    }
                }

                #[cfg(not(feature = "mysql"))]
                let _ = self.custom_type_defs;

                if column.rust_name == column.sql_name {
                    writeln!(out, "{} -> {},", column.sql_name, column_type)?;
                } else {
                    writeln!(out, r#"#[sql_name = "{}"]"#, column.sql_name)?;
                    writeln!(out, "{} -> {},", column.rust_name, column_type)?;
                }
            }
        }
        writeln!(f, "}}")?;
        Ok(())
    }
}

struct Joinable<'a>(&'a ForeignKeyConstraint);

impl<'a> Display for Joinable<'a> {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        let child_table_name = &self.0.child_table.rust_name;

        let parent_table_name = &self.0.parent_table.rust_name;

        write!(
            f,
            "diesel::joinable!({} -> {} ({}));",
            child_table_name, parent_table_name, self.0.foreign_key_columns_rust[0],
        )
    }
}

/// Lifted directly from libcore/fmt/builders.rs