mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add ai_user_daily_spend table and queries (#26562)
## Description Adds the spend tracking table and queries needed by [AIGOV-427](https://linear.app/codercom/issue/AIGOV-427/add-post-response-spend-accumulation) (post-response accumulation) and [AIGOV-428](https://linear.app/codercom/issue/AIGOV-428/add-pre-request-budget-enforcement) (pre-request enforcement). ## Changes - Add `ai_user_daily_spend` table to aggregate per-user, per-effective-group AI spend by UTC day. - Add `UpsertUserAIDailySpend` and `GetUserAISpendSince` queries. Closes https://linear.app/codercom/issue/AIGOV-426/add-daily-spend-table-and-queries > [!NOTE] > Initially generated by Claude Opus 4.7, modified and reviewed by @ssncferreira
This commit is contained in:
Generated
+12
@@ -4678,6 +4678,18 @@ type AISeatState struct {
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Daily AI spend per user and effective group.
|
||||
type AIUserDailySpend struct {
|
||||
// The user who incurred the spend.
|
||||
UserID uuid.UUID `db:"user_id" json:"user_id"`
|
||||
// The group this spend is attributed to for budget purposes.
|
||||
EffectiveGroupID uuid.UUID `db:"effective_group_id" json:"effective_group_id"`
|
||||
// UTC calendar day the spend was incurred.
|
||||
Day time.Time `db:"day" json:"day"`
|
||||
// Accumulated spend in micro-units (1 unit = 1,000,000).
|
||||
SpendMicros int64 `db:"spend_micros" json:"spend_micros"`
|
||||
}
|
||||
|
||||
type APIKey struct {
|
||||
ID string `db:"id" json:"id"`
|
||||
// hashed_secret contains a SHA256 hash of the key secret. This is considered a secret and MUST NOT be returned from the API as it is used for API key encryption in app proxying code.
|
||||
|
||||
Reference in New Issue
Block a user