Skip to content

Commit 543371c

Browse files
authored
Merge pull request #135 from dev-five-git/chage-fk-issue
Chage fk issue
2 parents e184b0a + 48e3911 commit 543371c

File tree

24 files changed

+1529
-288
lines changed

24 files changed

+1529
-288
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-naming/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch"},"note":"Fix change fk issue","date":"2026-04-14T04:54:12.310894100Z"}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ settings.local.json
44
coverage
55
lcov.info
66
.sisyphus
7+
.omc

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/diff.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ fn format_action(action: &MigrationAction) -> String {
184184
table.bright_cyan()
185185
)
186186
}
187+
MigrationAction::ReplaceConstraint {
188+
table, from, to, ..
189+
} => {
190+
format!(
191+
"{} {} {} {} {} {}",
192+
"Replace constraint:".bright_yellow(),
193+
format_constraint_type(from).bright_cyan().bold(),
194+
"->".bright_white(),
195+
format_constraint_type(to).bright_cyan().bold(),
196+
"on".bright_white(),
197+
table.bright_cyan()
198+
)
199+
}
187200
}
188201
}
189202

@@ -234,7 +247,9 @@ mod tests {
234247
use std::path::PathBuf;
235248
use tempfile::tempdir;
236249
use vespertide_config::VespertideConfig;
237-
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType, TableConstraint, TableDef};
250+
use vespertide_core::{
251+
ColumnDef, ColumnType, ReferenceAction, SimpleColumnType, TableConstraint, TableDef,
252+
};
238253

239254
struct CwdGuard {
240255
original: PathBuf,
@@ -565,6 +580,28 @@ mod tests {
565580
"This is a very long comment...".bright_cyan().bold()
566581
)
567582
)]
583+
#[case(
584+
MigrationAction::ReplaceConstraint {
585+
table: "posts".into(),
586+
from: vespertide_core::TableConstraint::ForeignKey {
587+
name: Some("fk_user".into()),
588+
columns: vec!["user_id".into()],
589+
ref_table: "users".into(),
590+
ref_columns: vec!["id".into()],
591+
on_delete: None,
592+
on_update: None,
593+
},
594+
to: vespertide_core::TableConstraint::ForeignKey {
595+
name: Some("fk_user".into()),
596+
columns: vec!["user_id".into()],
597+
ref_table: "users".into(),
598+
ref_columns: vec!["id".into()],
599+
on_delete: Some(ReferenceAction::Cascade),
600+
on_update: None,
601+
},
602+
},
603+
format!("{} {} {} {} {} {}", "Replace constraint:".bright_yellow(), "fk_user FK (user_id) -> users".bright_cyan().bold(), "->".bright_white(), "fk_user FK (user_id) -> users".bright_cyan().bold(), "on".bright_white(), "posts".bright_cyan())
604+
)]
568605
#[serial]
569606
fn format_action_cases(#[case] action: MigrationAction, #[case] expected: String) {
570607
assert_eq!(format_action(&action), expected);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ fn rewrite_plan_for_recreation(
602602
| MigrationAction::ModifyColumnDefault { table, .. }
603603
| MigrationAction::ModifyColumnComment { table, .. }
604604
| MigrationAction::AddConstraint { table, .. }
605-
| MigrationAction::RemoveConstraint { table, .. } => Some(table.as_str()),
605+
| MigrationAction::RemoveConstraint { table, .. }
606+
| MigrationAction::ReplaceConstraint { table, .. } => Some(table.as_str()),
606607
_ => None,
607608
};
608609
table.is_none_or(|t| !tables_to_recreate.contains(t))

0 commit comments

Comments
 (0)