Create a new variant. Args: variant_name (str): The name of the variant. project_id (str): The ID of the project. base (VariantBaseDB): The base of the variant. config (ConfigDB): The config of the variant. base_name (str): The name of the variant base.
(
app: AppDB,
user: UserDB,
variant_name: str,
project_id: str,
base: VariantBaseDB,
config: ConfigDB,
base_name: str,
commit_message: Optional[str] = None,
)
| 464 | |
| 465 | |
| 466 | async def create_new_app_variant( |
| 467 | app: AppDB, |
| 468 | user: UserDB, |
| 469 | variant_name: str, |
| 470 | project_id: str, |
| 471 | base: VariantBaseDB, |
| 472 | config: ConfigDB, |
| 473 | base_name: str, |
| 474 | commit_message: Optional[str] = None, |
| 475 | ) -> AppVariantDB: |
| 476 | """Create a new variant. |
| 477 | |
| 478 | Args: |
| 479 | variant_name (str): The name of the variant. |
| 480 | project_id (str): The ID of the project. |
| 481 | base (VariantBaseDB): The base of the variant. |
| 482 | config (ConfigDB): The config of the variant. |
| 483 | base_name (str): The name of the variant base. |
| 484 | commit_message (Optional[str]): The commit message for the new variant. |
| 485 | |
| 486 | Returns: |
| 487 | AppVariantDB: The created variant. |
| 488 | """ |
| 489 | |
| 490 | assert ( |
| 491 | config.parameters == {} |
| 492 | ), "Parameters should be empty when calling create_new_app_variant (otherwise revision should not be set to 0)" |
| 493 | |
| 494 | async with engine.core_session() as session: |
| 495 | variant = AppVariantDB( |
| 496 | app_id=app.id, |
| 497 | project_id=uuid.UUID(project_id), |
| 498 | modified_by_id=user.id, |
| 499 | revision=0, |
| 500 | variant_name=variant_name, |
| 501 | base_id=base.id, |
| 502 | base_name=base_name, |
| 503 | config_name=config.config_name, |
| 504 | config_parameters=config.parameters, |
| 505 | ) |
| 506 | |
| 507 | session.add(variant) |
| 508 | |
| 509 | await session.commit() |
| 510 | await session.refresh( |
| 511 | variant, |
| 512 | attribute_names=[ |
| 513 | "app", |
| 514 | "base", |
| 515 | ], |
| 516 | ) # Ensures the app, user and base relationship are loaded |
| 517 | |
| 518 | variant_revision = AppVariantRevisionsDB( |
| 519 | variant_id=variant.id, |
| 520 | revision=0, |
| 521 | commit_message=commit_message, |
| 522 | project_id=uuid.UUID(project_id), |
| 523 | modified_by_id=user.id, |
nothing calls this directly
no test coverage detected