mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 21:13:09 +00:00
migrations
This commit is contained in:
@@ -10,7 +10,8 @@ use reqwest::Url;
|
|||||||
use rpc_toolkit::url::Host;
|
use rpc_toolkit::url::Host;
|
||||||
use rpc_toolkit::Context;
|
use rpc_toolkit::Context;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::SqlitePool;
|
use sqlx::migrate::MigrateDatabase;
|
||||||
|
use sqlx::{Sqlite, SqlitePool};
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
@@ -63,13 +64,20 @@ impl RpcContext {
|
|||||||
.unwrap_or_else(|| Path::new("/mnt/embassy-os/embassy.db").to_owned()),
|
.unwrap_or_else(|| Path::new("/mnt/embassy-os/embassy.db").to_owned()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let secret_store = SqlitePool::connect(&format!(
|
let secret_store_url = format!(
|
||||||
"sqlite://{}",
|
"sqlite://{}",
|
||||||
base.secret_store
|
base.secret_store
|
||||||
.unwrap_or_else(|| Path::new("/mnt/embassy-os/secrets.db").to_owned())
|
.unwrap_or_else(|| Path::new("/mnt/embassy-os/secrets.db").to_owned())
|
||||||
.display()
|
.display()
|
||||||
))
|
);
|
||||||
.await?;
|
if !Sqlite::database_exists(&secret_store_url).await? {
|
||||||
|
Sqlite::create_database(&secret_store_url).await?;
|
||||||
|
}
|
||||||
|
let secret_store = SqlitePool::connect(&secret_store_url).await?;
|
||||||
|
sqlx::migrate!()
|
||||||
|
.run(&secret_store)
|
||||||
|
.await
|
||||||
|
.with_kind(crate::ErrorKind::Database)?;
|
||||||
let docker = Docker::connect_with_unix_defaults()?;
|
let docker = Docker::connect_with_unix_defaults()?;
|
||||||
let net_controller = Arc::new(
|
let net_controller = Arc::new(
|
||||||
NetController::init(
|
NetController::init(
|
||||||
|
|||||||
7
appmgr/src/install/cleanup.rs
Normal file
7
appmgr/src/install/cleanup.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
use crate::db::model::InstalledPackageDataEntry;
|
||||||
|
use crate::s9pk::manifest::{Manifest, PackageId};
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
pub async fn cleanup(info: Result<InstalledPackageDataEntry, &Manifest>) -> Result<(), Error> {
|
||||||
|
Ok(()) // TODO
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ use sha2::{Digest, Sha256};
|
|||||||
use tokio::fs::{File, OpenOptions};
|
use tokio::fs::{File, OpenOptions};
|
||||||
use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt};
|
||||||
|
|
||||||
|
use self::cleanup::cleanup;
|
||||||
use self::progress::{InstallProgress, InstallProgressTracker};
|
use self::progress::{InstallProgress, InstallProgressTracker};
|
||||||
use crate::context::{EitherContext, ExtendedContext, RpcContext};
|
use crate::context::{EitherContext, ExtendedContext, RpcContext};
|
||||||
use crate::db::model::{
|
use crate::db::model::{
|
||||||
@@ -37,6 +38,7 @@ use crate::status::{DependencyErrors, MainStatus, Status};
|
|||||||
use crate::util::{display_none, AsyncFileExt, Version};
|
use crate::util::{display_none, AsyncFileExt, Version};
|
||||||
use crate::{Error, ResultExt};
|
use crate::{Error, ResultExt};
|
||||||
|
|
||||||
|
pub mod cleanup;
|
||||||
pub mod progress;
|
pub mod progress;
|
||||||
|
|
||||||
pub const PKG_CACHE: &'static str = "/mnt/embassy-os/cache/packages";
|
pub const PKG_CACHE: &'static str = "/mnt/embassy-os/cache/packages";
|
||||||
@@ -232,13 +234,15 @@ pub async fn download_install_s9pk(
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
let mut handle = ctx.db.handle();
|
if let Err(e) = cleanup(Err(temp_manifest)).await {
|
||||||
let mut broken = crate::db::DatabaseModel::new()
|
let mut handle = ctx.db.handle();
|
||||||
.broken_packages()
|
let mut broken = crate::db::DatabaseModel::new()
|
||||||
.get_mut(&mut handle)
|
.broken_packages()
|
||||||
.await?;
|
.get_mut(&mut handle)
|
||||||
broken.push(pkg_id.clone());
|
.await?;
|
||||||
broken.save(&mut handle).await?;
|
broken.push(pkg_id.clone());
|
||||||
|
broken.save(&mut handle).await?;
|
||||||
|
}
|
||||||
Err(e)
|
Err(e)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -536,7 +540,7 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
|
|||||||
{
|
{
|
||||||
configured &= res.configured;
|
configured &= res.configured;
|
||||||
}
|
}
|
||||||
// cleanup(pkg_id, Some(prev)).await?;
|
cleanup(Ok(prev)).await?;
|
||||||
if let Some(res) = manifest
|
if let Some(res) = manifest
|
||||||
.migrations
|
.migrations
|
||||||
.from(&prev_manifest.version, pkg_id, version, &manifest.volumes)
|
.from(&prev_manifest.version, pkg_id, version, &manifest.volumes)
|
||||||
|
|||||||
Reference in New Issue
Block a user