Skip to content

brokkr-models::models::deployment_objects

Rust

Deployment Object Module

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

Data Model

Deployment objects represent individual deployments or changes to a stack’s configuration. They are stored in the deployment_objects table with the following structure:

  • id: UUID, primary key
  • created_at: TIMESTAMP, when the deployment object was created
  • updated_at: TIMESTAMP, when the deployment object was last updated
  • deleted_at: TIMESTAMP, for soft deletion support
  • sequence_id: BIGSERIAL, auto-incrementing sequence number for ordering
  • stack_id: UUID, foreign key referencing the stacks table
  • yaml_content: TEXT, the YAML content of the deployment
  • yaml_checksum: VARCHAR(64), SHA-256 checksum of the YAML content
  • submitted_at: TIMESTAMP, when the deployment was submitted
  • is_deletion_marker: BOOLEAN, indicates if this object marks a deletion
  • generator_id: UUID, ID of the generator associated with this deployment object

Usage

Deployment objects are used to track changes and updates to stack configurations over time. They provide a historical record of deployments and can be used for rollbacks, audits, and tracking the evolution of a stack’s configuration.

Constraints

  • The stack_id must be a valid, non-nil UUID.
  • The yaml_content must not be empty.
  • The yaml_checksum is automatically generated from the yaml_content.
  • Deployment objects are designed to be immutable after creation, with exceptions for soft deletion.

pub

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

Represents a deployment object in the database.

Name Type Description
id Uuid Unique identifier for the deployment object.
created_at DateTime<Utc> Timestamp when the deployment object was created.
updated_at DateTime<Utc> Timestamp when the deployment object was last updated.
deleted_at Option<DateTime<Utc>> Timestamp for soft deletion, if applicable.
sequence_id i64 Auto-incrementing sequence number for ordering.
stack_id Uuid ID of the stack this deployment object belongs to.
yaml_content String YAML content of the deployment.
yaml_checksum String SHA-256 checksum of the YAML content.
submitted_at DateTime<Utc> Timestamp when the deployment was submitted.
is_deletion_marker bool Indicates if this object marks a deletion.

pub

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

Represents a new deployment object to be inserted into the database.

Name Type Description
stack_id Uuid ID of the stack this deployment object belongs to.
yaml_content String YAML content of the deployment.
yaml_checksum String SHA-256 checksum of the YAML content.
is_deletion_marker bool Indicates if this object marks a deletion.

pub

fn new(
stack_id: Uuid,
yaml_content: String,
is_deletion_marker: bool,
) -> Result<Self, String>

Creates a new NewDeploymentObject instance.

Parameters:

Name Type Description
stack_id Uuid UUID of the stack this deployment object belongs to.
yaml_content String YAML content of the deployment. Must be a non-empty string.
is_deletion_marker bool Boolean indicating if this object marks a deletion.
generator_id - UUID of the generator associated with this deployment object.

Returns:

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

Source
pub fn new(
stack_id: Uuid,
yaml_content: String,
is_deletion_marker: bool,
) -> Result<Self, String> {
// Validate stack_id
if stack_id.is_nil() {
return Err("Invalid stack ID".to_string());
}
// Validate yaml_content. Deletion markers are allowed to be empty:
// the agent removes resources by the stack annotation, so a marker's
// body is never read (BROKKR-T-0194).
if !is_deletion_marker && yaml_content.trim().is_empty() {
return Err("YAML content cannot be empty".to_string());
}
// Generate SHA-256 checksum
let yaml_checksum = generate_checksum(&yaml_content);
Ok(NewDeploymentObject {
stack_id,
yaml_content,
yaml_checksum,
is_deletion_marker,
})
}