Skip to content

Commit 44c2f8b

Browse files
committed
Rm yaml feature
1 parent 3d2aa60 commit 44c2f8b

4 files changed

Lines changed: 34 additions & 131 deletions

File tree

crates/vespertide-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ futures = "0.3"
2424
async-recursion = "1"
2525
vespertide-config = { workspace = true, features = ["cli", "schema"] }
2626
vespertide-core = { workspace = true, features = ["schema"] }
27-
vespertide-loader = { workspace = true, features = ["yaml"] }
27+
vespertide-loader = { workspace = true }
2828
vespertide-planner = { workspace = true }
2929
vespertide-query = { workspace = true }
3030
vespertide-exporter = { workspace = true }

crates/vespertide-loader/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ vespertide-config = { workspace = true }
1414
vespertide-planner = { workspace = true }
1515
anyhow = "1"
1616
serde_json = "1.0"
17-
serde_yaml = { version = "0.9", optional = true }
18-
19-
[features]
20-
default = ["yaml"]
21-
yaml = ["dep:serde_yaml"]
17+
serde_yaml = "0.9"
2218

2319
[dev-dependencies]
2420
tempfile = "3"

crates/vespertide-loader/src/migrations.rs

Lines changed: 27 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,8 @@ pub fn load_migrations(config: &VespertideConfig) -> Result<Vec<MigrationPlan>>
3030
serde_json::from_str(&content)
3131
.with_context(|| format!("parse migration: {}", path.display()))?
3232
} else {
33-
#[cfg(feature = "yaml")]
34-
{
35-
serde_yaml::from_str(&content)
36-
.with_context(|| format!("parse migration: {}", path.display()))?
37-
}
38-
#[cfg(not(feature = "yaml"))]
39-
{
40-
anyhow::bail!(
41-
"YAML support not enabled. Enable the 'yaml' feature or use JSON format: {}",
42-
path.display()
43-
);
44-
}
33+
serde_yaml::from_str(&content)
34+
.with_context(|| format!("parse migration: {}", path.display()))?
4535
};
4636

4737
// Validate the migration plan
@@ -99,16 +89,9 @@ pub fn load_migrations_from_dir(
9989
format!("Failed to parse JSON migration {}: {}", path.display(), e)
10090
})?
10191
} else {
102-
#[cfg(feature = "yaml")]
103-
{
104-
serde_yaml::from_str(&content).map_err(|e| {
105-
format!("Failed to parse YAML migration {}: {}", path.display(), e)
106-
})?
107-
}
108-
#[cfg(not(feature = "yaml"))]
109-
{
110-
return Err(format!("YAML support not enabled. Enable the 'yaml' feature or use JSON format: {}", path.display()).into());
111-
}
92+
serde_yaml::from_str(&content).map_err(|e| {
93+
format!("Failed to parse YAML migration {}: {}", path.display(), e)
94+
})?
11295
};
11396

11497
plans.push(plan);
@@ -269,7 +252,6 @@ mod tests {
269252
assert_eq!(plans[2].version, 3);
270253
}
271254

272-
#[cfg(feature = "yaml")]
273255
#[test]
274256
fn test_load_migrations_from_dir_with_yaml_migration() {
275257
let temp_dir = TempDir::new().unwrap();
@@ -297,7 +279,6 @@ actions:
297279
assert_eq!(plans[0].version, 1);
298280
}
299281

300-
#[cfg(feature = "yaml")]
301282
#[test]
302283
fn test_load_migrations_from_dir_with_yml_migration() {
303284
let temp_dir = TempDir::new().unwrap();
@@ -325,58 +306,47 @@ actions:
325306
assert_eq!(plans[0].version, 1);
326307
}
327308

