Skip to content

Commit b72a014

Browse files
committed
Fix change fk issue
1 parent e184b0a commit b72a014

14 files changed

+772
-292
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"}

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: 13 additions & 0 deletions
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

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))

crates/vespertide-core/src/action.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ pub enum MigrationAction {
8686
table: TableName,
8787
constraint: TableConstraint,
8888
},
89+
ReplaceConstraint {
90+
table: TableName,
91+
from: TableConstraint,
92+
to: TableConstraint,
93+
},
8994
RenameTable {
9095
from: TableName,
9196
to: TableName,
@@ -207,6 +212,13 @@ impl MigrationAction {
207212
constraint: constraint.with_prefix(prefix),
208213
}
209214
}
215+
MigrationAction::ReplaceConstraint { table, from, to } => {
216+
MigrationAction::ReplaceConstraint {
217+
table: format!("{}{}", prefix, table),
218+
from: from.with_prefix(prefix),
219+
to: to.with_prefix(prefix),
220+
}
221+
}
210222
MigrationAction::RenameTable { from, to } => MigrationAction::RenameTable {
211223
from: format!("{}{}", prefix, from),
212224
to: format!("{}{}", prefix, to),
@@ -339,6 +351,33 @@ impl fmt::Display for MigrationAction {
339351
};
340352
write!(f, "RemoveConstraint: {}.{}", table, constraint_name)
341353
}
354+
MigrationAction::ReplaceConstraint { table, to, .. } => {
355+
let constraint_name = match to {
356+
TableConstraint::PrimaryKey { .. } => "PRIMARY KEY",
357+
TableConstraint::Unique { name, .. } => {
358+
if let Some(n) = name {
359+
return write!(f, "ReplaceConstraint: {}.{} (UNIQUE)", table, n);
360+
}
361+
"UNIQUE"
362+
}
363+
TableConstraint::ForeignKey { name, .. } => {
364+
if let Some(n) = name {
365+
return write!(f, "ReplaceConstraint: {}.{} (FOREIGN KEY)", table, n);
366+
}
367+
"FOREIGN KEY"
368+
}
369+
TableConstraint::Check { name, .. } => {
370+
return write!(f, "ReplaceConstraint: {}.{} (CHECK)", table, name);
371+
}
372+
TableConstraint::Index { name, .. } => {
373+
if let Some(n) = name {
374+
return write!(f, "ReplaceConstraint: {}.{} (INDEX)", table, n);
375+
}
376+
"INDEX"
377+
}
378+
};
379+
write!(f, "ReplaceConstraint: {}.{}", table, constraint_name)
380+
}
342381
MigrationAction::RenameTable { from, to } => {
343382
write!(f, "RenameTable: {} -> {}", from, to)
344383
}

0 commit comments

Comments
 (0)