mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 20:00:29 +01:00
Remove environments from synced folder, and stop syncing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::error::Result;
|
||||
use crate::models::SyncModel;
|
||||
use chrono::Utc;
|
||||
use log::{debug, warn};
|
||||
use log::{debug, info, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Formatter};
|
||||
@@ -164,6 +164,13 @@ pub(crate) async fn get_fs_candidates(dir: &Path) -> Result<Vec<FsCandidate>> {
|
||||
|
||||
let path = dir_entry.path();
|
||||
let (model, checksum) = match SyncModel::from_file(&path) {
|
||||
// TODO: Remove this once we have logic to handle environments. This it to clean
|
||||
// any existing ones from the sync dir that resulted from the 2025.1 betas.
|
||||
Ok(Some((SyncModel::Environment(e), _))) => {
|
||||
fs::remove_file(path).await?;
|
||||
info!("Cleaned up synced environment {}", e.id);
|
||||
continue;
|
||||
}
|
||||
Ok(Some(m)) => m,
|
||||
Ok(None) => continue,
|
||||
Err(e) => {
|
||||
@@ -205,9 +212,17 @@ pub(crate) fn compute_sync_ops(
|
||||
let op = match (db_map.get(k), fs_map.get(k)) {
|
||||
(None, None) => return None, // Can never happen
|
||||
(None, Some(fs)) => SyncOp::DbCreate { fs: fs.to_owned() },
|
||||
(Some(DbCandidate::Unmodified(model, sync_state)), None) => SyncOp::DbDelete {
|
||||
model: model.to_owned(),
|
||||
state: sync_state.to_owned(),
|
||||
(Some(DbCandidate::Unmodified(model, sync_state)), None) => {
|
||||
// TODO: Remove this once we have logic to handle environments. This it to
|
||||
// ignore the cleaning we did above of any environments that were written
|
||||
// to disk in the 2025.1 betas.
|
||||
if let SyncModel::Environment(_) = model {
|
||||
return None;
|
||||
}
|
||||
SyncOp::DbDelete {
|
||||
model: model.to_owned(),
|
||||
state: sync_state.to_owned(),
|
||||
}
|
||||
},
|
||||
(Some(DbCandidate::Modified(model, sync_state)), None) => SyncOp::FsUpdate {
|
||||
model: model.to_owned(),
|
||||
@@ -318,7 +333,7 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
||||
);
|
||||
let mut sync_state_ops = Vec::new();
|
||||
let mut workspaces_to_upsert = Vec::new();
|
||||
let mut environments_to_upsert = Vec::new();
|
||||
let environments_to_upsert = Vec::new();
|
||||
let mut folders_to_upsert = Vec::new();
|
||||
let mut http_requests_to_upsert = Vec::new();
|
||||
let mut grpc_requests_to_upsert = Vec::new();
|
||||
@@ -380,11 +395,13 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
||||
// batch upsert to make foreign keys happy
|
||||
match fs.model {
|
||||
SyncModel::Workspace(m) => workspaces_to_upsert.push(m),
|
||||
SyncModel::Environment(m) => environments_to_upsert.push(m),
|
||||
SyncModel::Folder(m) => folders_to_upsert.push(m),
|
||||
SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m),
|
||||
SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m),
|
||||
SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m),
|
||||
|
||||
// TODO: Handle environments in sync
|
||||
SyncModel::Environment(_) => {}
|
||||
};
|
||||
SyncStateOp::Create {
|
||||
model_id,
|
||||
@@ -397,11 +414,13 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
||||
// batch upsert to make foreign keys happy
|
||||
match fs.model {
|
||||
SyncModel::Workspace(m) => workspaces_to_upsert.push(m),
|
||||
SyncModel::Environment(m) => environments_to_upsert.push(m),
|
||||
SyncModel::Folder(m) => folders_to_upsert.push(m),
|
||||
SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m),
|
||||
SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m),
|
||||
SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m),
|
||||
|
||||
// TODO: Handle environments in sync
|
||||
SyncModel::Environment(_) => {}
|
||||
}
|
||||
SyncStateOp::Update {
|
||||
state: state.to_owned(),
|
||||
|
||||
@@ -25,6 +25,7 @@ export function SyncToFilesystemSetting({
|
||||
<VStack className="my-2" space={3}>
|
||||
<Banner color="info">
|
||||
Sync workspace data to folder as plain text files, ideal for backup and Git collaboration.
|
||||
Environments are excluded in order to keep your secrets private.
|
||||
</Banner>
|
||||
{error && <div className="text-danger">{error}</div>}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ function isModelRelevant(m: AnyModel) {
|
||||
if (
|
||||
m.model !== 'workspace' &&
|
||||
m.model !== 'folder' &&
|
||||
m.model !== 'environment' &&
|
||||
// m.model !== 'environment' && // Not synced anymore
|
||||
m.model !== 'http_request' &&
|
||||
m.model !== 'grpc_request' &&
|
||||
m.model !== 'websocket_request'
|
||||
|
||||
Reference in New Issue
Block a user