fix(backend): include empty schemas in list_datatable_schemas endpoint (#7708)

The endpoint now returns all non-system schemas, including empty ones
without tables. This is useful for CLI and frontend features that need
to know about available schemas for autocompletion and app creation.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
centdix
2026-01-27 19:14:26 +01:00
committed by GitHub
parent 564d8266dc
commit 705bc48131
+39 -15
View File
@@ -1336,31 +1336,55 @@ async fn get_datatable_schema(db: &DB, w_id: &str, datatable_name: &str) -> Resu
}
});
// Query the schema information
let rows = client
// First, get all non-system schemas (including empty ones)
let schema_rows = client
.query(
r#"
SELECT
nsp.nspname::text AS table_schema,
c.table_name::text,
c.column_name::text,
c.udt_name::text,
c.is_nullable::text,
c.column_default::text
FROM information_schema.columns c
JOIN pg_namespace nsp ON c.table_schema = nsp.nspname
WHERE nsp.nspname NOT IN ('information_schema', 'pg_toast', 'pg_catalog')
AND c.table_name IS NOT NULL
ORDER BY c.table_schema, c.table_name, c.ordinal_position
SELECT nspname::text AS schema_name
FROM pg_namespace
WHERE nspname NOT IN ('information_schema', 'pg_toast', 'pg_catalog')
AND nspname NOT LIKE 'pg_%'
ORDER BY nspname
"#,
&[],
)
.await
.map_err(|e| Error::internal_err(format!("Failed to query schema: {}", e)))?;
.map_err(|e| Error::internal_err(format!("Failed to query schemas: {}", e)))?;
// Build hierarchical structure: schema -> table -> column -> compact_type
let mut schema_map: SchemaMap = HashMap::new();
// Collect schema names and initialize map
let schema_names: Vec<String> = schema_rows
.iter()
.map(|row| {
let name: String = row.get(0);
schema_map.entry(name.clone()).or_default();
name
})
.collect();
// Query column information only for the schemas we found
let rows = client
.query(
r#"
SELECT
table_schema::text,
table_name::text,
column_name::text,
udt_name::text,
is_nullable::text,
column_default::text
FROM information_schema.columns
WHERE table_schema = ANY($1)
AND table_name IS NOT NULL
ORDER BY table_schema, table_name, ordinal_position
"#,
&[&schema_names],
)
.await
.map_err(|e| Error::internal_err(format!("Failed to query columns: {}", e)))?;
for row in rows {
let table_schema: String = row.get(0);
let table_name: String = row.get(1);