Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_4sB2YBEV80GvtBNjS_r76.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch"},"note":"Support enum","date":"2025-12-17T11:30:23.776147Z"}
70 changes: 14 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions crates/vespertide-cli/src/commands/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use colored::Colorize;
use vespertide_loader::{load_config, load_models};
use vespertide_loader::load_config;
use vespertide_planner::apply_action;
use vespertide_query::{DatabaseBackend, build_plan_queries};

use crate::utils::load_migrations;
Expand All @@ -21,7 +22,10 @@ pub fn cmd_log(backend: DatabaseBackend) -> Result<()> {
plans.len().to_string().bright_yellow().bold()
);
println!();
let current_models = load_models(&config)?;

// Build baseline schema incrementally as we iterate through migrations
let mut baseline_schema = Vec::new();

for plan in &plans {
println!(
"{} {}",
Expand All @@ -44,9 +48,15 @@ pub fn cmd_log(backend: DatabaseBackend) -> Result<()> {
plan.actions.len().to_string().bright_yellow()
);

let plan_queries = build_plan_queries(plan, &current_models)
// Use the current baseline schema (from all previous migrations)
let plan_queries = build_plan_queries(plan, &baseline_schema)
.map_err(|e| anyhow::anyhow!("query build error for v{}: {}", plan.version, e))?;

// Update baseline schema incrementally by applying each action
for action in &plan.actions {
let _ = apply_action(&mut baseline_schema, action);
}

for (i, pq) in plan_queries.iter().enumerate() {
println!(
" {}. {}",
Expand Down
11 changes: 8 additions & 3 deletions crates/vespertide-cli/src/commands/sql.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use colored::Colorize;
use vespertide_planner::plan_next_migration;
use vespertide_planner::{plan_next_migration_with_baseline, schema_from_plans};
use vespertide_query::{DatabaseBackend, build_plan_queries};

use crate::utils::{load_config, load_migrations, load_models};
Expand All @@ -10,10 +10,15 @@ pub fn cmd_sql(backend: DatabaseBackend) -> Result<()> {
let current_models = load_models(&config)?;
let applied_plans = load_migrations(&config)?;

let plan = plan_next_migration(&current_models, &applied_plans)
// Reconstruct the baseline schema from applied migrations
let baseline_schema = schema_from_plans(&applied_plans)
.map_err(|e| anyhow::anyhow!("failed to reconstruct schema: {}", e))?;

// Plan next migration using the pre-computed baseline
let plan = plan_next_migration_with_baseline(&current_models, &applied_plans, &baseline_schema)
.map_err(|e| anyhow::anyhow!("planning error: {}", e))?;

emit_sql(&plan, backend, &current_models)
emit_sql(&plan, backend, &baseline_schema)
}

fn emit_sql(
Expand Down
Loading