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_VBxNuIzZ8oAhXU1OCJ7ow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch"},"note":"Add column validation","date":"2025-12-18T15:48:46.157103400Z"}
1 change: 1 addition & 0 deletions .changepacks/changepack_log_YlSdZ6-kG9UnxW5iK-l9X.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch"},"note":"Implement num_enum","date":"2025-12-18T15:48:35.861293400Z"}
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
local.db
settings.local.json
/target
local.db
settings.local.json
coverage
30 changes: 21 additions & 9 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/vespertide-cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
#[case(
MigrationAction::AddColumn {
table: "users".into(),
column: ColumnDef {
column: Box::new(ColumnDef {
name: "name".into(),
r#type: ColumnType::Simple(SimpleColumnType::Text),
nullable: true,
Expand All @@ -258,7 +258,7 @@ mod tests {
unique: None,
index: None,
foreign_key: None,
},
}),
fill_with: None,
},
format!("{} {}.{}", "Add column:".bright_green(), "users".bright_cyan(), "name".bright_cyan().bold())
Expand Down
8 changes: 6 additions & 2 deletions crates/vespertide-cli/src/commands/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::{Context, Result};
use clap::ValueEnum;
use vespertide_config::VespertideConfig;
use vespertide_core::TableDef;
use vespertide_exporter::{Orm, render_entity};
use vespertide_exporter::{Orm, render_entity_with_schema};

use crate::utils::load_config;

Expand Down Expand Up @@ -51,8 +51,12 @@ pub fn cmd_export(orm: OrmArg, export_dir: Option<PathBuf>) -> Result<()> {

let orm_kind: Orm = orm.into();

// Extract all tables for schema context (used for FK chain resolution)
let all_tables: Vec<TableDef> = normalized_models.iter().map(|(t, _)| t.clone()).collect();

for (table, rel_path) in &normalized_models {
let code = render_entity(orm_kind, table).map_err(|e| anyhow::anyhow!(e))?;
let code = render_entity_with_schema(orm_kind, table, &all_tables)
.map_err(|e| anyhow::anyhow!(e))?;
let out_path = build_output_path(&target_root, rel_path, orm_kind);
if let Some(parent) = out_path.parent() {
fs::create_dir_all(parent)
Expand Down
4 changes: 2 additions & 2 deletions crates/vespertide-cli/src/commands/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ mod tests {
version: 1,
actions: vec![MigrationAction::AddColumn {
table: "users".into(),
column: ColumnDef {
column: Box::new(ColumnDef {
name: "nickname".into(),
r#type: ColumnType::Simple(SimpleColumnType::Text),
nullable: false,
Expand All @@ -441,7 +441,7 @@ mod tests {
unique: None,
index: None,
foreign_key: None,
},
}),
fill_with: Some("default".into()),
}],
};
Expand Down
4 changes: 2 additions & 2 deletions crates/vespertide-core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum MigrationAction {
},
AddColumn {
table: TableName,
column: ColumnDef,
column: Box<ColumnDef>,
/// Optional fill value to backfill existing rows when adding NOT NULL without default.
fill_with: Option<String>,
},
Expand Down Expand Up @@ -194,7 +194,7 @@ mod tests {
#[case::add_column(
MigrationAction::AddColumn {
table: "users".into(),
column: default_column(),
column: Box::new(default_column()),
fill_with: None,
},
"AddColumn: users.email"
Expand Down
21 changes: 11 additions & 10 deletions crates/vespertide-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pub mod action;
pub mod migration;
pub mod schema;

pub use action::{MigrationAction, MigrationPlan};
pub use migration::{MigrationError, MigrationOptions};
pub use schema::{
ColumnDef, ColumnName, ColumnType, ComplexColumnType, IndexDef, IndexName, ReferenceAction,
SimpleColumnType, StrOrBoolOrArray, TableConstraint, TableDef, TableName, TableValidationError,
};
pub mod action;
pub mod migration;
pub mod schema;

pub use action::{MigrationAction, MigrationPlan};
pub use migration::{MigrationError, MigrationOptions};
pub use schema::{
ColumnDef, ColumnName, ColumnType, ComplexColumnType, EnumValues, IndexDef, IndexName,
NumValue, ReferenceAction, SimpleColumnType, StrOrBoolOrArray, TableConstraint, TableDef,
TableName, TableValidationError,
};
Loading