feat(limits): limit the monitors shown on one status page
Platform admins set a default for how many monitors a status page may show, and an override per organization, like the other limits. Saving a page with more gives 422 page_monitor_limit; a page beyond a lowered limit keeps its monitors but cannot grow. The page editor names the limit and the organization's usage lists it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
4cde0f7e56
commit
ca852c8299
17 files changed
+611
-416
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
const adminListOrgs = `-- name: AdminListOrgs :many
|
||||
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
|
||||
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
|
||||
o.limit_monitors_per_page,
|
||||
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
|
||||
(SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages,
|
||||
coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id,
|
||||
@@ -61,6 +62,7 @@ type AdminListOrgsRow struct {
|
||||
LimitStatusPages *int32
|
||||
LimitRegionsPerMonitor *int32
|
||||
LimitOwnRegionsCount *bool
|
||||
LimitMonitorsPerPage *int32
|
||||
Monitors int32
|
||||
StatusPages int32
|
||||
OwnerID uuid.UUID
|
||||
@@ -102,6 +104,7 @@ func (q *Queries) AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([
|
||||
&i.LimitStatusPages,
|
||||
&i.LimitRegionsPerMonitor,
|
||||
&i.LimitOwnRegionsCount,
|
||||
&i.LimitMonitorsPerPage,
|
||||
&i.Monitors,
|
||||
&i.StatusPages,
|
||||
&i.OwnerID,
|
||||
@@ -133,6 +136,17 @@ func (q *Queries) CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, er
|
||||
return count, err
|
||||
}
|
||||
|
||||
const countStatusPageMonitors = `-- name: CountStatusPageMonitors :one
|
||||
SELECT count(*) FROM status_page_monitors WHERE page_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CountStatusPageMonitors(ctx context.Context, pageID uuid.UUID) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countStatusPageMonitors, pageID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const countStatusPages = `-- name: CountStatusPages :one
|
||||
SELECT count(*) FROM status_pages WHERE org_id = $1
|
||||
`
|
||||
@@ -157,8 +171,9 @@ func (q *Queries) LockOrgUsage(ctx context.Context, orgID uuid.UUID) error {
|
||||
|
||||
const setOrgLimits = `-- name: SetOrgLimits :one
|
||||
UPDATE orgs SET limit_monitors = $1, limit_status_pages = $2,
|
||||
limit_regions_per_monitor = $3, limit_own_regions_count = $4
|
||||
WHERE id = $5
|
||||
limit_regions_per_monitor = $3, limit_own_regions_count = $4,
|
||||
limit_monitors_per_page = $5
|
||||
WHERE id = $6
|
||||
RETURNING id, slug
|
||||
`
|
||||
|
||||
@@ -167,6 +182,7 @@ type SetOrgLimitsParams struct {
|
||||
StatusPages *int32
|
||||
RegionsPerMonitor *int32
|
||||
OwnRegionsCount *bool
|
||||
MonitorsPerPage *int32
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
@@ -181,6 +197,7 @@ func (q *Queries) SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (Set
|
||||
arg.StatusPages,
|
||||
arg.RegionsPerMonitor,
|
||||
arg.OwnRegionsCount,
|
||||
arg.MonitorsPerPage,
|
||||
arg.ID,
|
||||
)
|
||||
var i SetOrgLimitsRow
|
||||
|
||||
Reference in new issue
Block a user