Skip to content

Commit 6b0f086

Browse files
committed
postgres: include enums in schema
1 parent 65f544c commit 6b0f086

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/postgres/def/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::*;
88
pub struct Schema {
99
pub schema: String,
1010
pub tables: Vec<TableDef>,
11+
pub enums: Vec<EnumDef>,
1112
}
1213

1314
#[derive(Clone, Debug, PartialEq)]

src/postgres/discovery/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ impl SchemaDiscovery {
5959

6060
#[doc(hidden)]
6161
pub async fn discover_with<C: Connection>(&self, conn: &C) -> Result<Schema, SqlxError> {
62-
let enums: EnumVariantMap = self
63-
.discover_enums_with(conn)
64-
.await?
65-
.into_iter()
66-
.map(|enum_def| (enum_def.typename, enum_def.values))
62+
let enums = self.discover_enums_with(conn).await?;
63+
let enum_map: EnumVariantMap = enums
64+
.iter()
65+
.map(|enum_def| (enum_def.typename.clone(), enum_def.values.clone()))
6766
.collect();
6867

6968
let mut tables = Vec::new();
7069
for table in self.discover_tables_with(conn).await? {
71-
tables.push(self.discover_table_with(conn, table, &enums).await?);
70+
tables.push(self.discover_table_with(conn, table, &enum_map).await?);
7271
}
7372

7473
Ok(Schema {
7574
schema: self.schema.to_string(),
7675
tables,
76+
enums,
7777
})
7878
}
7979

0 commit comments

Comments
 (0)