diff --git a/registry/sqlx-data.json b/registry/sqlx-data.json index 679efef3..0bb35712 100644 --- a/registry/sqlx-data.json +++ b/registry/sqlx-data.json @@ -1480,6 +1480,21 @@ }, "query": "\n UPDATE categories\n SET extension_count = extension_count + 1\n WHERE id = $1\n " }, + "f5c4444586051427aaf351b423d8dba82b213eef6e707a1cf5b54854769ce1b9": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Int4", + "Text", + "Bool", + "Int4" + ] + } + }, + "query": "INSERT INTO v1.extensions_loadable_libraries (extension_version_id, library_name, requires_restart, priority)\n VALUES ($1, $2, $3, $4)" + }, "f77d6c607d830e7ea1d564c34ec42b998e0c2657f4cdb8a89dd211a29b4a7d65": { "describe": { "columns": [], diff --git a/registry/src/openapi.rs b/registry/src/openapi.rs index 21e719e6..0cca7c43 100644 --- a/registry/src/openapi.rs +++ b/registry/src/openapi.rs @@ -1,10 +1,9 @@ use utoipa::openapi::License; use utoipa::OpenApi; -use crate::v1::repository::{ - ExtensionConfigurationView, ExtensionPreloadLibrariesView, ExtensionView, TrunkProjectView, -}; +use crate::v1::repository::{ExtensionView, TrunkProjectView}; use crate::v1::routes as v1; +use crate::views::extension_publish::{ExtensionConfiguration, LoadableLibrary}; // v1 API documentation #[derive(OpenApi)] @@ -17,8 +16,8 @@ use crate::v1::routes as v1; ), components(schemas( ExtensionView, - ExtensionPreloadLibrariesView, - ExtensionConfigurationView, + LoadableLibrary, + ExtensionConfiguration, TrunkProjectView, )) )] diff --git a/registry/src/routes/extensions.rs b/registry/src/routes/extensions.rs index 2645f59c..08ba02ab 100644 --- a/registry/src/routes/extensions.rs +++ b/registry/src/routes/extensions.rs @@ -89,9 +89,17 @@ pub async fn publish( .fetch_optional(&mut tx) .await?; + // TODO(vini): change here let system_deps = serde_json::to_value(&new_extension.system_dependencies)?; let libraries = serde_json::to_value(&new_extension.libraries)?; + // Save configurations and libraries to the v1 tables + { + if let Some(configs) = &new_extension.configurations {} + + if let Some(libraries) = &new_extension.libraries {} + } + match exists { // TODO(ianstanton) Refactor into separate functions Some(exists) => { diff --git a/registry/src/v1/repository.rs b/registry/src/v1/repository.rs index 0b008437..7983eb4c 100644 --- a/registry/src/v1/repository.rs +++ b/registry/src/v1/repository.rs @@ -3,6 +3,7 @@ use utoipa::{ToResponse, ToSchema}; use crate::errors::Result; use crate::repository::Registry; +use crate::views::extension_publish::{ExtensionConfiguration, LoadableLibrary}; #[derive(Debug, Clone, Serialize, Deserialize, ToSchema, ToResponse)] pub struct TrunkProjectView { @@ -14,28 +15,14 @@ pub struct TrunkProjectView { pub extensions: Vec, } -#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)] -pub struct ExtensionConfigurationView { - pub name: String, - pub is_required: bool, - pub recommended_default: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -pub struct ExtensionPreloadLibrariesView { - library_name: String, - requires_restart: bool, - priority: i32, -} - #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ExtensionView { pub extension_name: String, pub version: String, pub trunk_project_name: String, pub dependencies_extension_names: Option>, - pub loadable_libraries: Option>, - pub configurations: Option>, + pub loadable_libraries: Option>, + pub configurations: Option>, } impl Registry { @@ -360,29 +347,50 @@ impl Registry { } // 5. insert extension configurations - for config in configurations { - sqlx::query!( + self.insert_configurations(extension_version_id, configurations) + .await?; + + // 6. insert shared preload libraries + self.insert_loadable_libraries(extension_version_id, loadable_libraries) + .await?; + } + Ok(()) + } + + async fn insert_configurations( + &self, + extension_version_id: i32, + configurations: impl Iterator, + ) -> Result { + for config in configurations { + sqlx::query!( "INSERT INTO v1.extension_configurations (extension_version_id, is_required, configuration_name, recommended_default_value) VALUES ($1, $2, $3, $4)", extension_version_id, config.is_required, - config.name, - config.recommended_default, + config.configuration_name, + config.recommended_default_value, ).execute(&self.pool).await?; - } + } + Ok(()) + } - // 6. insert shared preload libraries - for library in loadable_libraries { - sqlx::query!( - "INSERT INTO v1.extensions_loadable_libraries (extension_version_id, library_name, requires_restart, priority) - VALUES ($1, $2, $3, $4)", - extension_version_id, - library.library_name, - library.requires_restart, - library.priority, - ).execute(&self.pool).await?; - } + async fn insert_loadable_libraries( + &self, + extension_version_id: i32, + loadable_libraries: impl Iterator, + ) -> Result { + for library in loadable_libraries { + sqlx::query!( + "INSERT INTO v1.extensions_loadable_libraries (extension_version_id, library_name, requires_restart, priority) + VALUES ($1, $2, $3, $4)", + extension_version_id, + library.library_name, + library.requires_restart, + library.priority, + ).execute(&self.pool).await?; } + Ok(()) } } diff --git a/registry/src/views/extension_publish.rs b/registry/src/views/extension_publish.rs index 18a70139..ff5c16f4 100644 --- a/registry/src/views/extension_publish.rs +++ b/registry/src/views/extension_publish.rs @@ -1,7 +1,8 @@ //! This module handles the expected information an extension should have use std::collections::HashMap; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; pub type SystemDependencies = HashMap>; @@ -17,5 +18,20 @@ pub struct ExtensionUpload { pub repository: Option, pub categories: Option>, pub system_dependencies: Option, - pub libraries: Option>, + pub libraries: Option>, + pub configurations: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct LoadableLibrary { + pub library_name: String, + pub requires_restart: bool, + pub priority: i32, +} + +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct ExtensionConfiguration { + pub configuration_name: String, + pub is_required: bool, + pub recommended_default_value: Option, }