Respond with extension name and version

This commit is contained in:
Jere Vaara
2024-10-10 12:51:53 +03:00
parent a766ac3dc7
commit 2b5d79f625
4 changed files with 44 additions and 7 deletions

View File

@@ -1368,7 +1368,7 @@ LIMIT 100",
download_size
}
pub fn install_extension(&self, ext_name: &str, db_name: &str) -> Result<()> {
pub fn install_extension(&self, ext_name: &str, db_name: &str) -> Result<String> {
let mut conf =
Config::from_str(self.connstr.as_str()).context("Failed to parse connection string")?;
conf.dbname(db_name);
@@ -1387,7 +1387,17 @@ LIMIT 100",
.execute(&query, &[])
.context(format!("Failed to execute query: {}", query))?;
Ok(())
let version_query = format!(
"SELECT extversion FROM pg_extension WHERE extname = '{}'",
ext_name.to_string().pg_quote()
);
let version: String = db_client
.query_one(&version_query, &[])
.context(format!("Failed to execute query: {}", version_query))?
.get(0);
Ok(version)
}
#[tokio::main]

View File

@@ -10,6 +10,7 @@ use crate::catalog::{get_database_schema, get_dbs_and_roles};
use crate::compute::forward_termination_signal;
use crate::compute::{ComputeNode, ComputeState, ParsedSpec};
use compute_api::requests::ConfigurationRequest;
use compute_api::responses::ExtensionInstallResult;
use compute_api::responses::{ComputeStatus, ComputeStatusResponse, GenericAPIError};
use anyhow::Result;
@@ -116,7 +117,13 @@ async fn routes(req: Request<Body>, compute: &Arc<ComputeNode>) -> Response<Body
let database = body["database"].as_str().unwrap();
let res = compute.install_extension(extension, database);
match res {
Ok(_) => Response::new(Body::from("true")),
Ok(res) => render_json(Body::from(
serde_json::to_string(&ExtensionInstallResult {
extension: extension.to_string(),
version: res,
})
.unwrap(),
)),
Err(e) => {
error!("install_extension failed: {}", e);
render_json_error(&e.to_string(), StatusCode::INTERNAL_SERVER_ERROR)

View File

@@ -173,11 +173,15 @@ paths:
200:
description: Result from extension installation
content:
text/plain:
application/json:
schema:
type: string
description: Error text or 'true' if extension was installed.
example: "true"
$ref: "#/components/schemas/ExtensionInstallResult"
500:
description: Error during extension installation.
content:
application/json:
schema:
$ref: "#/components/schemas/GenericError"
/configure:
post:
@@ -444,6 +448,16 @@ components:
- configuration
example: running
ExtensionInstallResult:
type: object
properties:
extension:
description: Name of the extension.
type: string
version:
description: Version of the extension.
type: string
InstalledExtensions:
type: object
properties:

View File

@@ -168,3 +168,9 @@ pub struct InstalledExtension {
pub struct InstalledExtensions {
pub extensions: Vec<InstalledExtension>,
}
#[derive(Clone, Debug, Default, Serialize)]
pub struct ExtensionInstallResult {
pub extension: String,
pub version: String,
}