diff --git a/compute_tools/src/spec.rs b/compute_tools/src/spec.rs index e0c0e9404b..28717ec0f6 100644 --- a/compute_tools/src/spec.rs +++ b/compute_tools/src/spec.rs @@ -425,7 +425,28 @@ pub fn handle_grants(node: &ComputeNode, client: &mut Client) -> Result<()> { // Explicitly grant CREATE ON SCHEMA PUBLIC to the web_access user. // This is needed since postgres 15, where this privilege is removed by default. - let grant_query: String = "GRANT CREATE ON SCHEMA public TO web_access".to_string(); + let grant_query = "DO $$\n\ + BEGIN\n\ + IF EXISTS(\n\ + SELECT nspname\n\ + FROM pg_catalog.pg_namespace\n\ + WHERE nspname = 'public'\n\ + ) AND\n\ + version() LIKE 'PostgreSQL 15%'\n\ + THEN\n\ + IF EXISTS(\n\ + SELECT rolname\n\ + FROM pg_catalog.pg_roles\n\ + WHERE rolname = 'web_access'\n\ + )\n\ + THEN\n\ + GRANT CREATE ON SCHEMA public TO web_access;\n\ + END IF;\n\ + END IF;\n\ + END\n\ + $$;" + .to_string(); + info!("grant query for db {} : {}", &db.name, &grant_query); db_client.simple_query(&grant_query)?; }