mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 17:28:29 +02:00
Fix broken environment migration
This commit is contained in:
@@ -68,11 +68,11 @@ export function migrateImport(contents: string) {
|
|||||||
|
|
||||||
// Migrate v4 to v5
|
// Migrate v4 to v5
|
||||||
for (const environment of parsed.resources.environments ?? []) {
|
for (const environment of parsed.resources.environments ?? []) {
|
||||||
if ('base' in environment && environment.base) {
|
if ('base' in environment && environment.base && environment.parentModel == null) {
|
||||||
environment.parentModel = 'workspace';
|
environment.parentModel = 'workspace';
|
||||||
environment.parentId = null;
|
environment.parentId = null;
|
||||||
delete environment.base;
|
delete environment.base;
|
||||||
} else if ('base' in environment && !environment.base) {
|
} else if ('base' in environment && !environment.base && environment.parentModel == null) {
|
||||||
environment.parentModel = 'environment';
|
environment.parentModel = 'environment';
|
||||||
environment.parentId = null;
|
environment.parentId = null;
|
||||||
delete environment.base;
|
delete environment.base;
|
||||||
|
|||||||
@@ -84,8 +84,9 @@ impl<'de> Deserialize<'de> for SyncModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn migrate_environment(obj: &mut Mapping) {
|
fn migrate_environment(obj: &mut Mapping) {
|
||||||
match obj.get("base") {
|
match (obj.get("base"), obj.get("parentModel")) {
|
||||||
Some(Value::Bool(base)) => {
|
(Some(Value::Bool(base)), None) => {
|
||||||
|
println!("Migrating legacy environment {}", serde_yaml::to_string(obj).unwrap());
|
||||||
if *base {
|
if *base {
|
||||||
obj.insert("parentModel".into(), "workspace".into());
|
obj.insert("parentModel".into(), "workspace".into());
|
||||||
} else {
|
} else {
|
||||||
@@ -220,7 +221,7 @@ impl TryFrom<AnyModel> for SyncModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod placeholder_tests {
|
mod migration_tests {
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use crate::models::SyncModel;
|
use crate::models::SyncModel;
|
||||||
|
|
||||||
@@ -271,6 +272,30 @@ color: null
|
|||||||
_ => panic!("expected sub environment"),
|
_ => panic!("expected sub environment"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let raw = r#"
|
||||||
|
type: environment
|
||||||
|
model: environment
|
||||||
|
id: ev_fAUS49FUN2
|
||||||
|
parentId: fld_123
|
||||||
|
parentModel: folder
|
||||||
|
workspaceId: wk_kfSI3JDHd7
|
||||||
|
createdAt: 2025-01-11T17:02:58.012792
|
||||||
|
updatedAt: 2025-07-23T20:00:46.049649
|
||||||
|
name: Folder Environment
|
||||||
|
public: true
|
||||||
|
base: false
|
||||||
|
variables: []
|
||||||
|
color: null
|
||||||
|
"#;
|
||||||
|
let m: SyncModel = serde_yaml::from_str(raw)?;
|
||||||
|
match m {
|
||||||
|
SyncModel::Environment(env) => {
|
||||||
|
assert_eq!(env.parent_model, "folder".to_string());
|
||||||
|
assert_eq!(env.parent_id, Some("fld_123".to_string()));
|
||||||
|
}
|
||||||
|
_ => panic!("expected folder environment"),
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user