From 0569d714c3c7eb629bfa100b69a4110b0f937cc6 Mon Sep 17 00:00:00 2001 From: Matt Thompson Date: Sun, 23 Aug 2026 10:12:06 +0100 Subject: [PATCH 1/2] fix(codegen): emit uuid import for oxide format The oxide format is generated with --with-prelude=none, so nothing re-exports Uuid the way sea_orm::entity::prelude does. write_rs_type names it by bare identifier, and gen_imports only ever emitted serde and active-enum imports, so any table with a native uuid column produced a file that could not compile. Emit `use uuid::Uuid;` when the entity has a uuid column, following gen_import_active_enum. Decimal, IpNetwork and PgVector are named the same way and will need the same treatment when a column first uses them. Also pass the missing rename_active_enums argument at the six impl_active_enum test call sites, which have not compiled since the --rename-variant-name flag was added. Co-Authored-By: Claude Opus 5 --- sea-orm-codegen/src/entity/active_enum.rs | 6 ++ sea-orm-codegen/src/entity/writer/oxide.rs | 85 ++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/sea-orm-codegen/src/entity/active_enum.rs b/sea-orm-codegen/src/entity/active_enum.rs index a6e71948ca..cb5468b3b0 100644 --- a/sea-orm-codegen/src/entity/active_enum.rs +++ b/sea-orm-codegen/src/entity/active_enum.rs @@ -192,6 +192,7 @@ mod tests { &TokenStream::new(), &TokenStream::new(), EntityFormat::Compact, + Default::default(), ) .to_string(), quote!( @@ -235,6 +236,7 @@ mod tests { &TokenStream::new(), &TokenStream::new(), EntityFormat::Compact, + Default::default(), ) .to_string(), quote!( @@ -287,6 +289,7 @@ mod tests { &bonus_derive(["specta::Type", "ts_rs::TS"]), &TokenStream::new(), EntityFormat::Compact, + Default::default(), ) .to_string(), build_generated_enum(), @@ -324,6 +327,7 @@ mod tests { &TokenStream::new(), &bonus_attributes([r#"serde(rename_all = "camelCase")"#]), EntityFormat::Compact, + Default::default(), ) .to_string(), quote!( @@ -357,6 +361,7 @@ mod tests { &TokenStream::new(), &bonus_attributes([r#"serde(rename_all = "camelCase")"#, "ts(export)"]), EntityFormat::Compact, + Default::default(), ) .to_string(), quote!( @@ -408,6 +413,7 @@ mod tests { &TokenStream::new(), &TokenStream::new(), EntityFormat::Compact, + Default::default(), ) .to_string(), quote!( diff --git a/sea-orm-codegen/src/entity/writer/oxide.rs b/sea-orm-codegen/src/entity/writer/oxide.rs index cdc818bc2a..cfb1979512 100644 --- a/sea-orm-codegen/src/entity/writer/oxide.rs +++ b/sea-orm-codegen/src/entity/writer/oxide.rs @@ -40,10 +40,35 @@ impl EntityWriter { imports.extend(Self::gen_import_serde(with_serde)); imports.extend(Self::gen_import_active_enum(entity)); + imports.extend(Self::gen_import_uuid(entity)); imports } + /// The oxide format is generated without a prelude, so any type named by + /// bare identifier in the model struct needs an explicit import here. + pub fn gen_import_uuid(entity: &Entity) -> TokenStream { + fn has_uuid(col_type: &sea_query::ColumnType) -> bool { + match col_type { + sea_query::ColumnType::Uuid => true, + sea_query::ColumnType::Array(inner) => has_uuid(inner), + _ => false, + } + } + + if entity + .columns + .iter() + .any(|col| has_uuid(col.get_inner_col_type())) + { + quote! { + use uuid::Uuid; + } + } else { + TokenStream::new() + } + } + #[allow(clippy::too_many_arguments)] pub fn gen_oxide_model_struct( entity: &Entity, @@ -199,3 +224,63 @@ impl EntityWriter { } } } + +#[cfg(test)] +mod tests { + use crate::{Column, Entity, EntityWriter}; + use sea_query::{ColumnType, RcOrArc}; + + fn column(name: &str, col_type: ColumnType) -> Column { + Column { + name: name.to_owned(), + col_type, + auto_increment: false, + not_null: true, + unique: false, + unique_key: None, + } + } + + fn entity(columns: Vec) -> Entity { + Entity { + table_name: "test".to_owned(), + columns, + relations: vec![], + conjunct_relations: vec![], + primary_keys: vec![], + } + } + + #[test] + fn gen_import_uuid_emits_import_for_uuid_column() { + let entity = entity(vec![ + column("id", ColumnType::BigInteger), + column("uuid", ColumnType::Uuid), + ]); + assert_eq!( + EntityWriter::gen_import_uuid(&entity).to_string(), + "use uuid :: Uuid ;" + ); + } + + #[test] + fn gen_import_uuid_emits_import_for_uuid_array_column() { + let entity = entity(vec![column( + "uuids", + ColumnType::Array(RcOrArc::new(ColumnType::Uuid)), + )]); + assert_eq!( + EntityWriter::gen_import_uuid(&entity).to_string(), + "use uuid :: Uuid ;" + ); + } + + #[test] + fn gen_import_uuid_emits_nothing_without_uuid_column() { + let entity = entity(vec![ + column("id", ColumnType::BigInteger), + column("name", ColumnType::Text), + ]); + assert!(EntityWriter::gen_import_uuid(&entity).is_empty()); + } +} From 57b355376b1e4e366cf67e8062e4ce5bf5a3bf33 Mon Sep 17 00:00:00 2001 From: Matt Thompson Date: Mon, 24 Aug 2026 07:42:16 +0100 Subject: [PATCH 2/2] Remove comment --- sea-orm-codegen/src/entity/writer/oxide.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/sea-orm-codegen/src/entity/writer/oxide.rs b/sea-orm-codegen/src/entity/writer/oxide.rs index cfb1979512..310db0e7f9 100644 --- a/sea-orm-codegen/src/entity/writer/oxide.rs +++ b/sea-orm-codegen/src/entity/writer/oxide.rs @@ -45,8 +45,6 @@ impl EntityWriter { imports } - /// The oxide format is generated without a prelude, so any type named by - /// bare identifier in the model struct needs an explicit import here. pub fn gen_import_uuid(entity: &Entity) -> TokenStream { fn has_uuid(col_type: &sea_query::ColumnType) -> bool { match col_type {