MCPcopy Create free account
hub / github.com/PostHog/duckgres / validateOrgDefaultWorkerProfile

Function validateOrgDefaultWorkerProfile

controlplane/admin/api.go:748–774  ·  view source on GitHub ↗

validateOrgDefaultWorkerProfile rejects garbage default-worker-profile values at the API boundary so they can never enter the config store (the control plane tolerates bad rows by ignoring them, but a 400 here surfaces the typo to the operator instead of a silently-ignored default). Empty strings ar

(org *configstore.Org)

Source from the content-addressed store, hash-verified

746 orgExists bool
747 )
748 err := s.db().Transaction(func(tx *gorm.DB) error {
749 if err := configstore.LockOrgConnectionAdmissionTx(tx, orgID); err != nil {
750 return err
751 }
752
753 var count int64
754 if err := tx.Model(&configstore.Org{}).Where("name = ?", orgID).Count(&count).Error; err != nil {
755 return err
756 }
757 if count == 0 {
758 return nil
759 }
760 orgExists = true
761
762 // SELECT ... FOR UPDATE: blocks concurrent mutators on the same row
763 // until this transaction commits. A missing row is not an error —
764 // PUT on a brand-new warehouse lands in the same path.
765 var warehouse configstore.ManagedWarehouse
766 err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).
767 First(&warehouse, "org_id = ?", orgID).Error
768 if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
769 return err
770 }
771
772 before := warehouse
773 missing := errors.Is(err, gorm.ErrRecordNotFound)
774
775 if err := mutate(&warehouse); err != nil {
776 return err
777 }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected