(session: SessionDep, ctx: TenantContextDep, id: int)
| 623 | |
| 624 | @router.post("/{id}/set-default") |
| 625 | async def set_default_cluster(session: SessionDep, ctx: TenantContextDep, id: int): |
| 626 | # "Default cluster" is a per-Org concept now: each Org has at most |
| 627 | # one default, and that's what its members' deploy form falls back |
| 628 | # to. Writing it follows the standard cluster-write rule (admin |
| 629 | # always; Org owner only on their own Org's clusters). |
| 630 | cluster = await Cluster.one_by_id(session, id) |
| 631 | if not cluster: |
| 632 | raise NotFoundException(message=f"cluster {id} not found") |
| 633 | assert_cluster_writable(ctx, cluster) |
| 634 | |
| 635 | try: |
| 636 | # Unset any existing default in this cluster's Org. Postgres |
| 637 | # holds this to one via a partial unique index; MySQL/OceanBase |
| 638 | # have no partial-index equivalent, so we tolerate (and clear) |
| 639 | # any duplicates instead of relying on the DB. |
| 640 | existing_defaults = await Cluster.all_by_fields( |
| 641 | session, |
| 642 | { |
| 643 | 'is_default': True, |
| 644 | 'deleted_at': None, |
| 645 | 'owner_principal_id': cluster.owner_principal_id, |
| 646 | }, |
| 647 | ) |
| 648 | for dc in existing_defaults: |
| 649 | if dc.id != cluster.id: |
| 650 | await dc.update( |
| 651 | session=session, |
| 652 | source={"is_default": False}, |
| 653 | auto_commit=False, |
| 654 | ) |
| 655 | # Set this cluster as the Org's default. |
| 656 | await cluster.update( |
| 657 | session=session, |
| 658 | source={"is_default": True}, |
| 659 | auto_commit=False, |
| 660 | ) |
| 661 | await session.commit() |
| 662 | except Exception as e: |
| 663 | raise InternalServerErrorException( |
| 664 | message=f"Failed to set default cluster: {e}" |
| 665 | ) |
| 666 | |
| 667 | |
| 668 | @router.post("/{id}/worker-pools", response_model=WorkerPoolPublic) |
nothing calls this directly
no test coverage detected