25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(redshift): use compatible object metadata catalogs
t8y23f939e045830
diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rsindex aba199f390..3fdec24de7 100644--- a/crates/dbx-core/src/db/postgres.rs+++ b/crates/dbx-core/src/db/postgres.rs@@ -4116,6 +4116,26 @@ fn list_object_routines_sql(include_timestamps: bool, has_proc_prokind: bool, haWHERE n.nspname = $1 AND NOT p.proisagg AND NOT p.proiswindow"}+fn redshift_routine_objects_sql() -> &'static str {+ "SELECT function_name AS object_name, \+ CASE function_type \+ WHEN 'STORED PROCEDURE' THEN 'PROCEDURE' \+ ELSE 'FUNCTION' \+ END AS object_type, \+ NULL::varchar AS object_comment, \+ NULL::varchar AS created_at, \+ NULL::varchar AS updated_at, \+ NULL::varchar AS parent_schema, \+ NULL::varchar AS parent_name, \+ argument_type AS signature, \+ CASE function_type WHEN 'STORED PROCEDURE' THEN 2 ELSE 3 END AS sort_order \+ FROM svv_redshift_functions \+ WHERE database_name = current_database() \+ AND schema_name = $1 \+ AND function_type IN ('STORED PROCEDURE', 'REGULAR FUNCTION') \+ ORDER BY sort_order, object_name"+}+/// SQL for listing user-defined types in one schema.////// Only explicitly created types are returned: base types (b), standalone@@ -4361,8 +4381,37 @@ pub async fn list_objects(}};- Ok(rows- .iter()+ Ok(object_rows_to_infos(&rows, schema))+}++pub async fn list_redshift_objects(+ pool: &Pool,+ schema: &str,+ include_relations: bool,+ include_routines: bool,+) -> Result<Vec<ObjectInfo>, String> {+ let client = checkout_postgres_client(pool, None, super::connection_timeout()).await?;+ let mut rows = Vec::new();++ if include_relations {+ // Redshift does not support PostgreSQL's generic file, object-location,+ // or transaction-ID helpers, so skip the timestamp variant entirely.+ rows = list_objects_rows(&client, schema, false, false, false, false, true, false, false).await?;+ }++ if include_routines {+ let routine_rows = client+ .query_typed(redshift_routine_objects_sql(), &[(&schema, Type::VARCHAR)])+ .await+ .map_err(|error| format!("Redshift routine metadata query failed: {error}"))?;+ rows.extend(routine_rows);+ }++ Ok(object_rows_to_infos(&rows, schema))+}++fn object_rows_to_infos(rows: &[Row], schema: &str) -> Vec<ObjectInfo> {+ rows.iter().map(|row| {let object_type = pg_row_try_string(row, 1);let raw_signature = row.try_get::<_, Option<String>>(7).ok().flatten();@@ -4389,7 +4438,7 @@ pub async fn list_objects(xugu_type_members_expandable: None,}})- .collect())+ .collect()}fn custom_type_list_metadata(value: Option<&str>) -> (Option<String>, Option<bool>) {@@ -10816,6 +10865,29 @@ mod tests {assert!(!sql.contains("pg_get_function_identity_arguments"));}+ #[test]+ fn redshift_routine_objects_sql_uses_supported_catalog_view() {+ let sql = redshift_routine_objects_sql();+ assert!(sql.contains("FROM svv_redshift_functions"));+ assert!(sql.contains("database_name = current_database()"));+ assert!(sql.contains("schema_name = $1"));+ assert!(sql.contains("'STORED PROCEDURE'"));+ assert!(sql.contains("'REGULAR FUNCTION'"));+ assert!(!sql.contains("pg_proc"));+ assert!(!sql.contains("pg_get_function"));+ assert!(!sql.contains("UNION"));+ }++ #[test]+ fn redshift_relation_objects_sql_avoids_unsupported_postgres_helpers() {+ let sql = list_objects_sql(false, false, false, false, true, false, false);+ assert!(sql.contains("pg_catalog.pg_class"));+ assert!(!sql.contains("pg_catalog.pg_proc"));+ assert!(!sql.contains("pg_stat_file"));+ assert!(!sql.contains("pg_relation_filepath"));+ assert!(!sql.contains("pg_xact_commit_timestamp"));+ }+#[test]fn redshift_columns_sql_uses_simple_information_schema_metadata() {let sql = redshift_columns_sql("tenant's", "orders");diff --git a/crates/dbx-core/src/schema.rs b/crates/dbx-core/src/schema.rsindex 580e44e59f..396dc19ae0 100644--- a/crates/dbx-core/src/schema.rs+++ b/crates/dbx-core/src/schema.rs@@ -5272,6 +5272,18 @@ struct ObjectListOutcome {paging_applied: bool,}+async fn list_native_postgres_objects(+ pool: &deadpool_postgres::Pool,+ config: &ConnectionConfig,+ schema: &str,+) -> Result<Vec<db::ObjectInfo>, String> {+ if config.db_type == DatabaseType::Redshift {+ db::postgres::list_redshift_objects(pool, schema, true, true).await+ } else {+ db::postgres::list_objects(pool, schema, true, true, false).await+ }+}+fn unpaged_object_list(objects: Vec<db::ObjectInfo>) -> ObjectListOutcome {ObjectListOutcome { objects, paging_applied: false }}@@ -5398,7 +5410,7 @@ async fn list_objects_once(if let Some(config) = fallback_config.as_ref() {match native_postgres_metadata_pool(state, connection_id, database, config).await {Ok(Some(pool)) => {- return db::postgres::list_objects(&pool, schema, true, true, false)+ return list_native_postgres_objects(&pool, config, schema).await.map(unpaged_object_list)}@@ -5427,7 +5439,7 @@ async fn list_objects_once(if let Some(pool) =native_postgres_metadata_pool(state, connection_id, database, config).await?{- return db::postgres::list_objects(&pool, schema, true, true, false)+ return list_native_postgres_objects(&pool, config, schema).await.map(unpaged_object_list).map_err(|fallback_error| {@@ -5473,6 +5485,13 @@ async fn list_objects_once(PoolKind::Postgres(p) if db_config.as_ref().is_some_and(is_cloudberry_config) => {db::cloudberry::list_objects(p, schema).await.map(unpaged_object_list)}+ PoolKind::Postgres(p) if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::Redshift) => {+ let include_relations = object_types_include_relations(object_types);+ let include_routines = object_types_include_routines(object_types);+ db::postgres::list_redshift_objects(p, schema, include_relations, include_routines)+ .await+ .map(unpaged_object_list)+ }PoolKind::Postgres(p) => {let include_relations = object_types_include_relations(object_types);let include_routines = object_types_include_routines(object_types);@@ -5549,7 +5568,7 @@ async fn list_completion_objects_once(if let Some(config) = fallback_config.as_ref() {match native_postgres_metadata_pool(state, connection_id, database, config).await {Ok(Some(pool)) => {- return db::postgres::list_objects(&pool, schema, true, true, false)+ return list_native_postgres_objects(&pool, config, schema).await.map(filter_completion_objects)}@@ -5574,7 +5593,7 @@ async fn list_completion_objects_once(if let Some(pool) =native_postgres_metadata_pool(state, connection_id, database, config).await?{- return db::postgres::list_objects(&pool, schema, true, true, false)+ return list_native_postgres_objects(&pool, config, schema).await.map(filter_completion_objects).map_err(|fallback_error| {@@ -5607,6 +5626,9 @@ async fn list_completion_objects_once(PoolKind::Postgres(p) if db_config.as_ref().is_some_and(is_cloudberry_config) => {db::cloudberry::list_objects(p, schema).await.map(filter_completion_objects)}+ PoolKind::Postgres(p) if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::Redshift) => {+ db::postgres::list_redshift_objects(p, schema, false, true).await.map(filter_completion_objects)+ }PoolKind::Postgres(p) => {db::postgres::list_objects(p, schema, true, true, false).await.map(filter_completion_objects)}