package wages import ( "context" "github.com/jackc/pgx/v5/pgxpool" ) // acquirePool resolves the pool to query and a release the caller MUST defer. // // These services read GLOBAL reference tables (SAM opportunities, awards, BLS wages) that carry no // organization_id and no row level security, so they do not need a tenant transaction. They do need a // pool that actually exists, and under per tenant routing the DB has none of its own: reading s.db.Pool // directly was a nil dereference that PANICKED the request. Acquire returns the leaf pool for the // caller's tenant, where these same global tables live because they are part of the shared migration set. // // In shared mode this is a no op wrapper over the single pool. func (s *Service) acquirePool(ctx context.Context) (*pgxpool.Pool, func(), error) { leaf, release, err := s.db.Acquire(ctx) if err != nil { return nil, nil, err } if leaf.Pool == nil { release() return nil, nil, ErrNoDatabase } return leaf.Pool, release, nil }