Skip to content

brokkr-models::models::stacks

Rust

Stack Module

This module defines structures and methods for managing stacks in the system.

Data Model

Stacks represent a collection of related deployment objects and configurations. They are stored in the stacks table with the following structure:

  • id: UUID, primary key
  • created_at: TIMESTAMP, when the stack was created
  • updated_at: TIMESTAMP, when the stack was last updated
  • deleted_at: TIMESTAMP, for soft deletion support
  • name: VARCHAR(255), name of the stack
  • description: TEXT, optional description of the stack

Usage

Stacks are core entities in the system, representing a logical grouping of deployment objects. They can be associated with agents, labeled, and annotated for better organization and management.

Constraints

  • The name must be a non-empty string.
  • The description, if provided, must not be an empty string.
  • There should be a unique constraint on the name field.

pub

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

Represents a stack in the database.

Name Type Description
id Uuid Unique identifier for the stack.
created_at DateTime<Utc> Timestamp when the stack was created.
updated_at DateTime<Utc> Timestamp when the stack was last updated.
deleted_at Option<DateTime<Utc>> Timestamp for soft deletion, if applicable.
name String Name of the stack.
description Option<String> Optional description of the stack.
generator_id Uuid Optional generator ID.

pub

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

Represents a new stack to be inserted into the database.

Name Type Description
name String Name of the stack.
description Option<String> Optional description of the stack.
generator_id Uuid Optional generator ID.

pub

fn new(
name: String,
description: Option<String>,
generator_id: Uuid,
) -> Result<Self, String>

Creates a new NewStack instance.

Parameters:

Name Type Description
name String Name of the stack. Must be a non-empty string.
description Option<String> Optional description of the stack. If provided, must not be an empty string.
generator_id Uuid Optional generator ID.

Returns:

Returns Ok(NewStack) if all parameters are valid, otherwise returns an Err with a description of the validation failure.

Source
pub fn new(
name: String,
description: Option<String>,
generator_id: Uuid,
) -> Result<Self, String> {
// Validate name
if name.trim().is_empty() {
return Err("Stack name cannot be empty".to_string());
}
// Validate description (if provided)
if let Some(desc) = &description
&& desc.trim().is_empty()
{
return Err("Stack description cannot be empty if provided".to_string());
}
Ok(NewStack {
name,
description,
generator_id,
})
}