trying to rework database migrations
This commit is contained in:
@@ -138,6 +138,7 @@ pub async fn create_pack(
|
||||
tags: request.tags,
|
||||
runtime_deps: request.runtime_deps,
|
||||
is_standard: request.is_standard,
|
||||
installers: serde_json::json!({}),
|
||||
};
|
||||
|
||||
let pack = PackRepository::create(&state.db, pack_input).await?;
|
||||
@@ -220,6 +221,7 @@ pub async fn update_pack(
|
||||
tags: request.tags,
|
||||
runtime_deps: request.runtime_deps,
|
||||
is_standard: request.is_standard,
|
||||
installers: None,
|
||||
};
|
||||
|
||||
let pack = PackRepository::update(&state.db, existing_pack.id, update_input).await?;
|
||||
@@ -527,6 +529,7 @@ async fn register_pack_internal(
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
is_standard: false,
|
||||
installers: serde_json::json!({}),
|
||||
};
|
||||
|
||||
let pack = PackRepository::create(&state.db, pack_input).await?;
|
||||
@@ -624,12 +627,10 @@ pub async fn install_pack(
|
||||
StatusCode,
|
||||
Json<crate::dto::ApiResponse<PackInstallResponse>>,
|
||||
)> {
|
||||
use attune_common::models::CreatePackInstallation;
|
||||
use attune_common::pack_registry::{
|
||||
calculate_directory_checksum, DependencyValidator, PackInstaller, PackStorage,
|
||||
};
|
||||
use attune_common::repositories::List;
|
||||
use attune_common::repositories::PackInstallationRepository;
|
||||
|
||||
tracing::info!("Installing pack from source: {}", request.source);
|
||||
|
||||
@@ -782,34 +783,26 @@ pub async fn install_pack(
|
||||
.ok();
|
||||
|
||||
// Store installation metadata
|
||||
let installation_repo = PackInstallationRepository::new(state.db.clone());
|
||||
let (source_url, source_ref) =
|
||||
get_source_metadata(&source, &request.source, request.ref_spec.as_deref());
|
||||
|
||||
let installation_metadata = CreatePackInstallation {
|
||||
PackRepository::update_installation_metadata(
|
||||
&state.db,
|
||||
pack_id,
|
||||
source_type: source_type.to_string(),
|
||||
source_type.to_string(),
|
||||
source_url,
|
||||
source_ref,
|
||||
checksum: checksum.clone(),
|
||||
checksum_verified: installed.checksum.is_some() && checksum.is_some(),
|
||||
installed_by: user_id,
|
||||
installation_method: "api".to_string(),
|
||||
storage_path: final_path.to_string_lossy().to_string(),
|
||||
meta: Some(serde_json::json!({
|
||||
"original_source": request.source,
|
||||
"force": request.force,
|
||||
"skip_tests": request.skip_tests,
|
||||
})),
|
||||
};
|
||||
|
||||
installation_repo
|
||||
.create(installation_metadata)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::warn!("Failed to store installation metadata: {}", e);
|
||||
ApiError::DatabaseError(format!("Failed to store installation metadata: {}", e))
|
||||
})?;
|
||||
checksum.clone(),
|
||||
installed.checksum.is_some() && checksum.is_some(),
|
||||
user_id,
|
||||
"api".to_string(),
|
||||
final_path.to_string_lossy().to_string(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::warn!("Failed to store installation metadata: {}", e);
|
||||
ApiError::DatabaseError(format!("Failed to store installation metadata: {}", e))
|
||||
})?;
|
||||
|
||||
// Clean up temp directory
|
||||
let _ = installer.cleanup(&installed.path).await;
|
||||
|
||||
@@ -434,6 +434,7 @@ pub async fn create_test_pack(pool: &PgPool, ref_name: &str) -> Result<Pack> {
|
||||
tags: vec!["test".to_string()],
|
||||
runtime_deps: vec![],
|
||||
is_standard: false,
|
||||
installers: json!({}),
|
||||
};
|
||||
|
||||
Ok(PackRepository::create(pool, input).await?)
|
||||
|
||||
@@ -12,7 +12,7 @@ mod helpers;
|
||||
use attune_common::{
|
||||
models::Pack,
|
||||
pack_registry::calculate_directory_checksum,
|
||||
repositories::{pack::PackRepository, pack_installation::PackInstallationRepository, List},
|
||||
repositories::{pack::PackRepository, List},
|
||||
};
|
||||
use helpers::{Result, TestContext};
|
||||
use serde_json::json;
|
||||
@@ -351,19 +351,18 @@ async fn test_install_pack_metadata_tracking() -> Result<()> {
|
||||
let pack_id = body["data"]["pack"]["id"].as_i64().unwrap();
|
||||
|
||||
// Verify installation metadata was created
|
||||
let installation_repo = PackInstallationRepository::new(ctx.pool.clone());
|
||||
let installation = installation_repo
|
||||
.get_by_pack_id(pack_id)
|
||||
let pack = PackRepository::find_by_id(&ctx.pool, pack_id)
|
||||
.await?
|
||||
.expect("Should have installation record");
|
||||
.expect("Should have pack record");
|
||||
|
||||
assert_eq!(installation.pack_id, pack_id);
|
||||
assert_eq!(installation.source_type, "local_directory");
|
||||
assert!(installation.source_url.is_some());
|
||||
assert!(installation.checksum.is_some());
|
||||
assert_eq!(pack.id, pack_id);
|
||||
assert_eq!(pack.source_type.as_deref(), Some("local_directory"));
|
||||
assert!(pack.source_url.is_some());
|
||||
assert!(pack.checksum.is_some());
|
||||
assert!(pack.installed_at.is_some());
|
||||
|
||||
// Verify checksum matches
|
||||
let stored_checksum = installation.checksum.as_ref().unwrap();
|
||||
let stored_checksum = pack.checksum.as_ref().unwrap();
|
||||
assert_eq!(
|
||||
stored_checksum, &original_checksum,
|
||||
"Stored checksum should match calculated checksum"
|
||||
@@ -451,13 +450,14 @@ async fn test_install_pack_storage_path_created() -> Result<()> {
|
||||
let pack_id = body["data"]["pack"]["id"].as_i64().unwrap();
|
||||
|
||||
// Verify installation metadata has storage path
|
||||
let installation_repo = PackInstallationRepository::new(ctx.pool.clone());
|
||||
let installation = installation_repo
|
||||
.get_by_pack_id(pack_id)
|
||||
let pack = PackRepository::find_by_id(&ctx.pool, pack_id)
|
||||
.await?
|
||||
.expect("Should have installation record");
|
||||
.expect("Should have pack record");
|
||||
|
||||
let storage_path = &installation.storage_path;
|
||||
let storage_path = pack
|
||||
.storage_path
|
||||
.as_ref()
|
||||
.expect("Should have storage path");
|
||||
assert!(
|
||||
storage_path.contains("storage-test"),
|
||||
"Storage path should contain pack ref"
|
||||
|
||||
@@ -42,6 +42,7 @@ async fn setup_test_pack_and_action(pool: &PgPool) -> Result<(Pack, Action)> {
|
||||
tags: vec!["test".to_string()],
|
||||
runtime_deps: vec![],
|
||||
is_standard: false,
|
||||
installers: json!({}),
|
||||
};
|
||||
let pack = PackRepository::create(pool, pack_input).await?;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ async fn create_test_pack(state: &AppState, name: &str) -> i64 {
|
||||
tags: vec![],
|
||||
runtime_deps: vec![],
|
||||
is_standard: false,
|
||||
installers: json!({}),
|
||||
};
|
||||
|
||||
let pack = PackRepository::create(&state.db, input)
|
||||
|
||||
@@ -48,6 +48,7 @@ async fn create_test_pack(state: &AppState, name: &str) -> i64 {
|
||||
tags: vec![],
|
||||
runtime_deps: vec![],
|
||||
is_standard: false,
|
||||
installers: json!({}),
|
||||
};
|
||||
|
||||
let pack = PackRepository::create(&state.db, input)
|
||||
|
||||
Reference in New Issue
Block a user