Skip to content

Commit 56ab403

Browse files
authored
Merge pull request #77 from dev-five-git/fill-with-default
Add fill with default
2 parents aa56562 + df88ae0 commit 56ab403

7 files changed

Lines changed: 391 additions & 26 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-naming/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch"},"note":"Add fill_with default","date":"2026-01-21T07:14:49.745170500Z"}

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
echo 'merge_derives = true' >> .rustfmt.toml
5050
echo 'use_small_heuristics = "Default"' >> .rustfmt.toml
5151
cargo fmt
52-
cargo tarpaulin --out Lcov Stdout
52+
cargo tarpaulin --out Lcov Stdout --workspace --exclude app
5353
- name: Upload to codecov.io
5454
uses: codecov/codecov-action@v5
5555
with:

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vespertide-cli/src/commands/revision.rs

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ fn parse_fill_with_args(args: &[String]) -> HashMap<(String, String), String> {
2929
}
3030

3131
/// Format the type info string for display.
32-
fn format_type_info(column_type: Option<&String>) -> String {
33-
column_type.map(|t| format!(" ({})", t)).unwrap_or_default()
32+
/// Includes column type and default value hint if available.
33+
fn format_type_info(column_type: Option<&String>, default_value: Option<&String>) -> String {
34+
match (column_type, default_value) {
35+
(Some(t), Some(d)) => format!(" ({}, default: {})", t, d),
36+
(Some(t), None) => format!(" ({})", t),
37+
(None, Some(d)) => format!(" (default: {})", d),
38+
(None, None) => String::new(),
39+
}
3440
}
3541

3642
/// Format a single fill_with item for display.
@@ -75,9 +81,10 @@ fn print_fill_with_item_and_get_prompt(
7581
table: &str,
7682
column: &str,
7783
column_type: Option<&String>,
84+
default_value: Option<&String>,
7885
action_type: &str,
7986
) -> String {
80-
let type_info = format_type_info(column_type);
87+
let type_info = format_type_info(column_type, default_value);
8188
let item_display = format_fill_with_item(table, column, &type_info, action_type);
8289
println!("{}", item_display);
8390
format_fill_with_prompt(table, column)
@@ -128,6 +135,7 @@ where
128135
&item.table,
129136
&item.column,
130137
item.column_type.as_ref(),
138+
item.default_value.as_ref(),
131139
item.action_type,
132140
);
133141

@@ -720,15 +728,30 @@ mod tests {
720728
}
721729

722730
#[test]
723-
fn test_format_type_info_with_some() {
724-
let column_type = Some("Integer".to_string());
725-
let result = format_type_info(column_type.as_ref());
726-
assert_eq!(result, " (Integer)");
731+
fn test_format_type_info_with_type_and_default() {
732+
let column_type = Some("integer".to_string());
733+
let default_value = Some("0".to_string());
734+
let result = format_type_info(column_type.as_ref(), default_value.as_ref());
735+
assert_eq!(result, " (integer, default: 0)");
736+
}
737+
738+
#[test]
739+
fn test_format_type_info_with_type_only() {
740+
let column_type = Some("text".to_string());
741+
let result = format_type_info(column_type.as_ref(), None);
742+
assert_eq!(result, " (text)");
743+
}
744+
745+
#[test]
746+
fn test_format_type_info_with_default_only() {
747+
let default_value = Some("0".to_string());
748+
let result = format_type_info(None, default_value.as_ref());
749+
assert_eq!(result, " (default: 0)");
727750
}
728751

729752
#[test]
730753
fn test_format_type_info_with_none() {
731-
let result = format_type_info(None);
754+
let result = format_type_info(None, None);
732755
assert_eq!(result, "");
733756
}
734757

@@ -766,7 +789,8 @@ mod tests {
766789
let prompt = print_fill_with_item_and_get_prompt(
767790
"users",
768791
"email",
769-
Some(&"Text".to_string()),
792+
Some(&"text".to_string()),
793+
Some(&"''".to_string()),
770794
"AddColumn",
771795
);
772796
assert!(prompt.contains("Enter fill value for"));
@@ -776,13 +800,32 @@ mod tests {
776800

777801
#[test]
778802
fn test_print_fill_with_item_and_get_prompt_no_type() {
779-
let prompt =
780-
print_fill_with_item_and_get_prompt("orders", "status", None, "ModifyColumnNullable");
803+
let prompt = print_fill_with_item_and_get_prompt(
804+
"orders",
805+
"status",
806+
None,
807+
None,
808+
"ModifyColumnNullable",
809+
);
781810
assert!(prompt.contains("Enter fill value for"));
782811
assert!(prompt.contains("orders"));
783812
assert!(prompt.contains("status"));
784813
}
785814

815+
#[test]
816+
fn test_print_fill_with_item_and_get_prompt_with_default() {
817+
let prompt = print_fill_with_item_and_get_prompt(
818+
"users",
819+
"age",
820+
Some(&"integer".to_string()),
821+
Some(&"0".to_string()),
822+
"AddColumn",
823+
);
824+
assert!(prompt.contains("Enter fill value for"));
825+
assert!(prompt.contains("users"));
826+
assert!(prompt.contains("age"));
827+
}
828+
786829
#[test]
787830
fn test_print_fill_with_header() {
788831
// Just verify it doesn't panic - output goes to stdout
@@ -804,7 +847,8 @@ mod tests {
804847
table: "users".to_string(),
805848
column: "email".to_string(),
806849
action_type: "AddColumn",
807-
column_type: Some("Text".to_string()),
850+
column_type: Some("text".to_string()),
851+
default_value: Some("''".to_string()),
808852
}];
809853

810854
let mut fill_values = HashMap::new();
@@ -832,14 +876,16 @@ mod tests {
832876
table: "users".to_string(),
833877
column: "email".to_string(),
834878
action_type: "AddColumn",
835-
column_type: Some("Text".to_string()),
879+
column_type: Some("text".to_string()),
880+
default_value: Some("''".to_string()),
836881
},
837882
FillWithRequired {
838883
action_index: 1,
839884
table: "orders".to_string(),
840885
column: "status".to_string(),
841886
action_type: "ModifyColumnNullable",
842887
column_type: None,
888+
default_value: None,
843889
},
844890
];
845891

@@ -898,7 +944,8 @@ mod tests {
898944
table: "users".to_string(),
899945
column: "email".to_string(),
900946
action_type: "AddColumn",
901-
column_type: Some("Text".to_string()),
947+
column_type: Some("text".to_string()),
948+
default_value: Some("''".to_string()),
902949
}];
903950

904951
let mut fill_values = HashMap::new();

0 commit comments

Comments
 (0)