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

Code before:
            #[cfg(feature = "mysql")]
            Backend::Mysql => mysql_diesel_types(),
        };

        let mut all_types = table_data
            .iter()
            .flat_map(|t| {
                t.column_data.iter().map(move |c| CustomColumnType {
                    table_name: t.name.clone(),
                    column_name: c.rust_name.clone(),
                    column_type: c.ty.clone(),
                })
            })
            .filter(|t| !diesel_provided_types.contains(&t.column_type.rust_name as &str))
            .collect::<Vec<_>>();

        all_types.sort_unstable_by(|a, b| a.column_type.rust_name.cmp(&b.column_type.rust_name));

        #[cfg(feature = "postgres")]
        all_types.dedup_by(|a, b| a.column_type.rust_name.eq(&b.column_type.rust_name));

        all_types
    } else {
        Vec::new()
    };

    let definitions = TableDefinitions {
        tables: table_data,
        fk_constraints: foreign_keys,
        with_docs: config.with_docs,
        custom_type_defs: CustomTypeList {
            backend,
            types_sorted: custom_types_sorted,
            with_docs: match config.with_docs {
                DocConfig::DatabaseCommentsFallbackToAutoGeneratedDocComment => true,
                DocConfig::OnlyDatabaseComments | DocConfig::NoDocComments => false,
            },
            #[cfg(any(feature = "postgres", feature = "mysql"))]
            derives: config.custom_type_derives(),
        },
        import_types: config.import_types(),
    };

    if let Some(schema_name) = config.schema_name() {
        write!(out, "{}", ModuleDefinition(schema_name, definitions))?;
    } else {
        write!(out, "{}", definitions.custom_type_defs)?;
        write!(out, "{definitions}")?;
    }

    if let Some(ref patch_file) = config.patch_file {

Review comment (refactor):
That should be done for all backends, as it simplifies the code and we do note expect to have duplicates for mysql

Code after:
            #[cfg(feature = "mysql")]
            Backend::Mysql => mysql_diesel_types(),
        };

        let mut all_types = table_data
            .iter()
            .flat_map(|t| {
                t.column_data.iter().map(move |c| {
                    (
                        &c.ty,
                        CustomColumnType::new(
                            backend,
                            t.name.clone(),
                            c.rust_name.clone(),
                            c.ty.clone(),
                        ),
                    )
                })
            })
            .filter(|t| !diesel_provided_types.contains(&t.0.rust_name as &str))
            .map(|t| t.1)
            .collect::<Vec<_>>();

        all_types.sort_unstable_by(|a, b| a.column_type.rust_name.cmp(&b.column_type.rust_name));

        #[cfg(feature = "postgres")]
        if backend == Backend::Pg {
            // We only de-duplicate postgres custom types, since they can have one definition and multiple usages.
            all_types.dedup_by(|a, b| a.column_type.rust_name.eq(&b.column_type.rust_name));
        }

        all_types
    } else {
        Vec::new()
    };

    let definitions = TableDefinitions {
        tables: table_data,
        fk_constraints: foreign_keys,
        with_docs: config.with_docs,
        custom_type_defs: CustomTypeList {
            backend,
            types_sorted: custom_types_sorted,
            with_docs: match config.with_docs {
                DocConfig::DatabaseCommentsFallbackToAutoGeneratedDocComment => true,
                DocConfig::OnlyDatabaseComments | DocConfig::NoDocComments => false,
            },
            #[cfg(any(feature = "postgres", feature = "mysql"))]
            derives: config.custom_type_derives(),
        },
        import_types: config.import_types(),