| 275 | }) |
| 276 | return err |
| 277 | }) |
| 278 | } |
| 279 | |
| 280 | func (s *gormAPIStore) GetOrg(name string) (*configstore.Org, error) { |
| 281 | var org configstore.Org |
| 282 | if err := s.db().Preload("Users").Preload("Warehouse").Preload("Teams").Preload("Trino").First(&org, "name = ?", name).Error; err != nil { |
| 283 | return nil, err |
| 284 | } |
| 285 | return &org, nil |
| 286 | } |
| 287 | |
| 288 | func (s *gormAPIStore) UpdateOrg(name string, updates configstore.Org) (*configstore.Org, bool, error) { |
| 289 | fields := map[string]interface{}{ |
| 290 | "max_workers": updates.MaxWorkers, |
| 291 | "max_vcpus": updates.MaxVCPUs, |
| 292 | // Org default worker profile: written unconditionally so an explicit |
| 293 | // empty string CLEARS the default (the handler's presence-merge keeps |
| 294 | // omitted fields at their stored values before this runs). |
| 295 | "default_worker_cpu": updates.DefaultWorkerCPU, |
| 296 | "default_worker_memory": updates.DefaultWorkerMemory, |
| 297 | "default_worker_ttl": updates.DefaultWorkerTTL, |
| 298 | "default_worker_min_hot_idle": updates.DefaultWorkerMinHotIdle, |
| 299 | // Hot-idle pool caps: written unconditionally for the same reason — |
| 300 | // 0 / "" clears the cap back to unlimited after the presence-merge. |
| 301 | "max_hot_idle_workers": updates.MaxHotIdleWorkers, |
| 302 | "max_hot_idle_cpu": updates.MaxHotIdleCPU, |
| 303 | "max_hot_idle_memory": updates.MaxHotIdleMemory, |
| 304 | } |
| 305 | if updates.DataImportsTableNamingVersion != "" { |
| 306 | fields["data_imports_table_naming_version"] = updates.DataImportsTableNamingVersion |
| 307 | } |
| 308 | // DatabaseName is "" = preserve (the column is NOT NULL and the handler's |
| 309 | // presence-merge has already preserved omitted fields, so a "" here can |
| 310 | // only mean "key absent"). A non-empty value renames the database — and |
| 311 | // with it the org's managed hostname (<database_name>.<managed-suffix>), |
| 312 | // which is exactly the operator surface for fixing orgs whose stored name |
| 313 | // is not a routable DNS label. The unique index still guards collisions; |
| 314 | // validation lives in the handler. |
| 315 | if updates.DatabaseName != "" { |