Skip to content

Commit 3a14c20

Browse files
committed
Add check
1 parent a15b084 commit 3a14c20

5 files changed

Lines changed: 400 additions & 1 deletion

File tree

crates/vespertide-cli/src/utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::PathBuf;
44
use anyhow::{Context, Result};
55
use vespertide_config::{FileFormat, VespertideConfig};
66
use vespertide_core::{MigrationPlan, TableDef};
7+
use vespertide_planner::validate_schema;
78

89
/// Load vespertide.json config from current directory.
910
pub fn load_config() -> Result<VespertideConfig> {
@@ -51,6 +52,12 @@ pub fn load_models(config: &VespertideConfig) -> Result<Vec<TableDef>> {
5152
}
5253
}
5354

55+
// Validate schema integrity before returning
56+
if !tables.is_empty() {
57+
validate_schema(&tables)
58+
.map_err(|e| anyhow::anyhow!("schema validation failed: {}", e))?;
59+
}
60+
5461
Ok(tables)
5562
}
5663

crates/vespertide-planner/src/error.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,17 @@ pub enum PlannerError {
1212
ColumnNotFound(String, String),
1313
#[error("index not found: {0}.{1}")]
1414
IndexNotFound(String, String),
15+
#[error("duplicate table name: {0}")]
16+
DuplicateTableName(String),
17+
#[error("foreign key references non-existent table: {0}.{1} -> {2}")]
18+
ForeignKeyTableNotFound(String, String, String),
19+
#[error("foreign key references non-existent column: {0}.{1} -> {2}.{3}")]
20+
ForeignKeyColumnNotFound(String, String, String, String),
21+
#[error("index references non-existent column: {0}.{1} -> {2}")]
22+
IndexColumnNotFound(String, String, String),
23+
#[error("constraint references non-existent column: {0}.{1} -> {2}")]
24+
ConstraintColumnNotFound(String, String, String),
25+
#[error("constraint has empty column list: {0}.{1}")]
26+
EmptyConstraintColumns(String, String),
1527
}
1628

crates/vespertide-planner/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ pub mod diff;
33
pub mod error;
44
pub mod plan;
55
pub mod schema;
6+
pub mod validate;
67

78
pub use error::PlannerError;
89
pub use plan::plan_next_migration;
910
pub use schema::schema_from_plans;
1011
pub use diff::diff_schemas;
1112
pub use apply::apply_action;
13+
pub use validate::validate_schema;

0 commit comments

Comments
 (0)