Skip to content

Commit

Permalink
Parse Postgres citext as Type::Unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jan 4, 2023
1 parent 1cb5db2 commit ea1bd52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/postgres/parser/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,19 @@ pub fn parse_array_attributes(

impl ColumnInfo {
pub fn parse_enum_variants(mut self, enums: &HashMap<String, Vec<String>>) -> Self {
let mut enum_name = None;
let mut no_enum_variants = true;
if let Type::Enum(ref mut enum_def) = self.col_type {
enum_name = Some(&enum_def.typename);
if let Some(def) = enums.get(&enum_def.typename) {
enum_def.values = def.clone()
no_enum_variants = def.is_empty();
enum_def.values = def.clone();
}
}
// An enum column without any variants will be treated as unknown column type
if let (Some(enum_name), true) = (enum_name, no_enum_variants) {
self.col_type = Type::Unknown(enum_name.into());
}
self
}
}
10 changes: 10 additions & 0 deletions tests/live/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ async fn main() {
let connection = setup(&url, "sea-schema").await;
let mut executor = connection.acquire().await.unwrap();

sqlx::query("CREATE EXTENSION IF NOT EXISTS citext")
.execute(&mut executor)
.await
.unwrap();

let create_enum_stmt = Type::create()
.as_enum(Alias::new("crazy_enum"))
.values(vec![
Expand Down Expand Up @@ -337,5 +342,10 @@ fn create_collection_table() -> TableCreateStatement {
.not_null(),
)
.col(ColumnDef::new(Alias::new("integers_opt")).array(ColumnType::Integer))
.col(
ColumnDef::new(Alias::new("case_insensitive_text"))
.custom(Alias::new("citext"))
.not_null(),
)
.to_owned()
}

0 comments on commit ea1bd52

Please sign in to comment.