Skip to content

Commit 220999c

Browse files
committed
Add case
1 parent 06bdddc commit 220999c

24 files changed

+345
-302
lines changed

Cargo.lock

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

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use colored::Colorize;
3-
use vespertide_query::build_plan_queries;
3+
use vespertide_query::{DatabaseBackend, build_plan_queries};
44

55
use crate::utils::load_migrations;
66

@@ -27,7 +27,11 @@ pub fn cmd_log() -> Result<()> {
2727
plan.version.to_string().bright_magenta().bold()
2828
);
2929
if let Some(created) = &plan.created_at {
30-
println!(" {} {}", "Created at:".bright_cyan(), created.bright_white());
30+
println!(
31+
" {} {}",
32+
"Created at:".bright_cyan(),
33+
created.bright_white()
34+
);
3135
}
3236
if let Some(comment) = &plan.comment {
3337
println!(" {} {}", "Comment:".bright_cyan(), comment.bright_white());
@@ -50,7 +54,7 @@ pub fn cmd_log() -> Result<()> {
5054
println!(
5155
" {}. {}",
5256
(i + 1).to_string().bright_magenta().bold(),
53-
q.sql().trim().bright_white()
57+
q.build(DatabaseBackend::Postgres).trim().bright_white()
5458
);
5559
println!(" {} {:?}", "binds:".bright_cyan(), q.binds());
5660
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use colored::Colorize;
33
use vespertide_planner::plan_next_migration;
4-
use vespertide_query::build_plan_queries;
4+
use vespertide_query::{DatabaseBackend, build_plan_queries};
55

66
use crate::utils::{load_config, load_migrations, load_models};
77

@@ -35,7 +35,11 @@ fn emit_sql(plan: &vespertide_core::MigrationPlan) -> Result<()> {
3535
plan.version.to_string().bright_magenta()
3636
);
3737
if let Some(created_at) = &plan.created_at {
38-
println!("{} {}", "Created at:".bright_cyan(), created_at.bright_white());
38+
println!(
39+
"{} {}",
40+
"Created at:".bright_cyan(),
41+
created_at.bright_white()
42+
);
3943
}
4044
if let Some(comment) = &plan.comment {
4145
println!("{} {}", "Comment:".bright_cyan(), comment.bright_white());
@@ -56,7 +60,7 @@ fn emit_sql(plan: &vespertide_core::MigrationPlan) -> Result<()> {
5660
println!(
5761
"{}. {}",
5862
(i + 1).to_string().bright_magenta().bold(),
59-
q.sql().trim().bright_white()
63+
q.build(DatabaseBackend::Postgres).trim().bright_white()
6064
);
6165
println!(" {} {:?}", "binds:".bright_cyan(), q.binds());
6266
}

crates/vespertide-query/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ sea-query = "0.32"
1515

1616
[dev-dependencies]
1717
rstest = "0.26"
18+
insta = "1.44"

crates/vespertide-query/src/builder.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,4 @@ mod tests {
124124
let sql2_mysql = result[1].build(DatabaseBackend::MySql);
125125
assert!(sql2_mysql.contains("`posts`"));
126126
}
127-
128-
#[test]
129-
fn test_backward_compatibility_methods() {
130-
let plan = MigrationPlan {
131-
comment: None,
132-
created_at: None,
133-
version: 1,
134-
actions: vec![MigrationAction::DeleteTable {
135-
table: "users".into(),
136-
}],
137-
};
138-
139-
let result = build_plan_queries(&plan).unwrap();
140-
assert_eq!(result.len(), 1);
141-
142-
// Test backward compatibility methods
143-
let sql = result[0].sql();
144-
assert!(sql.contains("DROP TABLE"));
145-
146-
// binds() should return empty for DDL statements
147-
let binds = result[0].binds();
148-
assert!(binds.is_empty());
149-
}
150127
}

crates/vespertide-query/src/snapshots/vespertide_query__sql__tests__build_migration_action@build_migration_action_DeleteTable { table

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/vespertide-query/src/sql.rs
3+
expression: q.build(backend)
4+
---
5+
CREATE INDEX `idx` ON `t` (`c`)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/vespertide-query/src/sql.rs
3+
expression: q.build(backend)
4+
---
5+
DROP INDEX `idx` ON `t`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/vespertide-query/src/sql.rs
3+
expression: q.build(backend)
4+
---
5+
RENAME TABLE `a` TO `b`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/vespertide-query/src/sql.rs
3+
expression: q.build(backend)
4+
---
5+
ALTER TABLE `a` ADD CONSTRAINT `fk` FOREIGN KEY (`c`) REFERENCES `b` (`id`)

0 commit comments

Comments
 (0)