Function update_app

Source
pub async fn update_app(
    pool: &Pool<MySql>,
    id: i64,
    name: Option<&str>,
    git_repo: Option<&str>,
    git_branch: Option<&str>,
    container_image_url: Option<&str>,
    region_id: Option<i64>,
    maintenance_mode: Option<bool>,
) -> Result<App>
Expand description

Updates an existing application in the database.

This function modifies an application record with the provided parameters. It uses a dynamic SQL query that only updates fields for which values are provided, leaving other fields unchanged. The updated_at timestamp is always updated to reflect the modification time.

§Arguments

  • pool - Database connection pool for executing the query
  • id - Unique identifier of the application to update
  • name - Optional new name for the application
  • git_repo - Optional new Git repository URL
  • git_branch - Optional new Git branch
  • container_image_url - Optional new container image URL
  • region_id - Optional new region ID
  • maintenance_mode - Optional new maintenance mode status

§Returns

  • Ok(App) - Successfully updated application with all current values
  • Err(anyhow::Error) - Failed to update application

§Dynamic Query Building

The function dynamically constructs the UPDATE SQL statement based on which parameters have values. This ensures the query only updates the fields that need to change, improving efficiency and reducing the risk of unintended changes.

§Transaction Handling

This function uses a database transaction to ensure atomicity of the operation. If any part of the operation fails, the entire operation is rolled back.