diff --git a/diesel_cli/src/infer_schema_internals/data_structures.rs b/diesel_cli/src/infer_schema_internals/data_structures.rs index f52568465766..0b7c9d4f1b03 100644 --- a/diesel_cli/src/infer_schema_internals/data_structures.rs +++ b/diesel_cli/src/infer_schema_internals/data_structures.rs @@ -162,8 +162,8 @@ impl ForeignKeyConstraint { #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum SupportedColumnStructures { - VIEW, - TABLE, + View, + Table, } #[derive(Debug)] @@ -198,8 +198,8 @@ impl ColumnData { impl Display for SupportedColumnStructures { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let format = match self { - Self::TABLE => "BASE TABLE", - Self::VIEW => "VIEW", + Self::Table => "BASE TABLE", + Self::View => "VIEW", }; write!(f, "{format}") } @@ -209,8 +209,8 @@ impl FromStr for SupportedColumnStructures { type Err = (); fn from_str(s: &str) -> Result { match s { - "BASE TABLE" => Ok(Self::TABLE), - "VIEW" => Ok(Self::VIEW), + "BASE TABLE" => Ok(Self::Table), + "VIEW" => Ok(Self::View), _ => unreachable!("This should never happen. Read {s}"), } } @@ -224,6 +224,6 @@ impl SupportedColumnStructures { .collect() } pub fn all() -> Vec { - vec![Self::VIEW, Self::TABLE] + vec![Self::View, Self::Table] } } diff --git a/diesel_cli/src/infer_schema_internals/inference.rs b/diesel_cli/src/infer_schema_internals/inference.rs index a6761b58e1ef..acfc06d42ec7 100644 --- a/diesel_cli/src/infer_schema_internals/inference.rs +++ b/diesel_cli/src/infer_schema_internals/inference.rs @@ -134,7 +134,7 @@ pub fn filter_column_structure( structure: SupportedColumnStructures, ) -> Vec { table_names - .into_iter() + .iter() .filter_map(|(s, t)| if *s == structure { Some(t) } else { None }) .cloned() .collect() @@ -286,19 +286,19 @@ fn load_column_structure_data( DocConfig::NoDocComments => None, DocConfig::OnlyDatabaseComments | DocConfig::DatabaseCommentsFallbackToAutoGeneratedDocComment => { - get_table_comment(connection, &name)? + get_table_comment(connection, name)? } }; - get_column_information(connection, &name, &config.column_sorting)? + get_column_information(connection, name, &config.column_sorting)? .into_iter() .map(|c| { let default_pk = vec![]; let ty = determine_column_type( &c, connection, - &name, - primary_key.unwrap_or_else(|| &default_pk), + name, + primary_key.unwrap_or(&default_pk), config, )?; diff --git a/diesel_cli/src/infer_schema_internals/sqlite.rs b/diesel_cli/src/infer_schema_internals/sqlite.rs index c1f5545a492e..29a5d3057ae3 100644 --- a/diesel_cli/src/infer_schema_internals/sqlite.rs +++ b/diesel_cli/src/infer_schema_internals/sqlite.rs @@ -50,7 +50,7 @@ pub fn load_table_names( .into_iter() .map(|table| { ( - SupportedColumnStructures::TABLE, + SupportedColumnStructures::Table, TableName::from_name(table), ) }); @@ -62,7 +62,7 @@ pub fn load_table_names( .order(name) .load::(connection)? .into_iter() - .map(|table| (SupportedColumnStructures::VIEW, TableName::from_name(table))); + .map(|table| (SupportedColumnStructures::View, TableName::from_name(table))); Ok(tables.chain(view).collect()) } diff --git a/diesel_cli/src/migrations/diff_schema.rs b/diesel_cli/src/migrations/diff_schema.rs index 0390acb1bd8b..551737e1a902 100644 --- a/diesel_cli/src/migrations/diff_schema.rs +++ b/diesel_cli/src/migrations/diff_schema.rs @@ -102,7 +102,7 @@ pub fn generate_sql_based_on_diff_schema( for (structure, table) in tables_from_database { tracing::info!(?table, "Diff for existing table"); match structure { - SupportedColumnStructures::TABLE => { + SupportedColumnStructures::Table => { let columns = crate::infer_schema_internals::load_table_data( &mut conn, table.clone(), @@ -151,7 +151,7 @@ pub fn generate_sql_based_on_diff_schema( }); } } - SupportedColumnStructures::VIEW => { + SupportedColumnStructures::View => { return Err(crate::errors::Error::UnsupportedFeature( "Views are not supported by --diff-schema yet".into(), )); diff --git a/diesel_cli/src/print_schema.rs b/diesel_cli/src/print_schema.rs index 3466f98103dc..20cf7c816c23 100644 --- a/diesel_cli/src/print_schema.rs +++ b/diesel_cli/src/print_schema.rs @@ -159,7 +159,7 @@ pub fn output_schema( let foreign_keys = remove_unsafe_foreign_keys_for_codegen( connection, &foreign_keys, - &filter_column_structure(&table_names, SupportedColumnStructures::TABLE), + &filter_column_structure(&table_names, SupportedColumnStructures::Table), ); let mut out = String::new(); @@ -169,10 +169,10 @@ pub fn output_schema( let data = table_names .into_iter() .map(|(kind, t)| match kind { - SupportedColumnStructures::TABLE => { + SupportedColumnStructures::Table => { Ok(ColumnData::Table(load_table_data(connection, t, config)?)) } - SupportedColumnStructures::VIEW => { + SupportedColumnStructures::View => { Ok(ColumnData::View(load_view_data(connection, t, config)?)) } }) @@ -660,7 +660,7 @@ impl<'a> Display for ColumnStructureDefinition<'a> { out, "{}", ColumnDefinitions { - columns: &self.table.columns(), + columns: self.table.columns(), with_docs: self.with_docs, table_full_sql_name: &full_sql_name, custom_type_overrides: self.custom_type_overrides