feat(coderd/database): track user status changes over time (#16019)

RE: https://github.com/coder/coder/issues/15740,
https://github.com/coder/coder/issues/15297

In order to add a graph to the coder frontend to show user status over
time as an indicator of license usage, this PR adds the following:

* a new `api.insightsUserStatusCountsOverTime` endpoint to the API
* which calls a new `GetUserStatusCountsOverTime` query from postgres
* which relies on two new tables `user_status_changes` and
`user_deleted`
* which are populated by a new trigger and function that tracks updates
to the users table

The chart itself will be added in a subsequent PR

---------

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
This commit is contained in:
Sas Swart
2025-01-13 13:08:16 +02:00
committed by GitHub
parent 73d8dde6ed
commit 4543b21b7c
25 changed files with 1456 additions and 3 deletions

61
coderd/apidoc/docs.go generated
View File

@ -1398,6 +1398,40 @@ const docTemplate = `{
}
}
},
"/insights/user-status-counts": {
"get": {
"security": [
{
"CoderSessionToken": []
}
],
"produces": [
"application/json"
],
"tags": [
"Insights"
],
"summary": "Get insights about user status counts",
"operationId": "get-insights-about-user-status-counts",
"parameters": [
{
"type": "integer",
"description": "Time-zone offset (e.g. -2)",
"name": "tz_offset",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/codersdk.GetUserStatusCountsResponse"
}
}
}
}
},
"/integrations/jfrog/xray-scan": {
"get": {
"security": [
@ -11207,6 +11241,20 @@ const docTemplate = `{
}
}
},
"codersdk.GetUserStatusCountsResponse": {
"type": "object",
"properties": {
"status_counts": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"$ref": "#/definitions/codersdk.UserStatusChangeCount"
}
}
}
}
},
"codersdk.GetUsersResponse": {
"type": "object",
"properties": {
@ -14570,6 +14618,19 @@ const docTemplate = `{
"UserStatusSuspended"
]
},
"codersdk.UserStatusChangeCount": {
"type": "object",
"properties": {
"count": {
"type": "integer",
"example": 10
},
"date": {
"type": "string",
"format": "date-time"
}
}
},
"codersdk.ValidateUserPasswordRequest": {
"type": "object",
"required": [