Update the app in the database. Arguments: app_id (str): The app id values_to_update (dict): The values to update in the app
(app_id: str, values_to_update: dict)
| 639 | |
| 640 | |
| 641 | async def update_app(app_id: str, values_to_update: dict) -> None: |
| 642 | """Update the app in the database. |
| 643 | |
| 644 | Arguments: |
| 645 | app_id (str): The app id |
| 646 | values_to_update (dict): The values to update in the app |
| 647 | """ |
| 648 | |
| 649 | async with engine.core_session() as session: |
| 650 | result = await session.execute(select(AppDB).filter_by(id=uuid.UUID(app_id))) |
| 651 | app = result.scalars().first() |
| 652 | if not app: |
| 653 | raise NoResultFound(f"App with {app_id} not found") |
| 654 | |
| 655 | # Check if 'app_name' is in the values to update |
| 656 | if "app_name" in values_to_update: |
| 657 | new_app_name = values_to_update["app_name"] |
| 658 | |
| 659 | # Check if another app with the same name exists for the user |
| 660 | existing_app_result = await session.execute( |
| 661 | select(AppDB) |
| 662 | .filter( |
| 663 | AppDB.project_id == app.project_id |
| 664 | ) # Assuming 'user_id' exists on the AppDB model |
| 665 | .filter(AppDB.app_name == new_app_name) |
| 666 | ) |
| 667 | existing_app = existing_app_result.scalars().first() |
| 668 | |
| 669 | if existing_app: |
| 670 | raise Exception( |
| 671 | f"Cannot update app name to '{new_app_name}' because another app with this name already exists." |
| 672 | ) |
| 673 | |
| 674 | for key, value in values_to_update.items(): |
| 675 | if hasattr(app, key): |
| 676 | setattr(app, key, value) |
| 677 | |
| 678 | await session.commit() |
| 679 | |
| 680 | |
| 681 | async def get_deployment_by_id(deployment_id: str) -> DeploymentDB: |
nothing calls this directly
no test coverage detected