328-
#[test]
329-
fn test_load_migrations_from_dir_with_invalid_json() {
330-
let temp_dir = TempDir::new().unwrap();
331-
let migrations_dir = temp_dir.path().join("migrations");
332-
fs::create_dir_all(&migrations_dir).unwrap();
333-
334-
let invalid_json = r#"{"version": 1, "actions": [invalid]}"#;
335-
fs::write(migrations_dir.join("0001_invalid.json"), invalid_json).unwrap();
336-
337-
let result = load_migrations_from_dir(Some(temp_dir.path().to_path_buf()));
338-
assert!(result.is_err());
339-
let err_msg = result.unwrap_err().to_string();
340-
assert!(err_msg.contains("Failed to parse JSON migration"));
341-
}
342-
343-
#[cfg(not(feature = "yaml"))]
344309
#[test]
345310
#[serial]
346-
fn test_load_migrations_reports_yaml_disabled_for_runtime_loader() {
311+
fn test_load_migrations_reads_yaml_for_runtime_loader() {
347312
let temp_dir = TempDir::new().unwrap();
348313
let _guard = CwdGuard::new(&temp_dir.path().to_path_buf());
349314
write_config(temp_dir.path());
350315
fs::create_dir_all("migrations").unwrap();
351-
fs::write("migrations/0001_test.yaml", "version: 1\nactions: []\n").unwrap();
352316

353-
let result = load_migrations(&VespertideConfig::default());
354-
assert!(result.is_err());
355-
let err_msg = result.unwrap_err().to_string();
356-
assert!(err_msg.contains("YAML support not enabled"));
357-
assert!(err_msg.contains("0001_test.yaml"));
317+
let migration_content = r#"---
318+
version: 1
319+
actions:
320+
- type: create_table
321+
table: users
322+
columns:
323+
- name: id
324+
type: integer
325+
nullable: false
326+
constraints: []
327+
"#;
328+
fs::write("migrations/0001_test.yaml", migration_content).unwrap();
329+
330+
let plans = load_migrations(&VespertideConfig::default()).unwrap();
331+
assert_eq!(plans.len(), 1);
332+
assert_eq!(plans[0].version, 1);
358333
}
359334

360-
#[cfg(not(feature = "yaml"))]
361335
#[test]
362-
fn test_load_migrations_from_dir_reports_yaml_disabled() {
336+
fn test_load_migrations_from_dir_with_invalid_json() {
363337
let temp_dir = TempDir::new().unwrap();
364338
let migrations_dir = temp_dir.path().join("migrations");
365339
fs::create_dir_all(&migrations_dir).unwrap();
366-
fs::write(
367-
migrations_dir.join("0001_test.yaml"),
368-
"version: 1\nactions: []\n",
369-
)
370-
.unwrap();
340+
341+
let invalid_json = r#"{"version": 1, "actions": [invalid]}"#;
342+
fs::write(migrations_dir.join("0001_invalid.json"), invalid_json).unwrap();
371343

372344
let result = load_migrations_from_dir(Some(temp_dir.path().to_path_buf()));
373345
assert!(result.is_err());
374346
let err_msg = result.unwrap_err().to_string();
375-
assert!(err_msg.contains("YAML support not enabled"));
376-
assert!(err_msg.contains("0001_test.yaml"));
347+
assert!(err_msg.contains("Failed to parse JSON migration"));
377348
}
378349

379-
#[cfg(feature = "yaml")]
380350
#[test]
381351
fn test_load_migrations_from_dir_with_invalid_yaml() {
382352
let temp_dir = TempDir::new().unwrap();

crates/vespertide-loader/src/models.rs

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,8 @@ fn load_models_recursive(dir: &Path, tables: &mut Vec<TableDef>) -> Result<()> {
5959
serde_json::from_str(&content)
6060
.with_context(|| format!("parse JSON model: {}", path.display()))?
6161
} else {
62-
#[cfg(feature = "yaml")]
63-
{
64-
serde_yaml::from_str(&content)
65-
.with_context(|| format!("parse YAML model: {}", path.display()))?
66-
}
67-
#[cfg(not(feature = "yaml"))]
68-
{
69-
anyhow::bail!(
70-
"YAML support not enabled. Enable the 'yaml' feature or use JSON format: {}",
71-
path.display()
72-
);
73-
}
62+
serde_yaml::from_str(&content)
63+
.with_context(|| format!("parse YAML model: {}", path.display()))?
7464
};
7565

7666
tables.push(table);
@@ -155,16 +145,9 @@ fn load_models_recursive_internal(
155145
format!("Failed to parse JSON model {}: {}", path.display(), e)
156146
})?
157147
} else {
158-
#[cfg(feature = "yaml")]
159-
{
160-
serde_yaml::from_str(&content).map_err(|e| {
161-
format!("Failed to parse YAML model {}: {}", path.display(), e)
162-
})?
163-
}
164-
#[cfg(not(feature = "yaml"))]
165-
{
166-
return Err(format!("YAML support not enabled. Enable the 'yaml' feature or use JSON format: {}", path.display()).into());
167-
}
148+
serde_yaml::from_str(&content).map_err(|e| {
149+
format!("Failed to parse YAML model {}: {}", path.display(), e)
150+
})?
168151
};
169152

170153
tables.push(table);
@@ -227,7 +210,6 @@ mod tests {
227210
assert_eq!(models.len(), 0);
228211
}
229212

230-
#[cfg(feature = "yaml")]
231213
#[test]
232214
#[serial]
233215
fn load_models_reads_yaml_and_validates() {
@@ -338,28 +320,6 @@ mod tests {
338320
assert!(err_msg.contains("Failed to normalize table 'orders'"));
339321
}
340322

341-
#[cfg(not(feature = "yaml"))]
342-
#[test]
343-
#[serial]
344-
fn load_models_reports_yaml_disabled_for_runtime_loader() {
345-
let tmp = tempdir().unwrap();
346-
let _guard = CwdGuard::new(&tmp.path().to_path_buf());
347-
write_config();
348-
349-
fs::create_dir_all("models").unwrap();
350-
fs::write(
351-
"models/users.yaml",
352-
"name: users\ncolumns: []\nconstraints: []\n",
353-
)
354-
.unwrap();
355-
356-
let result = load_models(&VespertideConfig::default());
357-
assert!(result.is_err());
358-
let err_msg = result.unwrap_err().to_string();
359-
assert!(err_msg.contains("YAML support not enabled"));
360-
assert!(err_msg.contains("users.yaml"));
361-
}
362-
363323
#[test]
364324
#[serial]
365325
fn test_load_models_from_dir_with_root() {
@@ -434,27 +394,6 @@ mod tests {
434394
assert_eq!(models.len(), 0);
435395
}
436396

437-
#[cfg(not(feature = "yaml"))]
438-
#[test]
439-
#[serial]
440-
fn test_load_models_from_dir_reports_yaml_disabled() {
441-
let temp_dir = tempdir().unwrap();
442-
let models_dir = temp_dir.path().join("models");
443-
fs::create_dir_all(&models_dir).unwrap();
444-
fs::write(
445-
models_dir.join("users.yaml"),
446-
"name: users\ncolumns: []\nconstraints: []\n",
447-
)
448-
.unwrap();
449-
450-
let result = load_models_from_dir(Some(temp_dir.path().to_path_buf()));
451-
assert!(result.is_err());
452-
let err_msg = result.unwrap_err().to_string();
453-
assert!(err_msg.contains("YAML support not enabled"));
454-
assert!(err_msg.contains("users.yaml"));
455-
}
456-
457-
#[cfg(feature = "yaml")]
458397
#[test]
459398
#[serial]
460399
fn test_load_models_from_dir_with_yaml() {
@@ -491,7 +430,6 @@ mod tests {
491430
assert_eq!(models[0].name, "users");
492431
}
493432

494-
#[cfg(feature = "yaml")]
495433
#[test]
496434
#[serial]
497435
fn test_load_models_from_dir_with_yml() {
@@ -580,7 +518,6 @@ mod tests {
580518
assert!(err_msg.contains("Failed to parse JSON model"));
581519
}
582520

583-
#[cfg(feature = "yaml")]
584521
#[test]
585522
#[serial]
586523
fn test_load_models_from_dir_with_invalid_yaml() {

0 commit comments

Comments
 (0)