mirror of
https://github.com/coder/coder.git
synced 2026-06-03 21:18:24 +00:00
cabb611fd9
Creates a new table `ai_seat_state` to keep track of when users consume an ai_seat. Once a user consumes an AI seat, they will forever in this table (as it stands today).
33 lines
610 B
SQL
33 lines
610 B
SQL
-- name: UpsertAISeatState :exec
|
|
INSERT INTO ai_seat_state (
|
|
user_id,
|
|
first_used_at,
|
|
last_used_at,
|
|
last_event_type,
|
|
last_event_description,
|
|
updated_at
|
|
)
|
|
VALUES
|
|
($1, $2, $2, $3, $4, $2)
|
|
ON CONFLICT (user_id) DO UPDATE
|
|
SET
|
|
last_used_at = EXCLUDED.last_used_at,
|
|
last_event_type = EXCLUDED.last_event_type,
|
|
last_event_description = EXCLUDED.last_event_description,
|
|
updated_at = EXCLUDED.updated_at
|
|
;
|
|
|
|
-- name: GetActiveAISeatCount :one
|
|
SELECT
|
|
COUNT(*)
|
|
FROM
|
|
ai_seat_state ais
|
|
JOIN
|
|
users u
|
|
ON
|
|
ais.user_id = u.id
|
|
WHERE
|
|
u.status = 'active'::user_status
|
|
AND u.deleted = false
|
|
AND u.is_system = false;
|