fix: improve error message when deleting organization with resources (#17049)

Closes
[coder/internal#477](https://github.com/coder/internal/issues/477)

![Screenshot 2025-03-21 at 11 25
57 AM](https://github.com/user-attachments/assets/50cc03e9-395d-4fc7-8882-18cb66b1fac9)

I'm solving this issue in two parts:

1. Updated the postgres function so that it doesn't omit 0 values in the
error
2. Created a new query to fetch the number of resources associated with
an organization and using that information to provider a cleaner error
message to the frontend

> **_NOTE:_** SQL is not my strong suit, and the code was created with
the help of AI. So I'd take extra time looking over what I wrote there
This commit is contained in:
brettkolodny
2025-03-25 15:31:24 -04:00
committed by GitHub
parent 2c53f7ae7c
commit cf10d98aab
13 changed files with 416 additions and 22 deletions

View File

@ -1012,6 +1012,13 @@ func (m queryMetricsStore) GetOrganizationIDsByMemberIDs(ctx context.Context, id
return organizations, err
}
func (m queryMetricsStore) GetOrganizationResourceCountByID(ctx context.Context, organizationID uuid.UUID) (database.GetOrganizationResourceCountByIDRow, error) {
start := time.Now()
r0, r1 := m.s.GetOrganizationResourceCountByID(ctx, organizationID)
m.queryLatencies.WithLabelValues("GetOrganizationResourceCountByID").Observe(time.Since(start).Seconds())
return r0, r1
}
func (m queryMetricsStore) GetOrganizations(ctx context.Context, args database.GetOrganizationsParams) ([]database.Organization, error) {
start := time.Now()
organizations, err := m.s.GetOrganizations(ctx, args)