brokkr-models::models::stack_annotations
Rust
Stack Annotation Module
This module defines structures and methods for managing stack annotations in the system.
Data Model
Stack annotations are key-value pairs associated with stacks, providing additional metadata.
They are stored in the stack_annotations table with the following structure:
id: UUID, primary keystack_id: UUID, foreign key referencing thestackstablekey: VARCHAR(255), the annotation keyvalue: TEXT, the annotation value
Usage
Stack annotations can be used to add metadata to stacks. This metadata can be used for filtering, grouping, or providing additional information about the stack that doesn’t fit into the main stack structure.
Constraints
- The
stack_idmust be a valid, non-nil UUID. - Both
keyandvaluemust be non-empty strings. - Both
keyandvaluemust not exceed 64 characters. - Neither
keynorvaluecan contain whitespace.
Structs
Section titled “Structs”struct StackAnnotation
Section titled “struct StackAnnotation”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema
Represents a stack annotation in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the annotation. |
stack_id |
Uuid |
ID of the stack this annotation belongs to. |
key |
String |
Key of the annotation (max 64 characters, no whitespace). |
value |
String |
Value of the annotation (max 64 characters, no whitespace). |
struct NewStackAnnotation
Section titled “struct NewStackAnnotation”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new stack annotation to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
ID of the stack this annotation belongs to. |
key |
String |
Key of the annotation (max 64 characters, no whitespace). |
value |
String |
Value of the annotation (max 64 characters, no whitespace). |
Methods
Section titled “Methods”pub
fn new( stack_id: Uuid, key: String, value: String,) -> Result<Self, String>Creates a new NewStackAnnotation instance.
Parameters:
| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
UUID of the stack to associate the annotation with. |
key |
String |
The key for the annotation. Must be non-empty, max 64 characters, and contain no whitespace. |
value |
String |
The value for the annotation. Must be non-empty, max 64 characters, and contain no whitespace. |
Returns:
Returns Ok(NewStackAnnotation) if all parameters are valid,
otherwise returns an Err with a description of the validation failure.
Source
pub fn new(stack_id: Uuid, key: String, value: String) -> Result<Self, String> { // Validate stack_id if stack_id.is_nil() { return Err("Invalid stack ID".to_string()); }
// Validate key if key.is_empty() { return Err("Key cannot be empty".to_string()); } if key.len() > 64 { return Err("Key cannot exceed 64 characters".to_string()); } if key.contains(char::is_whitespace) { return Err("Key cannot contain whitespace".to_string()); }
// Validate value if value.is_empty() { return Err("Value cannot be empty".to_string()); } if value.len() > 64 { return Err("Value cannot exceed 64 characters".to_string()); } if value.contains(char::is_whitespace) { return Err("Value cannot contain whitespace".to_string()); }
Ok(NewStackAnnotation { stack_id, key, value, }) }