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 queryid
- Unique identifier of the application to updatename
- Optional new name for the applicationgit_repo
- Optional new Git repository URLgit_branch
- Optional new Git branchcontainer_image_url
- Optional new container image URLregion_id
- Optional new region IDmaintenance_mode
- Optional new maintenance mode status
§Returns
Ok(App)
- Successfully updated application with all current valuesErr(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.