mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
Feat/patch migration (#1890)
* feat: Most of the ui conversions and removing the package-recovered * chore: Include the down process. * feat: Add in the potential community packages. * chore: Add in the services * Make it so we skip rebuil. * update version to 033 in FE * chore: Revert to next version for patch-db * fix: Build and check Co-authored-by: Lucy Cifferello <12953208+elvece@users.noreply.github.com>
This commit is contained in:
@@ -17,8 +17,9 @@ mod v0_3_1_1;
|
||||
mod v0_3_1_2;
|
||||
mod v0_3_2;
|
||||
mod v0_3_2_1;
|
||||
mod v0_3_3;
|
||||
|
||||
pub type Current = v0_3_2_1::Version;
|
||||
pub type Current = v0_3_3::Version;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||
#[serde(untagged)]
|
||||
@@ -32,6 +33,7 @@ enum Version {
|
||||
V0_3_1_2(Wrapper<v0_3_1_2::Version>),
|
||||
V0_3_2(Wrapper<v0_3_2::Version>),
|
||||
V0_3_2_1(Wrapper<v0_3_2_1::Version>),
|
||||
V0_3_3(Wrapper<v0_3_3::Version>),
|
||||
Other(emver::Version),
|
||||
}
|
||||
|
||||
@@ -56,6 +58,7 @@ impl Version {
|
||||
Version::V0_3_1_2(Wrapper(x)) => x.semver(),
|
||||
Version::V0_3_2(Wrapper(x)) => x.semver(),
|
||||
Version::V0_3_2_1(Wrapper(x)) => x.semver(),
|
||||
Version::V0_3_3(Wrapper(x)) => x.semver(),
|
||||
Version::Other(x) => x.clone(),
|
||||
}
|
||||
}
|
||||
@@ -191,6 +194,7 @@ pub async fn init<Db: DbHandle>(
|
||||
Version::V0_3_1_2(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
|
||||
Version::V0_3_2(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
|
||||
Version::V0_3_2_1(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
|
||||
Version::V0_3_3(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
|
||||
Version::Other(_) => {
|
||||
return Err(Error::new(
|
||||
eyre!("Cannot downgrade"),
|
||||
@@ -232,6 +236,7 @@ mod tests {
|
||||
Just(Version::V0_3_1_2(Wrapper(v0_3_1_2::Version::new()))),
|
||||
Just(Version::V0_3_2(Wrapper(v0_3_2::Version::new()))),
|
||||
Just(Version::V0_3_2_1(Wrapper(v0_3_2_1::Version::new()))),
|
||||
Just(Version::V0_3_3(Wrapper(v0_3_3::Version::new()))),
|
||||
em_version().prop_map(Version::Other),
|
||||
]
|
||||
}
|
||||
|
||||
164
backend/src/version/v0_3_3.rs
Normal file
164
backend/src/version/v0_3_3.rs
Normal file
@@ -0,0 +1,164 @@
|
||||
use async_trait::async_trait;
|
||||
use emver::VersionRange;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use super::v0_3_0::V0_3_0_COMPAT;
|
||||
use super::*;
|
||||
use crate::{COMMUNITY_MARKETPLACE, DEFAULT_MARKETPLACE};
|
||||
|
||||
const V0_3_3: emver::Version = emver::Version::new(0, 3, 3, 0);
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref COMMUNITY_PACKAGES: Vec<&'static str> = vec![
|
||||
"robosats",
|
||||
"syncthing",
|
||||
"balanceofsatoshis",
|
||||
"lightning-jet",
|
||||
"mastodon",
|
||||
"sphinx-relay",
|
||||
"agora",
|
||||
"lndg",
|
||||
"synapse",
|
||||
"thunderhub",
|
||||
];
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version;
|
||||
|
||||
#[async_trait]
|
||||
impl VersionT for Version {
|
||||
type Previous = v0_3_2_1::Version;
|
||||
fn new() -> Self {
|
||||
Version
|
||||
}
|
||||
fn semver(&self) -> emver::Version {
|
||||
V0_3_3
|
||||
}
|
||||
fn compat(&self) -> &'static VersionRange {
|
||||
&*V0_3_0_COMPAT
|
||||
}
|
||||
async fn up<Db: DbHandle>(&self, db: &mut Db) -> Result<(), Error> {
|
||||
let mut ui = crate::db::DatabaseModel::new().ui().get_mut(db).await?;
|
||||
|
||||
if let Some(Value::String(selected_url)) =
|
||||
ui["marketplace"]
|
||||
.get("selected-id")
|
||||
.and_then(|selected_id| {
|
||||
if let Value::String(selected_id) = selected_id {
|
||||
return Some(ui["marketplace"]["known-hosts"].get(&selected_id)?);
|
||||
}
|
||||
None
|
||||
})
|
||||
{
|
||||
ui["marketplace"]["selected-url"] = json!(selected_url);
|
||||
}
|
||||
if let Value::Object(ref mut obj) = *ui {
|
||||
obj.remove("pkg-order");
|
||||
obj.remove("auto-check-updates");
|
||||
}
|
||||
let known_hosts = ui["marketplace"]["known-hosts"].take();
|
||||
if let Value::Object(known_hosts) = known_hosts {
|
||||
for (_id, value) in known_hosts {
|
||||
if let (Value::String(name), Value::String(url)) = (&value["name"], &value["url"]) {
|
||||
ui["marketplace"]["known-hosts"][name] = json!(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(Value::Object(ref mut obj)) = ui.get_mut("marketplace") {
|
||||
obj.remove("selected-id");
|
||||
}
|
||||
if ui["marketplace"]["selected-url"].is_null() {
|
||||
ui["marketplace"]["selected-url"] = json!(MarketPlaceUrls::Default.url());
|
||||
}
|
||||
ui.save(db).await?;
|
||||
|
||||
for package_id in crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(db, false)
|
||||
.await?
|
||||
.iter()
|
||||
{
|
||||
let id: &str = &**package_id;
|
||||
if COMMUNITY_PACKAGES.iter().find(|x| x == &&id).is_none() {
|
||||
continue;
|
||||
}
|
||||
let mut package = crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.idx_model(package_id)
|
||||
.and_then(|x| x.installed())
|
||||
.get_mut(db)
|
||||
.await?;
|
||||
if let Some(ref mut package) = *package {
|
||||
package.marketplace_url = Some(MarketPlaceUrls::Community.url().parse().unwrap());
|
||||
}
|
||||
package.save(db).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
async fn down<Db: DbHandle>(&self, db: &mut Db) -> Result<(), Error> {
|
||||
let mut ui = crate::db::DatabaseModel::new().ui().get_mut(db).await?;
|
||||
let selected_url = ui["marketplace"]["selected-url"]
|
||||
.as_str()
|
||||
.map(|x| x.to_owned());
|
||||
let known_hosts = ui["marketplace"]["known-hosts"].take();
|
||||
ui["marketplace"]["known-hosts"] = json!({});
|
||||
if let Value::Object(known_hosts) = known_hosts {
|
||||
for (url, name) in known_hosts {
|
||||
if let Value::String(name) = name {
|
||||
let id = uuid::Uuid::new_v4().to_string();
|
||||
if Some(&name) == selected_url.as_ref() {
|
||||
ui["marketplace"]["selected-id"] = Value::String(id.clone());
|
||||
}
|
||||
ui["marketplace"]["known-hosts"][id.as_str()] = json!({
|
||||
"name": name,
|
||||
"url": url
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
ui["auto-check-updates"] = Value::Bool(true);
|
||||
ui["pkg-order"] = json!(crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(db, false)
|
||||
.await?
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect::<Vec<String>>());
|
||||
if let Some(Value::Object(ref mut obj)) = ui.get_mut("marketplace") {
|
||||
obj.remove("selected-url");
|
||||
}
|
||||
ui.save(db).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum MarketPlaceUrls {
|
||||
Default,
|
||||
Community,
|
||||
}
|
||||
|
||||
impl MarketPlaceUrls {
|
||||
pub fn url(&self) -> String {
|
||||
let url_string = match self {
|
||||
MarketPlaceUrls::Default => DEFAULT_MARKETPLACE,
|
||||
MarketPlaceUrls::Community => COMMUNITY_MARKETPLACE,
|
||||
};
|
||||
format!("{url_string}/")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_that_ui_includes_url() {
|
||||
let ui: Value =
|
||||
serde_json::from_str(include_str!("../../../frontend/patchdb-ui-seed.json")).unwrap();
|
||||
for market_place in [MarketPlaceUrls::Default, MarketPlaceUrls::Community] {
|
||||
let url = market_place.url();
|
||||
assert!(
|
||||
!ui["marketplace"]["known-hosts"][&url].is_null(),
|
||||
"Should have a market place for {url}"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user