Skip to content

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 key
  • template_id: UUID, foreign key referencing the stack_templates table
  • stack_id: UUID, foreign key referencing the stacks table
  • created_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_id and stack_id must be valid, non-nil UUIDs.
  • There is a unique constraint on the combination of template_id and stack_id to prevent duplicate associations.

pub

Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema

Represents a template target in the database.

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.

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema

Represents a new template target to be inserted into the database.

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.

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,
})
}