fix(highgo): preserve nullable metadata for pg-compatible agents (#1585)
This commit is contained in:
4 files changed
+93
-3
No files matched your search
@@ -1166,7 +1166,7 @@ pub async fn list_schemas(pool: &Pool) -> Result<Vec<String>, String> {
|
||||
|
||||
const POSTGRES_COLUMNS_SQL: &str = "SELECT a.attname AS column_name, \
|
||||
format_type(a.atttypid, a.atttypmod) AS full_type, \
|
||||
NOT a.attnotnull AS is_nullable, \
|
||||
COALESCE(c.is_nullable = 'YES', NOT a.attnotnull) AS is_nullable, \
|
||||
CASE WHEN a.attgenerated <> '' THEN NULL ELSE pg_get_expr(ad.adbin, ad.adrelid) END AS column_default, \
|
||||
EXISTS ( \
|
||||
SELECT 1 FROM pg_constraint co \
|
||||
@@ -1195,13 +1195,15 @@ const POSTGRES_COLUMNS_SQL: &str = "SELECT a.attname AS column_name, \
|
||||
LEFT JOIN pg_attrdef ad ON ad.adrelid = a.attrelid AND ad.adnum = a.attnum \
|
||||
LEFT JOIN pg_depend dep ON dep.refobjid = a.attrelid AND dep.refobjsubid = a.attnum AND dep.deptype = 'i' \
|
||||
LEFT JOIN pg_sequence pseq ON pseq.seqrelid = dep.objid \
|
||||
LEFT JOIN information_schema.columns c \
|
||||
ON c.table_schema = $1 AND c.table_name = $2 AND c.column_name = a.attname \
|
||||
WHERE a.attrelid = (quote_ident($1) || '.' || quote_ident($2))::regclass \
|
||||
AND a.attnum > 0 AND NOT a.attisdropped \
|
||||
ORDER BY a.attnum";
|
||||
|
||||
const POSTGRES_COLUMNS_COMPAT_SQL: &str = "SELECT a.attname AS column_name, \
|
||||
format_type(a.atttypid, a.atttypmod) AS full_type, \
|
||||
NOT a.attnotnull AS is_nullable, \
|
||||
COALESCE(c.is_nullable = 'YES', NOT a.attnotnull) AS is_nullable, \
|
||||
pg_get_expr(ad.adbin, ad.adrelid) AS column_default, \
|
||||
EXISTS ( \
|
||||
SELECT 1 FROM pg_constraint co \
|
||||
@@ -1220,6 +1222,8 @@ const POSTGRES_COLUMNS_COMPAT_SQL: &str = "SELECT a.attname AS column_name, \
|
||||
FROM pg_attribute a \
|
||||
JOIN pg_type t ON t.oid = a.atttypid \
|
||||
LEFT JOIN pg_attrdef ad ON ad.adrelid = a.attrelid AND ad.adnum = a.attnum \
|
||||
LEFT JOIN information_schema.columns c \
|
||||
ON c.table_schema = $1 AND c.table_name = $2 AND c.column_name = a.attname \
|
||||
WHERE a.attrelid = (quote_ident($1) || '.' || quote_ident($2))::regclass \
|
||||
AND a.attnum > 0 AND NOT a.attisdropped \
|
||||
ORDER BY a.attnum";
|
||||
@@ -2325,6 +2329,8 @@ mod tests {
|
||||
assert!(POSTGRES_COLUMNS_SQL.contains("pg_sequence"));
|
||||
assert!(POSTGRES_COLUMNS_SQL.contains("generated by default as identity"));
|
||||
assert!(POSTGRES_COLUMNS_SQL.contains("generated always as identity"));
|
||||
assert!(POSTGRES_COLUMNS_SQL.contains("COALESCE(c.is_nullable = 'YES', NOT a.attnotnull)"));
|
||||
assert!(POSTGRES_COLUMNS_SQL.contains("LEFT JOIN information_schema.columns"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2333,6 +2339,8 @@ mod tests {
|
||||
assert!(!POSTGRES_COLUMNS_COMPAT_SQL.contains("pg_sequence"));
|
||||
assert!(POSTGRES_COLUMNS_COMPAT_SQL.contains("NULL::text AS column_extra"));
|
||||
assert!(POSTGRES_COLUMNS_COMPAT_SQL.contains("col_description"));
|
||||
assert!(POSTGRES_COLUMNS_COMPAT_SQL.contains("COALESCE(c.is_nullable = 'YES', NOT a.attnotnull)"));
|
||||
assert!(POSTGRES_COLUMNS_COMPAT_SQL.contains("LEFT JOIN information_schema.columns"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -2047,6 +2047,35 @@ pub async fn get_table_ddl_core(
|
||||
}
|
||||
if let Some(client) = extract_pool!(&connections, &pool_key, Agent) {
|
||||
drop(connections);
|
||||
if let Some(config) = db_config.as_ref().filter(|config| is_agent_postgres_metadata_fallback_config(config))
|
||||
{
|
||||
match native_postgres_metadata_pool(state, connection_id, database, config).await {
|
||||
Ok(Some(pool)) => match pg_ddl(&pool, schema, table).await {
|
||||
Ok(ddl) => return Ok(ddl),
|
||||
Err(error) => {
|
||||
log::warn!(
|
||||
"[schema][agent:get_table_ddl:postgres-compatible-native-fallback-failed] connection_id={} database={} schema={} table={} error={}",
|
||||
connection_id,
|
||||
database,
|
||||
schema,
|
||||
table,
|
||||
error
|
||||
);
|
||||
}
|
||||
},
|
||||
Ok(None) => {}
|
||||
Err(error) => {
|
||||
log::warn!(
|
||||
"[schema][agent:get_table_ddl:postgres-compatible-native-pool-failed] connection_id={} database={} schema={} table={} error={}",
|
||||
connection_id,
|
||||
database,
|
||||
schema,
|
||||
table,
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut client = client.lock().await;
|
||||
return client.get_table_ddl(database, schema, table, agent_metadata_timeout(db_config.as_ref())).await;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user