From fe5b97425fa08854b4f1ce37451166f8a81d54d2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 22 Feb 2021 10:44:19 +0100 Subject: Multiple release stores This patch adds the ability to have more than one release store. With this patch, a user can (has to) configure release store names in the configuration file, and can then specify one of the configured names to release the artifacts to. This way, different release "channels" can be served, for example a stable channel and a rolling release channel (although "channel" is not in our wording). The code was adapted to be able to fetch releases from multiple release directories, in the crate::db::find_artifact implementation, so that re-using artifacts works across all release directories. Signed-off-by: Matthias Beyer --- src/db/find_artifacts.rs | 11 +++++++---- src/db/models/artifact.rs | 4 +++- src/db/models/releases.rs | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/db') diff --git a/src/db/find_artifacts.rs b/src/db/find_artifacts.rs index e3e418d..b4fbe3b 100644 --- a/src/db/find_artifacts.rs +++ b/src/db/find_artifacts.rs @@ -54,7 +54,7 @@ pub fn find_artifacts<'a>( database_connection: Arc, config: &Configuration, pkg: &Package, - release_store: &'a ReleaseStore, + release_stores: &'a [Arc], staging_store: Option<&'a StagingStore>, additional_env: &[(EnvironmentVariableName, String)], script_filter: bool, @@ -220,11 +220,14 @@ pub fn find_artifacts<'a>( // If we cannot find the artifact in the release store either, we return None. // This is the case if there indeed was a release, but it was removed from the // filesystem. - if let Some(art) = release_store.get(&artpath) { - trace!("Found in release: {:?}", art); - return release_store.root_path().join(art).map(|p| p.map(|p| (p, ndt))) + for release_store in release_stores { + if let Some(art) = release_store.get(&artpath) { + trace!("Found in release: {:?}", art); + return release_store.root_path().join(art).map(|p| p.map(|p| (p, ndt))) + } } + trace!("Found no release for artifact {:?} in any release store", artpath.display()); Ok(None) }) .filter_map_ok(|opt| opt) diff --git a/src/db/models/artifact.rs b/src/db/models/artifact.rs index 11e2cec..e5adbaf 100644 --- a/src/db/models/artifact.rs +++ b/src/db/models/artifact.rs @@ -48,8 +48,10 @@ impl Artifact { self, database_connection: &PgConnection, release_date: &NaiveDateTime, + release_store_name: &str, ) -> Result { - crate::db::models::Release::create(database_connection, &self, release_date) + let rs = crate::db::models::ReleaseStore::create(database_connection, release_store_name)?; + crate::db::models::Release::create(database_connection, &self, release_date, &rs) } pub fn get_release(&self, database_connection: &PgConnection) -> Result> { diff --git a/src/db/models/releases.rs b/src/db/models/releases.rs index 9136fee..48e4f02 100644 --- a/src/db/models/releases.rs +++ b/src/db/models/releases.rs @@ -47,6 +47,7 @@ impl Release { let new_rel = NewRelease { artifact_id: art.id, release_date: date, + release_store_id: store.id, }; diesel::insert_into(releases::table) -- cgit v1.2.3