fix(describer): do not assume we know indexes' tables
On PostgreSQL. We might not have permissions to read, etc. so we can't
assume we have a table corresponding to an index we read from the
catalog.
closes
closes
@@ -1030,7 +1030,13 @@ impl<'a> SqlSchemaDescriber<'a> {
let is_unique = row.get_expect_bool("is_unique");
let is_primary_key = row.get_expect_bool("is_primary_key");
let table_name = row.get_expect_string("table_name");
- let table_id = table_ids[table_name.as_str()];
+ let index_algo = row.get_expect_string("index_algo");
+
+ let table_id: TableId = if let Some(id) = table_ids.get(table_name.as_str()) {
+ *id
+ } else {
+ continue; // skip indexes on tables we do not know about (permissions, etc.)
+ };
let sort_order = row.get_string("column_order").map(|v| match v.as_ref() {
"ASC" => SQLSortOrder::Asc,
@@ -1042,12 +1048,12 @@ impl<'a> SqlSchemaDescriber<'a> {
});
let algorithm = if self.is_cockroach() {
- match row.get_expect_string("index_algo").as_str() {
+ match index_algo.as_str() {
"inverted" => SqlIndexAlgorithm::Gin,
_ => SqlIndexAlgorithm::BTree,
}
} else {
- match row.get_expect_string("index_algo").as_str() {
+ match index_algo.as_str() {
"btree" => SqlIndexAlgorithm::BTree,
"hash" => SqlIndexAlgorithm::Hash,
"gist" => SqlIndexAlgorithm::Gist,
