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_Df5l-MonoWWam1dtfDfhT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-naming/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch"},"note":"Add vespera schema_type","date":"2026-02-03T17:13:06.154567800Z"}
20 changes: 10 additions & 10 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions crates/vespertide-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub struct SeaOrmConfig {
/// Default: `Camel` (generates `#[serde(rename_all = "camelCase")]`)
#[serde(default = "default_enum_naming_case")]
pub enum_naming_case: NameCase,
/// Generate `vespera::schema_type!` macro invocation for each entity.
/// Default: `true`
#[serde(default = "default_vespera_schema_type")]
pub vespera_schema_type: bool,
}

fn default_extra_enum_derives() -> Vec<String> {
Expand All @@ -36,12 +40,17 @@ fn default_enum_naming_case() -> NameCase {
NameCase::Camel
}

fn default_vespera_schema_type() -> bool {
true
}

impl Default for SeaOrmConfig {
fn default() -> Self {
Self {
extra_enum_derives: default_extra_enum_derives(),
extra_model_derives: Vec::new(),
enum_naming_case: default_enum_naming_case(),
vespera_schema_type: default_vespera_schema_type(),
}
}
}
Expand All @@ -61,6 +70,11 @@ impl SeaOrmConfig {
pub fn enum_naming_case(&self) -> NameCase {
self.enum_naming_case
}

/// Whether to generate `vespera::schema_type!` macro invocation for each entity.
pub fn vespera_schema_type(&self) -> bool {
self.vespera_schema_type
}
}

/// Top-level vespertide configuration.
Expand Down Expand Up @@ -192,6 +206,7 @@ mod tests {
vec!["vespera::Schema".to_string()]
);
assert!(config.seaorm.extra_model_derives.is_empty());
assert!(config.seaorm.vespera_schema_type);
assert_eq!(config.prefix, "");
}

Expand Down
9 changes: 9 additions & 0 deletions crates/vespertide-exporter/src/seaorm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ pub fn render_entity_with_config(
lines.push(String::new());
render_indexes(&mut lines, &table.constraints);

// Generate vespera::schema_type! macro if enabled
if config.vespera_schema_type() {
let pascal_name = to_pascal_case(&table.name);
lines.push(format!(
"vespera::schema_type!(Schema from Model, name = \"{}Schema\");",
pascal_name
));
}

lines.push("impl ActiveModelBehavior for ActiveModel {}".into());

lines.push(String::new());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ pub struct Model {
pub status: TaskStatus,
}

vespera::schema_type!(Schema from Model, name = "TasksSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ pub struct Model {
pub status: TaskStatus,
}

vespera::schema_type!(Schema from Model, name = "TasksSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pub struct Model {
pub display_name: Option<String>,
}

vespera::schema_type!(Schema from Model, name = "UsersSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct Model {
pub tenant_id: i64,
}

vespera::schema_type!(Schema from Model, name = "AccountsSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ pub struct Model {
pub availability: AvailabilityStatus,
}

vespera::schema_type!(Schema from Model, name = "ProductsSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ pub struct Model {
pub priority: Option<TaskPriority>,
}

vespera::schema_type!(Schema from Model, name = "TasksSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ pub struct Model {
pub review_status: Option<DocStatus>,
}

vespera::schema_type!(Schema from Model, name = "DocumentsSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ pub struct Model {
pub severity: EventSeverity,
}

vespera::schema_type!(Schema from Model, name = "EventsSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ pub struct Model {
pub status: OrderStatus,
}

vespera::schema_type!(Schema from Model, name = "OrdersSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ pub struct Model {
pub is_archived: bool,
}

vespera::schema_type!(Schema from Model, name = "TasksSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub struct Model {
pub customers: HasOne<super::customers::Entity>,
}

vespera::schema_type!(Schema from Model, name = "InvoicesSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub struct Model {
pub user: HasOne<super::users::Entity>,
}

vespera::schema_type!(Schema from Model, name = "PostsSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pub struct Model {
pub email: String,
}

vespera::schema_type!(Schema from Model, name = "UsersSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pub struct Model {
pub jsonb_nullable: Option<Json>,
}

vespera::schema_type!(Schema from Model, name = "JsonStructSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ pub struct Model {
// Index definitions (SeaORM uses Statement builders externally)
// (unnamed) on [article_id]
// (unnamed) on [user_id]
vespera::schema_type!(Schema from Model, name = "ArticleUserSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct Model {
pub total: f32,
}

vespera::schema_type!(Schema from Model, name = "OrdersSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ pub struct Model {

// Index definitions (SeaORM uses Statement builders externally)
// idx_department on [department]
vespera::schema_type!(Schema from Model, name = "UsersSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ pub struct Model {
pub child_manies: HasMany<super::child_many::Entity>,
}

vespera::schema_type!(Schema from Model, name = "ParentSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub struct Model {
pub users: HasMany<super::user::Entity>,
}

vespera::schema_type!(Schema from Model, name = "ArticleSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct Model {
pub article_users: HasMany<super::article_user::Entity>,
}

vespera::schema_type!(Schema from Model, name = "ArticleSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub struct Model {
pub articles: HasMany<super::article::Entity>,
}

vespera::schema_type!(Schema from Model, name = "UserSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ pub struct Model {
pub used_by_user: HasOne<super::user::Entity>,
}

vespera::schema_type!(Schema from Model, name = "PostSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub struct Model {
pub updated_by_user: HasOne<super::settings::Entity>,
}

vespera::schema_type!(Schema from Model, name = "UserSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub struct Model {
pub backup_user_profiles: HasMany<super::profile::Entity>,
}

vespera::schema_type!(Schema from Model, name = "UserSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct Model {
pub not_junctions: HasMany<super::not_junction::Entity>,
}

vespera::schema_type!(Schema from Model, name = "AnotherSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct Model {
pub not_junctions: HasMany<super::not_junction::Entity>,
}

vespera::schema_type!(Schema from Model, name = "OtherSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct Model {
pub regulars: HasMany<super::regular::Entity>,
}

vespera::schema_type!(Schema from Model, name = "OtherSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ pub struct Model {
pub id: i32,
}

vespera::schema_type!(Schema from Model, name = "TestSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ pub struct Model {
pub id: i32,
}

vespera::schema_type!(Schema from Model, name = "TestSchema");
impl ActiveModelBehavior for ActiveModel {}
8 changes: 7 additions & 1 deletion schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"extraEnumDerives": [
"vespera::Schema"
],
"extraModelDerives": []
"extraModelDerives": [],
"vesperaSchemaType": true
}
},
"tableNamingCase": {
Expand Down Expand Up @@ -101,6 +102,11 @@
"items": {
"type": "string"
}
},
"vesperaSchemaType": {
"description": "Generate `vespera::schema_type!` macro invocation for each entity.\nDefault: `true`",
"type": "boolean",
"default": true
}
}
}
Expand Down