Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registry(v1): save Configuration and LoadableLibraries on publish #551

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions registry/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1414,21 +1414,6 @@
},
"query": "SELECT * FROM extension_detail_vw"
},
"cff34205e2334651e696df107dac775cff18f102ca67898d9d68303ddfa314c5": {
"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)"
},
"e41ccd0b4b07c1761d78d4de2efdba33979114f1b055db3261af653afca8be56": {
"describe": {
"columns": [],
Expand Down Expand Up @@ -1480,6 +1465,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": [],
Expand Down
9 changes: 4 additions & 5 deletions registry/src/openapi.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -17,8 +16,8 @@ use crate::v1::routes as v1;
),
components(schemas(
ExtensionView,
ExtensionPreloadLibrariesView,
ExtensionConfigurationView,
LoadableLibrary,
ExtensionConfiguration,
TrunkProjectView,
))
)]
Expand Down
2 changes: 1 addition & 1 deletion registry/src/routes/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ async fn insert_into_v1(
gzipped_archive: &[u8],
) -> anyhow::Result<()> {
let extension_views =
crate::v1::extractor::extract_extension_view(gzipped_archive, &new_extension.name)?;
crate::v1::extractor::extract_extension_view(gzipped_archive, &new_extension)?;

let trunk_project = TrunkProjectView {
name: new_extension.name,
Expand Down
11 changes: 7 additions & 4 deletions registry/src/v1/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{
};
use tar::EntryType;

use crate::views::extension_publish::ExtensionUpload;

use super::repository::ExtensionView;

pub struct ControlFile {
Expand All @@ -16,7 +18,7 @@ pub struct ControlFile {

pub fn extract_extension_view(
tar_gz: &[u8],
trunk_project_name: &str,
new_extension: &ExtensionUpload,
) -> anyhow::Result<Vec<ExtensionView>> {
let control_files = extract_control_files(tar_gz)?;

Expand All @@ -25,10 +27,11 @@ pub fn extract_extension_view(
.map(|control_file| ExtensionView {
extension_name: control_file.extension_name,
version: control_file.default_version.unwrap_or_default(),
trunk_project_name: trunk_project_name.to_string(),
trunk_project_name: new_extension.name.to_string(),
dependencies_extension_names: control_file.dependencies,
loadable_libraries: None,
configurations: None,
// TODO: should we clone this for every extension in a Trunk project?
loadable_libraries: new_extension.libraries.clone(),
configurations: new_extension.configurations.clone(),
})
.collect();

Expand Down
72 changes: 40 additions & 32 deletions registry/src/v1/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,28 +15,14 @@ pub struct TrunkProjectView {
pub extensions: Vec<ExtensionView>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct ExtensionConfigurationView {
pub name: String,
pub is_required: bool,
pub recommended_default: Option<String>,
}

#[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<Vec<String>>,
pub loadable_libraries: Option<Vec<ExtensionPreloadLibrariesView>>,
pub configurations: Option<Vec<ExtensionConfigurationView>>,
pub loadable_libraries: Option<Vec<LoadableLibrary>>,
pub configurations: Option<Vec<ExtensionConfiguration>>,
}

impl Registry {
Expand Down Expand Up @@ -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<Item = &ExtensionConfiguration>,
) -> 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<Item = &LoadableLibrary>,
) -> 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(())
}
}
20 changes: 18 additions & 2 deletions registry/src/views/extension_publish.rs
Original file line number Diff line number Diff line change
@@ -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<String, Vec<String>>;

Expand All @@ -17,5 +18,20 @@ pub struct ExtensionUpload {
pub repository: Option<String>,
pub categories: Option<Vec<String>>,
pub system_dependencies: Option<SystemDependencies>,
pub libraries: Option<Vec<String>>,
pub libraries: Option<Vec<LoadableLibrary>>,
pub configurations: Option<Vec<ExtensionConfiguration>>,
}

#[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<String>,
}
Loading