Remove environments from synced folder, and stop syncing

This commit is contained in:
Gregory Schier
2025-02-19 10:35:31 -08:00
parent 74f14a8392
commit 8ed0fd55c3
3 changed files with 28 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
use crate::error::Result; use crate::error::Result;
use crate::models::SyncModel; use crate::models::SyncModel;
use chrono::Utc; use chrono::Utc;
use log::{debug, warn}; use log::{debug, info, warn};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::{Display, Formatter}; 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 path = dir_entry.path();
let (model, checksum) = match SyncModel::from_file(&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(Some(m)) => m,
Ok(None) => continue, Ok(None) => continue,
Err(e) => { Err(e) => {
@@ -205,9 +212,17 @@ pub(crate) fn compute_sync_ops(
let op = match (db_map.get(k), fs_map.get(k)) { let op = match (db_map.get(k), fs_map.get(k)) {
(None, None) => return None, // Can never happen (None, None) => return None, // Can never happen
(None, Some(fs)) => SyncOp::DbCreate { fs: fs.to_owned() }, (None, Some(fs)) => SyncOp::DbCreate { fs: fs.to_owned() },
(Some(DbCandidate::Unmodified(model, sync_state)), None) => SyncOp::DbDelete { (Some(DbCandidate::Unmodified(model, sync_state)), None) => {
model: model.to_owned(), // TODO: Remove this once we have logic to handle environments. This it to
state: sync_state.to_owned(), // 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 { (Some(DbCandidate::Modified(model, sync_state)), None) => SyncOp::FsUpdate {
model: model.to_owned(), 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 sync_state_ops = Vec::new();
let mut workspaces_to_upsert = 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 folders_to_upsert = Vec::new();
let mut http_requests_to_upsert = Vec::new(); let mut http_requests_to_upsert = Vec::new();
let mut grpc_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 // batch upsert to make foreign keys happy
match fs.model { match fs.model {
SyncModel::Workspace(m) => workspaces_to_upsert.push(m), 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::Folder(m) => folders_to_upsert.push(m),
SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m), SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m),
SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m), SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m),
SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m), SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m),
// TODO: Handle environments in sync
SyncModel::Environment(_) => {}
}; };
SyncStateOp::Create { SyncStateOp::Create {
model_id, model_id,
@@ -397,11 +414,13 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
// batch upsert to make foreign keys happy // batch upsert to make foreign keys happy
match fs.model { match fs.model {
SyncModel::Workspace(m) => workspaces_to_upsert.push(m), 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::Folder(m) => folders_to_upsert.push(m),
SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m), SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m),
SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m), SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m),
SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m), SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m),
// TODO: Handle environments in sync
SyncModel::Environment(_) => {}
} }
SyncStateOp::Update { SyncStateOp::Update {
state: state.to_owned(), state: state.to_owned(),

View File

@@ -25,6 +25,7 @@ export function SyncToFilesystemSetting({
<VStack className="my-2" space={3}> <VStack className="my-2" space={3}>
<Banner color="info"> <Banner color="info">
Sync workspace data to folder as plain text files, ideal for backup and Git collaboration. 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> </Banner>
{error && <div className="text-danger">{error}</div>} {error && <div className="text-danger">{error}</div>}

View File

@@ -69,7 +69,7 @@ function isModelRelevant(m: AnyModel) {
if ( if (
m.model !== 'workspace' && m.model !== 'workspace' &&
m.model !== 'folder' && m.model !== 'folder' &&
m.model !== 'environment' && // m.model !== 'environment' && // Not synced anymore
m.model !== 'http_request' && m.model !== 'http_request' &&
m.model !== 'grpc_request' && m.model !== 'grpc_request' &&
m.model !== 'websocket_request' m.model !== 'websocket_request'