brokkr-models::models::template_targets
Rust
Template Target Module
This module defines structures and methods for managing template targets in the system.
Data Model
Template targets represent the association between templates and stacks. They track which stacks a template is compatible with based on label matching at the time of template creation.
id: UUID, primary keytemplate_id: UUID, foreign key referencing thestack_templatestablestack_id: UUID, foreign key referencing thestackstablecreated_at: TIMESTAMP, when the target association was created
Usage
Template targets are used to define which stacks a template can be instantiated into. When a template is created with labels, the system computes compatible stacks and stores these associations. This enables efficient querying of valid template-stack combinations without recomputing label matches on every request.
Constraints
- Both
template_idandstack_idmust be valid, non-nil UUIDs. - There is a unique constraint on the combination of
template_idandstack_idto prevent duplicate associations.
Structs
Section titled “Structs”struct TemplateTarget
Section titled “struct TemplateTarget”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema
Represents a template target in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the template target. |
template_id |
Uuid |
ID of the template associated with this target. |
stack_id |
Uuid |
ID of the stack associated with this target. |
created_at |
DateTime<Utc> |
Timestamp when the target association was created. |
struct NewTemplateTarget
Section titled “struct NewTemplateTarget”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new template target to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
template_id |
Uuid |
ID of the template to associate with a stack. |
stack_id |
Uuid |
ID of the stack to associate with a template. |
Methods
Section titled “Methods”pub
fn new(template_id: Uuid, stack_id: Uuid) -> Result<Self, String>Creates a new NewTemplateTarget instance.
Parameters:
| Name | Type | Description |
|---|---|---|
template_id |
Uuid |
UUID of the template to associate with a stack. |
stack_id |
Uuid |
UUID of the stack to associate with a template. |
Returns:
Returns Ok(NewTemplateTarget) if both UUIDs are valid and non-nil,
otherwise returns an Err with a description of the validation failure.
Source
pub fn new(template_id: Uuid, stack_id: Uuid) -> Result<Self, String> { // Validate template_id if template_id.is_nil() { return Err("Invalid template ID".to_string()); }
// Validate stack_id if stack_id.is_nil() { return Err("Invalid stack ID".to_string()); }
Ok(NewTemplateTarget { template_id, stack_id, }) }