2022-01-05 09:20:56 -06:00
// Code generated by sqlc. DO NOT EDIT.
2022-05-02 14:30:46 -05:00
// versions:
2026-05-13 18:55:24 +10:00
// sqlc v1.31.1
2022-01-05 09:20:56 -06:00
package database
import (
"context"
2026-09-10 13:54:11 +02:00
"encoding/json"
2022-06-17 00:26:40 -05:00
"time"
2022-01-24 11:07:42 -06:00
"github.com/google/uuid"
2022-01-05 09:20:56 -06:00
)
2022-10-10 15:37:06 -05:00
type sqlcQuerier interface {
2026-08-19 14:00:31 -07:00
// Set the lease to expire according to the provided timeout. If there is
// already a lease, an exception is raised.
AcquireExternalAuthLinkRefreshLease ( ctx context . Context , arg AcquireExternalAuthLinkRefreshLeaseParams ) ( ExternalAuthLink , error )
2023-03-08 06:38:11 +11:00
// Blocks until the lock is acquired.
//
// This must be called from within a transaction. The lock will be automatically
// released when the transaction ends.
AcquireLock ( ctx context . Context , pgAdvisoryXactLock int64 ) error
2024-06-28 11:21:25 +02:00
// Acquires the lease for a given count of notification messages, to enable concurrent dequeuing and subsequent sending.
// Only rows that aren't already leased (or ones which are leased but have exceeded their lease period) are returned.
//
// A "lease" here refers to a notifier taking ownership of a notification_messages row. A lease survives for the duration
// of CODER_NOTIFICATIONS_LEASE_PERIOD. Once a message is delivered, its status is updated and the lease expires (set to NULL).
// If a message exceeds its lease, that implies the notifier did not shutdown cleanly, or the table update failed somehow,
// and the row will then be eligible to be dequeued by another notifier.
//
// SKIP LOCKED is used to jump over locked rows. This prevents multiple notifiers from acquiring the same messages.
// See: https://www.postgresql.org/docs/9.5/sql-select.html#SQL-FOR-UPDATE-SHARE
//
AcquireNotificationMessages ( ctx context . Context , arg AcquireNotificationMessagesParams ) ([] AcquireNotificationMessagesRow , error )
2022-05-02 14:30:46 -05:00
// Acquires the lock for a single job that isn't started, completed,
// canceled, and that matches an array of provisioner types.
//
// SKIP LOCKED is used to jump over locked rows. This prevents
// multiple provisioners from acquiring the same jobs. See:
// https://www.postgresql.org/docs/9.5/sql-select.html#SQL-FOR-UPDATE-SHARE
2022-01-29 17:38:32 -06:00
AcquireProvisionerJob ( ctx context . Context , arg AcquireProvisionerJobParams ) ( ProvisionerJob , error )
2026-03-10 18:46:01 +00:00
AcquireStaleChatDiffStatuses ( ctx context . Context , limitVal int32 ) ([] AcquireStaleChatDiffStatusesRow , error )
2024-02-12 23:00:35 -08:00
// Bumps the workspace deadline by the template's configured "activity_bump"
// duration (default 1h). If the workspace bump will cross an autostart
// threshold, then the bump is autostart + TTL. This is the deadline behavior if
// the workspace was to autostart from a stopped state.
//
// Max deadline is respected, and the deadline will never be bumped past it.
2023-11-15 09:42:27 -06:00
// The deadline will never decrease.
2024-02-12 23:00:35 -08:00
// We only bump if the template has an activity bump duration set.
2023-10-13 13:53:02 +01:00
// We only bump if the raw interval is positive and non-zero.
2023-09-14 09:09:51 +01:00
// We only bump if workspace shutdown is manual.
// We only bump when 5% of the deadline has elapsed.
2023-11-15 09:42:27 -06:00
ActivityBumpWorkspace ( ctx context . Context , arg ActivityBumpWorkspaceParams ) error
2023-09-15 15:09:40 +01:00
// AllUserIDs returns all UserIDs regardless of user status or deletion.
2025-03-25 14:18:06 +02:00
AllUserIDs ( ctx context . Context , includeSystem bool ) ([] uuid . UUID , error )
2026-04-01 15:30:25 +11:00
ArchiveChatByID ( ctx context . Context , id uuid . UUID ) ([] Chat , error )
2023-10-10 10:52:42 -05:00
// Archiving templates is a soft delete action, so is reversible.
// Archiving prevents the version from being used and discovered
// by listing.
// Only unused template versions will be archived, which are any versions not
// referenced by the latest build of a workspace.
ArchiveUnusedTemplateVersions ( ctx context . Context , arg ArchiveUnusedTemplateVersionsParams ) ([] uuid . UUID , error )
2026-04-24 14:18:28 +01:00
// Archives inactive root chats (pinned and already-archived chats skipped),
// cascading to children via root_chat_id. Limits apply to roots, not total
2026-05-22 11:39:44 +01:00
// rows. The Go caller passes @archive_cutoff as UTC midnight so that all
// chats sharing the same last-activity date are archived together.
// Used by dbpurge.
2026-04-28 08:56:36 +01:00
// created_at ASC flows through to dbpurge's digest truncation; see
// buildDigestData in dbpurge.go for the tradeoff rationale.
2026-04-24 14:18:28 +01:00
AutoArchiveInactiveChats ( ctx context . Context , arg AutoArchiveInactiveChatsParams ) ([] AutoArchiveInactiveChatsRow , error )
2026-07-16 15:21:57 +01:00
// Backfills chat_messages.search_tsv for pending rows, newest first.
// The WHERE clause must match the predicate of
// idx_chat_messages_search_tsv_pending exactly so the partial index
// serves this query.
// NULL means "pending", empty tsvector means "backfilled, no text".
BackfillChatMessagesSearchTsv ( ctx context . Context , batchSize int32 ) ( int64 , error )
2026-03-10 18:46:01 +00:00
BackoffChatDiffStatus ( ctx context . Context , arg BackoffChatDiffStatusParams ) error
2026-06-12 13:33:12 +02:00
// Deletes heartbeat rows for the supplied (chat_id, runner_id) pairs.
BatchDeleteChatHeartbeats ( ctx context . Context , arg BatchDeleteChatHeartbeatsParams ) ( int64 , error )
2026-01-22 22:47:49 -08:00
BatchUpdateWorkspaceAgentMetadata ( ctx context . Context , arg BatchUpdateWorkspaceAgentMetadataParams ) error
2024-01-16 14:06:39 +00:00
BatchUpdateWorkspaceLastUsedAt ( ctx context . Context , arg BatchUpdateWorkspaceLastUsedAtParams ) error
2024-12-02 21:02:36 +00:00
BatchUpdateWorkspaceNextStartAt ( ctx context . Context , arg BatchUpdateWorkspaceNextStartAtParams ) error
2026-06-12 13:33:12 +02:00
BatchUpsertChatHeartbeats ( ctx context . Context , arg BatchUpsertChatHeartbeatsParams ) error
2026-04-03 15:47:26 -05:00
BatchUpsertConnectionLogs ( ctx context . Context , arg BatchUpsertConnectionLogsParams ) error
2024-06-28 11:21:25 +02:00
BulkMarkNotificationMessagesFailed ( ctx context . Context , arg BulkMarkNotificationMessagesFailedParams ) ( int64 , error )
BulkMarkNotificationMessagesSent ( ctx context . Context , arg BulkMarkNotificationMessagesSentParams ) ( int64 , error )
2025-10-28 03:16:41 +11:00
// Calculates the telemetry summary for a given provider, model, and client
// combination for telemetry reporting.
CalculateAIBridgeInterceptionsTelemetrySummary ( ctx context . Context , arg CalculateAIBridgeInterceptionsTelemetrySummaryParams ) ( CalculateAIBridgeInterceptionsTelemetrySummaryRow , error )
2025-04-03 10:58:30 +02:00
ClaimPrebuiltWorkspace ( ctx context . Context , arg ClaimPrebuiltWorkspaceParams ) ( ClaimPrebuiltWorkspaceRow , error )
2023-06-23 13:23:28 +04:00
CleanTailnetCoordinators ( ctx context . Context ) error
2023-12-01 10:02:30 +04:00
CleanTailnetLostPeers ( ctx context . Context ) error
CleanTailnetTunnels ( ctx context . Context ) error
2026-03-19 10:07:36 -04:00
CleanupDeletedMCPServerIDsFromChats ( ctx context . Context ) error
2026-09-04 17:04:13 +01:00
ClearChatDiffStatusPR ( ctx context . Context , arg ClearChatDiffStatusPRParams ) error
2026-03-24 08:58:47 +02:00
CountAIBridgeSessions ( ctx context . Context , arg CountAIBridgeSessionsParams ) ( int64 , error )
2025-07-01 07:31:14 +02:00
CountAuditLogs ( ctx context . Context , arg CountAuditLogsParams ) ( int64 , error )
2026-08-18 16:55:43 +02:00
// Excluding the candidate keeps ownership takeover capacity-neutral.
CountChatCapacityActiveByPool ( ctx context . Context , arg CountChatCapacityActiveByPoolParams ) ( CountChatCapacityActiveByPoolRow , error )
CountChatCapacityQueuedByPool ( ctx context . Context , staleSeconds int32 ) ( CountChatCapacityQueuedByPoolRow , error )
2026-06-12 13:33:12 +02:00
// Cheap queue-length check used by ChatMachine.Update when deciding
// whether the chat is in a "1" sub-state.
CountChatQueuedMessages ( ctx context . Context , chatID uuid . UUID ) ( int64 , error )
2025-07-15 15:03:30 +10:00
CountConnectionLogs ( ctx context . Context , arg CountConnectionLogsParams ) ( int64 , error )
2025-04-17 09:29:29 -04:00
// CountInProgressPrebuilds returns the number of in-progress prebuilds, grouped by preset ID and transition.
2025-10-24 15:27:49 +01:00
// Prebuild considered in-progress if it's in the "pending", "starting", "stopping", or "deleting" state.
2025-04-03 10:58:30 +02:00
CountInProgressPrebuilds ( ctx context . Context ) ([] CountInProgressPrebuildsRow , error )
2026-06-16 12:46:10 -07:00
// Groups OIDC user links by their issuer prefix (the part before "||" in
// linked_id) and returns a count for each. Empty linked_ids are reported
// with an empty issuer_prefix. Used for analysis before resetting
// mismatched links.
CountOIDCLinkedIDsByIssuer ( ctx context . Context ) ([] CountOIDCLinkedIDsByIssuerRow , error )
2025-10-24 15:27:49 +01:00
// CountPendingNonActivePrebuilds returns the number of pending prebuilds for non-active template versions
CountPendingNonActivePrebuilds ( ctx context . Context ) ([] CountPendingNonActivePrebuildsRow , error )
2025-03-03 10:12:48 +01:00
CountUnreadInboxNotificationsByUserID ( ctx context . Context , userID uuid . UUID ) ( int64 , error )
2025-08-07 15:58:59 -04:00
CreateUserSecret ( ctx context . Context , arg CreateUserSecretParams ) ( UserSecret , error )
2024-05-21 13:14:00 -05:00
CustomRoles ( ctx context . Context , arg CustomRolesParams ) ([] CustomRole , error )
2026-06-02 13:25:44 +02:00
DeleteAIGatewayKey ( ctx context . Context , id uuid . UUID ) ( DeleteAIGatewayKeyRow , error )
2026-05-14 16:10:46 +02:00
DeleteAIProviderByID ( ctx context . Context , id uuid . UUID ) error
DeleteAIProviderKey ( ctx context . Context , id uuid . UUID ) error
2022-05-27 16:47:03 -04:00
DeleteAPIKeyByID ( ctx context . Context , id string ) error
2022-10-19 21:12:03 -05:00
DeleteAPIKeysByUserID ( ctx context . Context , userID uuid . UUID ) error
2026-06-12 13:33:12 +02:00
// Deletes all heartbeat rows for the chat. Used during ownership
// transitions that abandon a lease.
DeleteAllChatHeartbeats ( ctx context . Context , chatID uuid . UUID ) error
2026-02-27 11:50:56 -05:00
DeleteAllChatQueuedMessages ( ctx context . Context , chatID uuid . UUID ) error
2026-06-12 13:33:12 +02:00
DeleteAllChatQueuedMessagesReturningCount ( ctx context . Context , chatID uuid . UUID ) ( int64 , error )
2026-05-01 15:00:08 -05:00
DeleteAllTailnetTunnels ( ctx context . Context , arg DeleteAllTailnetTunnelsParams ) ([] DeleteAllTailnetTunnelsRow , error )
2025-03-27 10:03:53 +00:00
// Deletes all existing webpush subscriptions.
// This should be called when the VAPID keypair is regenerated, as the old
// keypair will no longer be valid and all existing subscriptions will need to
// be recreated.
DeleteAllWebpushSubscriptions ( ctx context . Context ) error
2023-04-06 04:41:55 +10:00
DeleteApplicationConnectAPIKeysByUserID ( ctx context . Context , userID uuid . UUID ) error
2026-08-31 19:24:27 -05:00
// Deletes cached Terraform module archives ingested in the given time range and
// clears the template version references to them. created_by and mimetype
// identify a provisionerd-written module archive, matching the checks in
// provisionerdserver, so user-uploaded template tarballs are never removed.
// Only archives referenced by a template version are considered.
DeleteCachedModuleFilesCreatedBetween ( ctx context . Context , arg DeleteCachedModuleFilesCreatedBetweenParams ) ( int64 , error )
2026-06-17 00:10:07 -07:00
// Clears a chat's pinned context resources. Used as the first half of a
// clear-then-copy re-pin, and on its own when the chat's current agent
// has no snapshot.
DeleteChatContextResourcesByChatID ( ctx context . Context , chatID uuid . UUID ) error
2026-04-20 12:27:16 +02:00
// Deletes debug runs (and their cascaded steps) whose message IDs
// exceed the cutoff. The started_before bound prevents retried
// cleanup from deleting runs created by a replacement turn that
// raced ahead of the retry window.
2026-04-13 15:06:06 +02:00
DeleteChatDebugDataAfterMessageID ( ctx context . Context , arg DeleteChatDebugDataAfterMessageIDParams ) ( int64 , error )
2026-04-20 12:27:16 +02:00
// The started_before bound prevents retried cleanup from deleting
// runs created by a replacement turn that races ahead of the retry
// window (for example, after an unarchive races with a pending
// archive-cleanup retry).
DeleteChatDebugDataByChatID ( ctx context . Context , arg DeleteChatDebugDataByChatIDParams ) ( int64 , error )
2026-08-24 10:30:00 +01:00
DeleteChatModelConfigByID ( ctx context . Context , id uuid . UUID ) ( uuid . UUID , error )
2026-08-24 12:20:26 +02:00
DeleteChatOrganizationModelOverride ( ctx context . Context , arg DeleteChatOrganizationModelOverrideParams ) error
2026-02-27 11:50:56 -05:00
DeleteChatQueuedMessage ( ctx context . Context , arg DeleteChatQueuedMessageParams ) error
2026-06-12 13:33:12 +02:00
// Deletes a queued message, scoped to the parent chat. Returns the
// number of affected rows so callers can detect missing rows without
// a follow-up read.
DeleteChatQueuedMessageReturningCount ( ctx context . Context , arg DeleteChatQueuedMessageReturningCountParams ) ( int64 , error )
2024-09-17 18:08:18 +01:00
DeleteCryptoKey ( ctx context . Context , arg DeleteCryptoKeyParams ) ( CryptoKey , error )
2024-08-07 12:37:55 -05:00
DeleteCustomRole ( ctx context . Context , arg DeleteCustomRoleParams ) error
2025-11-24 10:24:32 -06:00
DeleteExpiredAPIKeys ( ctx context . Context , arg DeleteExpiredAPIKeysParams ) ( int64 , error )
2023-12-05 14:03:44 -06:00
DeleteExternalAuthLink ( ctx context . Context , arg DeleteExternalAuthLinkParams ) error
2026-06-16 11:01:43 +02:00
DeleteGroupAIBudget ( ctx context . Context , groupID uuid . UUID ) ( GroupAIBudget , error )
2022-10-10 15:37:06 -05:00
DeleteGroupByID ( ctx context . Context , id uuid . UUID ) error
2023-02-02 09:46:42 -06:00
DeleteGroupMemberFromGroup ( ctx context . Context , arg DeleteGroupMemberFromGroupParams ) error
2022-08-25 14:04:31 -07:00
DeleteLicense ( ctx context . Context , id int32 ) ( int32 , error )
2026-03-19 10:07:36 -04:00
DeleteMCPServerConfigByID ( ctx context . Context , id uuid . UUID ) error
DeleteMCPServerUserToken ( ctx context . Context , arg DeleteMCPServerUserTokenParams ) error
2026-08-19 20:04:13 +02:00
DeleteMCPServerUserTokensByConfigID ( ctx context . Context , mcpServerConfigID uuid . UUID ) error
2025-07-03 18:33:47 +02:00
DeleteOAuth2ProviderAppByClientID ( ctx context . Context , id uuid . UUID ) error
2023-12-21 12:38:42 -09:00
DeleteOAuth2ProviderAppByID ( ctx context . Context , id uuid . UUID ) error
2026-09-08 16:42:34 -07:00
// Returns sql.ErrNoRows when the delete removed nothing, so a caller can make
// this the arbiter of single use. A prior read cannot arbitrate: its result is
// stale the moment it returns.
//
// Concurrent deletes are arbitrated at READ COMMITTED, the default isolation
// level: the second transaction waits for the first, then removes nothing.
// SERIALIZABLE would abort and retry it instead.
DeleteOAuth2ProviderAppCodeByID ( ctx context . Context , id uuid . UUID ) ( OAuth2ProviderAppCode , error )
2024-02-20 15:58:43 -08:00
DeleteOAuth2ProviderAppCodesByAppAndUserID ( ctx context . Context , arg DeleteOAuth2ProviderAppCodesByAppAndUserIDParams ) error
2023-12-21 12:38:42 -09:00
DeleteOAuth2ProviderAppSecretByID ( ctx context . Context , id uuid . UUID ) error
2026-08-05 10:41:06 -07:00
// Filters directly on app_id rather than joining through app_secret_id,
// since app_secret_id is NULL for public (secretless) clients and would
// silently exclude their tokens from this delete.
2024-02-20 15:58:43 -08:00
DeleteOAuth2ProviderAppTokensByAppAndUserID ( ctx context . Context , arg DeleteOAuth2ProviderAppTokensByAppAndUserIDParams ) error
2025-11-21 11:35:36 +02:00
// Cumulative count.
2025-12-03 11:37:18 +02:00
DeleteOldAIBridgeRecords ( ctx context . Context , beforeTime time . Time ) ( int64 , error )
2025-07-15 15:45:36 +10:00
DeleteOldAuditLogConnectionEvents ( ctx context . Context , arg DeleteOldAuditLogConnectionEventsParams ) error
2025-12-02 16:50:09 +02:00
// Deletes old audit logs based on retention policy, excluding deprecated
// connection events (connect, disconnect, open, close) which are handled
// separately by DeleteOldAuditLogConnectionEvents.
DeleteOldAuditLogs ( ctx context . Context , arg DeleteOldAuditLogsParams ) ( int64 , error )
2026-05-25 11:14:36 +02:00
// Deletes boundary logs older than the given time, bounded by a row limit
// to avoid long-running transactions.
DeleteOldBoundaryLogs ( ctx context . Context , arg DeleteOldBoundaryLogsParams ) ( int64 , error )
2026-06-16 14:32:54 +02:00
// Deletes boundary sessions that have aged past retention and no longer
// have any associated logs.
DeleteOldBoundarySessions ( ctx context . Context , arg DeleteOldBoundarySessionsParams ) ( int64 , error )
2026-05-05 22:37:13 +02:00
// updated_at is the retention clock, so the window starts after the run
// stops being written to.
// Intentionally no finished_at IS NOT NULL guard: abandoned in-flight rows
// older than the cutoff are also purged.
DeleteOldChatDebugRuns ( ctx context . Context , arg DeleteOldChatDebugRunsParams ) ( int64 , error )
2026-04-08 11:08:09 +01:00
// Deletes chats that have been archived for longer than the given
// threshold. Active (non-archived) chats are never deleted.
2026-06-16 14:28:57 -07:00
// All chat-scoped child tables are removed via ON DELETE CASCADE.
2026-04-08 11:08:09 +01:00
// Parent/root references on child chats are SET NULL.
DeleteOldChats ( ctx context . Context , arg DeleteOldChatsParams ) ( int64 , error )
2025-12-02 16:17:52 +02:00
DeleteOldConnectionLogs ( ctx context . Context , arg DeleteOldConnectionLogsParams ) ( int64 , error )
2024-06-28 11:21:25 +02:00
// Delete all notification messages which have not been updated for over a week.
DeleteOldNotificationMessages ( ctx context . Context ) error
2023-12-01 13:43:05 +01:00
// Delete provisioner daemons that have been created at least a week ago
// and have not connected to coderd since a week.
2023-12-12 11:19:28 +00:00
// A provisioner daemon with "zeroed" last_seen_at column indicates possible
2023-12-01 13:43:05 +01:00
// connectivity issues (no provisioner daemon activity since registration).
DeleteOldProvisionerDaemons ( ctx context . Context ) error
2025-10-28 03:16:41 +11:00
// Deletes old telemetry locks from the telemetry_locks table.
DeleteOldTelemetryLocks ( ctx context . Context , periodEndingAtBefore time . Time ) error
2025-12-02 18:01:33 +02:00
// If an agent hasn't connected within the retention period, we purge its logs.
2024-08-30 17:39:09 +01:00
// Exception: if the logs are related to the latest build, we keep those around.
2023-03-23 14:09:13 -05:00
// Logs can take up a lot of space, so it's important we clean up frequently.
2025-12-02 18:01:33 +02:00
DeleteOldWorkspaceAgentLogs ( ctx context . Context , threshold time . Time ) ( int64 , error )
2023-02-28 13:33:33 -06:00
DeleteOldWorkspaceAgentStats ( ctx context . Context ) error
2026-07-07 09:18:30 -07:00
DeleteOldWorkspaceBuildOrchestrations ( ctx context . Context , arg DeleteOldWorkspaceBuildOrchestrationsParams ) ( int64 , error )
2024-06-20 05:06:37 -10:00
DeleteOrganizationMember ( ctx context . Context , arg DeleteOrganizationMemberParams ) error
2024-07-16 13:27:12 -04:00
DeleteProvisionerKey ( ctx context . Context , id uuid . UUID ) error
2022-10-17 08:43:30 -05:00
DeleteReplicasUpdatedBefore ( ctx context . Context , updatedAt time . Time ) error
2024-09-09 14:14:52 -05:00
DeleteRuntimeConfig ( ctx context . Context , key string ) error
2026-06-12 13:33:12 +02:00
DeleteStaleChatHeartbeats ( ctx context . Context , staleSeconds int32 ) ( int64 , error )
2026-06-15 09:38:52 -07:00
// Deletes any resources for the agent whose source is not in the
// supplied active set. Atomic alongside the snapshot upsert so the
// stored snapshot and resource rows always agree.
DeleteStaleWorkspaceAgentContextResources ( ctx context . Context , arg DeleteStaleWorkspaceAgentContextResourcesParams ) error
2023-11-15 10:13:27 +04:00
DeleteTailnetPeer ( ctx context . Context , arg DeleteTailnetPeerParams ) ( DeleteTailnetPeerRow , error )
DeleteTailnetTunnel ( ctx context . Context , arg DeleteTailnetTunnelParams ) ( DeleteTailnetTunnelRow , error )
2026-02-06 11:55:33 +02:00
DeleteTask ( ctx context . Context , arg DeleteTaskParams ) ( uuid . UUID , error )
2026-08-11 13:53:15 +02:00
DeleteUnlinkedChatFilesByIDs ( ctx context . Context , arg DeleteUnlinkedChatFilesByIDsParams ) ( int64 , error )
2026-06-16 11:01:43 +02:00
DeleteUserAIBudgetOverride ( ctx context . Context , userID uuid . UUID ) ( UserAIBudgetOverride , error )
2026-05-22 02:16:01 +02:00
DeleteUserAIProviderKey ( ctx context . Context , arg DeleteUserAIProviderKeyParams ) error
DeleteUserAIProviderKeysByProviderID ( ctx context . Context , aiProviderID uuid . UUID ) error
2026-03-24 00:48:18 +01:00
DeleteUserChatCompactionThreshold ( ctx context . Context , arg DeleteUserChatCompactionThresholdParams ) error
2026-04-29 12:57:47 -06:00
DeleteUserSecretByUserIDAndName ( ctx context . Context , arg DeleteUserSecretByUserIDAndNameParams ) ( UserSecret , error )
2026-05-20 00:09:09 +02:00
DeleteUserSkillByUserIDAndName ( ctx context . Context , arg DeleteUserSkillByUserIDAndNameParams ) ( UserSkill , error )
2025-03-27 10:03:53 +00:00
DeleteWebpushSubscriptionByUserIDAndEndpoint ( ctx context . Context , arg DeleteWebpushSubscriptionByUserIDAndEndpointParams ) error
DeleteWebpushSubscriptions ( ctx context . Context , ids [] uuid . UUID ) error
2025-09-12 12:21:01 -04:00
DeleteWorkspaceACLByID ( ctx context . Context , id uuid . UUID ) error
2026-03-17 12:16:43 -07:00
DeleteWorkspaceACLsByOrganization ( ctx context . Context , arg DeleteWorkspaceACLsByOrganizationParams ) error
2024-02-13 09:31:20 -05:00
DeleteWorkspaceAgentPortShare ( ctx context . Context , arg DeleteWorkspaceAgentPortShareParams ) error
2024-03-05 13:47:01 -05:00
DeleteWorkspaceAgentPortSharesByTemplate ( ctx context . Context , templateID uuid . UUID ) error
2026-06-15 09:38:52 -07:00
// Soft-deletes a single sub-agent (a child agent such as a devcontainer
// agent). Called from the DeleteSubAgent RPC when a sub-agent is torn
// down, which can happen mid-build without a full workspace rebuild.
//
// Agent context rows are hard-deleted for the same reason as in
// SoftDeletePriorWorkspaceAgents: they only describe live agents, the
// rebuild-time soft-delete queries skip already-deleted agents, and
// agents are never hard-deleted, so the rows would otherwise orphan
// forever.
2025-05-29 12:15:47 +01:00
DeleteWorkspaceSubAgentByID ( ctx context . Context , id uuid . UUID ) error
2025-01-08 16:22:51 +01:00
// Disable foreign keys and triggers for all tables.
// Deprecated: disable foreign keys was created to aid in migrating off
// of the test-only in-memory database. Do not use this in new code.
DisableForeignKeysAndTriggers ( ctx context . Context ) error
2024-07-11 10:57:49 +02:00
EnqueueNotificationMessage ( ctx context . Context , arg EnqueueNotificationMessageParams ) error
2025-09-02 09:38:43 +01:00
// Firstly, collect api_keys owned by the prebuilds user that correlate
// to workspaces no longer owned by the prebuilds user.
// Next, collect api_keys that belong to the prebuilds user but have no token name.
// These were most likely created via 'coder login' as the prebuilds user.
ExpirePrebuildsAPIKeys ( ctx context . Context , now time . Time ) error
2026-07-28 10:58:38 +01:00
// Returns per-user, per-group, per-model, per-provider aggregated AI spend for
// @organization_id over the [period_start, period_end) window. Spend is
// attributed through the token usage's effective group, and rows are bucketed
// by the token usage created_at, matching how ai_user_daily_spend is derived.
ExportOrganizationAISpend ( ctx context . Context , arg ExportOrganizationAISpendParams ) ([] ExportOrganizationAISpendRow , error )
2024-01-24 13:39:19 +00:00
FavoriteWorkspace ( ctx context . Context , id uuid . UUID ) error
2025-02-04 18:45:33 +01:00
FetchMemoryResourceMonitorsByAgentID ( ctx context . Context , agentID uuid . UUID ) ( WorkspaceAgentMemoryResourceMonitor , error )
2025-03-03 18:41:01 +01:00
FetchMemoryResourceMonitorsUpdatedAfter ( ctx context . Context , updatedAt time . Time ) ([] WorkspaceAgentMemoryResourceMonitor , error )
2024-06-28 11:21:25 +02:00
// This is used to build up the notification_message's JSON payload.
FetchNewMessageMetadata ( ctx context . Context , arg FetchNewMessageMetadataParams ) ( FetchNewMessageMetadataRow , error )
2025-02-04 18:45:33 +01:00
FetchVolumesResourceMonitorsByAgentID ( ctx context . Context , agentID uuid . UUID ) ([] WorkspaceAgentVolumeResourceMonitor , error )
2025-03-03 18:41:01 +01:00
FetchVolumesResourceMonitorsUpdatedAfter ( ctx context . Context , updatedAt time . Time ) ([] WorkspaceAgentVolumeResourceMonitor , error )
2026-04-13 15:06:06 +02:00
// Marks orphaned in-progress rows as interrupted so they do not stay
2026-04-17 16:27:53 +02:00
// in a non-terminal state forever. The NOT IN list must match the
2026-04-13 15:06:06 +02:00
// terminal statuses defined by ChatDebugStatus in codersdk/chats.go.
//
// The steps CTE also catches steps whose parent run was just finalized
// (via run_id IN), because PostgreSQL data-modifying CTEs share the
2026-04-17 16:27:53 +02:00
// same snapshot and cannot see each other's row updates. Without this,
2026-04-13 15:06:06 +02:00
// a step with a recent updated_at would survive its run's finalization
// and remain in 'in_progress' state permanently.
2026-04-17 16:27:53 +02:00
//
// @now is the caller's clock timestamp so that mock-clock tests stay
// consistent with the @updated_before cutoff.
FinalizeStaleChatDebugRows ( ctx context . Context , arg FinalizeStaleChatDebugRowsParams ) ( FinalizeStaleChatDebugRowsRow , error )
2025-08-20 11:02:53 +02:00
// FindMatchingPresetID finds a preset ID that is the largest exact subset of the provided parameters.
// It returns the preset ID if a match is found, or NULL if no match is found.
// The query finds presets where all preset parameters are present in the provided parameters,
// and returns the preset with the most parameters (largest subset).
FindMatchingPresetID ( ctx context . Context , arg FindMatchingPresetIDParams ) ( uuid . UUID , error )
2026-07-30 13:01:48 +02:00
// AI Gateway cost for one chat tree: the root chat plus every subagent
// beneath it. The spawning chat's ID is recorded as the interception session
// ID (see chatprovider.CoderHeaders), so a subagent's requests are attributed
// to its parent rather than the root, and only whole trees can be summed. The
// owner check guards against session-id collisions. Usage without an
// effective group never reaches ai_user_daily_spend.
GetAIBridgeChatCost ( ctx context . Context , rootChatID uuid . UUID ) ( GetAIBridgeChatCostRow , error )
2025-09-16 21:31:17 +02:00
GetAIBridgeInterceptionByID ( ctx context . Context , id uuid . UUID ) ( AIBridgeInterception , error )
2026-03-03 21:04:41 +02:00
// Look up the parent interception and the root of the thread by finding
// which interception recorded a tool usage with the given tool call ID.
// COALESCE ensures that if the parent has no thread_root_id (i.e. it IS
// the root), we return its own ID as the root.
GetAIBridgeInterceptionLineageByToolCallID ( ctx context . Context , toolCallID string ) ( GetAIBridgeInterceptionLineageByToolCallIDRow , error )
2025-09-25 16:37:28 +02:00
GetAIBridgeInterceptions ( ctx context . Context ) ([] AIBridgeInterception , error )
2026-07-30 13:09:46 +02:00
// Returns the most contacted destination hosts for an AI session, ordered by
// call count descending and limited to the top @limit_ rows. total_domains is
// the number of distinct domains across the whole session, used to render a
// "+N more" overflow beyond the returned rows. Only HTTP egress is considered;
// dns/git/fs boundary logs do not carry a domain in the same shape.
//
// Windowing mirrors the network_calls aggregation in ListAIBridgeSessions:
// each interception's boundary logs fall in the open interval (this seq, next
// interception's seq) within the same firewall session. The exclusive lower
// bound drops the interception's own LLM-provider call. next_seq considers all
// interceptions in the firewall session so windows never bleed across AI
// sessions that share one firewall session, and falls back to the maximum
// sequence_number for the last interception so the window stays an
// index-satisfiable range.
GetAIBridgeSessionTopDomains ( ctx context . Context , arg GetAIBridgeSessionTopDomainsParams ) ([] GetAIBridgeSessionTopDomainsRow , error )
2025-09-25 16:37:28 +02:00
GetAIBridgeTokenUsagesByInterceptionID ( ctx context . Context , interceptionID uuid . UUID ) ([] AIBridgeTokenUsage , error )
GetAIBridgeToolUsagesByInterceptionID ( ctx context . Context , interceptionID uuid . UUID ) ([] AIBridgeToolUsage , error )
GetAIBridgeUserPromptsByInterceptionID ( ctx context . Context , interceptionID uuid . UUID ) ([] AIBridgeUserPrompt , error )
2026-06-26 18:16:01 +02:00
// Authenticates a standalone AI Gateway replica by its hashed key secret,
// returning the matched key. The lookup is an exact match on a unique index,
// so a returned row is itself proof the secret is valid.
GetAIGatewayKeyByHashedSecret ( ctx context . Context , hashedSecret [] byte ) ( AIGatewayKey , error )
2026-08-20 11:36:58 +01:00
// Returns the price in effect for the model, preferring a custom price over
// the price book.
2026-06-16 11:01:43 +02:00
GetAIModelPriceByProviderModel ( ctx context . Context , arg GetAIModelPriceByProviderModelParams ) ( AIModelPrice , error )
2026-08-20 11:36:58 +01:00
// Returns the price in effect for each model, preferring a custom price over
2026-08-20 11:56:58 +01:00
// the price book. Filtering by source narrows the rows considered first, so a
// model carrying both prices reports the one from the named source.
// The source 'all' reports every row instead. It joins the DISTINCT ON key, so
// each source forms its own group and nothing collapses. Every other source
// contributes the same constant, leaving the key as (provider, model).
2026-08-13 15:00:36 +01:00
GetAIModelPrices ( ctx context . Context , arg GetAIModelPricesParams ) ([] AIModelPrice , error )
2026-05-14 16:10:46 +02:00
GetAIProviderByID ( ctx context . Context , id uuid . UUID ) ( AIProvider , error )
2026-05-22 07:53:23 +02:00
// Lock the provider row until the model-config write completes. The
// transaction alone does not stop a concurrent soft-delete or disable
// between validation and writing the model config reference.
GetAIProviderByIDForReferenceLock ( ctx context . Context , id uuid . UUID ) ( AIProvider , error )
2026-05-14 16:10:46 +02:00
GetAIProviderByName ( ctx context . Context , name string ) ( AIProvider , error )
GetAIProviderKeyByID ( ctx context . Context , id uuid . UUID ) ( AIProviderKey , error )
2026-05-22 07:53:23 +02:00
// Returns the provider IDs that have at least one provider-scoped key.
GetAIProviderKeyPresence ( ctx context . Context , providerIds [] uuid . UUID ) ([] uuid . UUID , error )
2026-05-20 10:21:36 +02:00
// Returns AI provider key rows. By default, only rows whose parent
// provider is live (deleted = FALSE) are returned, so the API list
// handler can fetch every visible provider's keys in a single query.
// The dbcrypt key rotation utility passes include_deleted=TRUE to
// re-encrypt rows that belong to soft-deleted providers as well.
GetAIProviderKeys ( ctx context . Context , includeDeleted bool ) ([] AIProviderKey , error )
2026-05-14 16:10:46 +02:00
// Returns all keys for a provider, ordered by created_at ASC so the
// oldest key is returned first. AI Bridge currently uses the oldest
// key per provider; multiple keys are stored to support future
// failover and rotation flows.
GetAIProviderKeysByProviderID ( ctx context . Context , providerID uuid . UUID ) ([] AIProviderKey , error )
2026-05-22 09:50:01 +02:00
// Returns all keys for the requested providers, ordered by provider then created_at ASC
// so callers can select the oldest non-empty key per provider without issuing N queries.
GetAIProviderKeysByProviderIDs ( ctx context . Context , providerIds [] uuid . UUID ) ([] AIProviderKey , error )
2026-05-14 16:10:46 +02:00
// Returns AI provider rows. Soft-deleted and disabled rows are excluded
// unless include_deleted or include_disabled is set.
GetAIProviders ( ctx context . Context , arg GetAIProvidersParams ) ([] AIProvider , error )
2022-01-20 07:46:51 -06:00
GetAPIKeyByID ( ctx context . Context , id string ) ( APIKey , error )
2023-03-02 09:39:38 -08:00
// there is no unique constraint on empty token names
GetAPIKeyByName ( ctx context . Context , arg GetAPIKeyByNameParams ) ( APIKey , error )
2026-02-24 16:27:03 +01:00
GetAPIKeysByLoginType ( ctx context . Context , arg GetAPIKeysByLoginTypeParams ) ([] APIKey , error )
2023-02-23 07:00:27 -08:00
GetAPIKeysByUserID ( ctx context . Context , arg GetAPIKeysByUserIDParams ) ([] APIKey , error )
2022-06-17 00:26:40 -05:00
GetAPIKeysLastUsedAfter ( ctx context . Context , lastUsed time . Time ) ([] APIKey , error )
2026-03-16 11:53:20 -05:00
GetActiveAISeatCount ( ctx context . Context ) ( int64 , error )
2026-04-09 10:33:00 -04:00
GetActiveChatsByAgentID ( ctx context . Context , agentID uuid . UUID ) ([] Chat , error )
2025-06-19 11:08:48 -04:00
GetActivePresetPrebuildSchedules ( ctx context . Context ) ([] TemplateVersionPresetPrebuildSchedule , error )
2025-03-25 14:18:06 +02:00
GetActiveUserCount ( ctx context . Context , includeSystem bool ) ( int64 , error )
2026-07-27 20:43:57 -05:00
// Returns the authorization roles (site and org-scoped, including implied
// member roles and organization default roles) and the group memberships
// for every active, non-deleted user who is neither a system user nor a
// service account, matching the GetActiveUserCount population.
// Must stay semantically in sync with GetAuthorizationUserRoles;
// TestGetActiveUsersAuthorizationRolesParity enforces this.
GetActiveUsersAuthorizationRoles ( ctx context . Context ) ([] GetActiveUsersAuthorizationRolesRow , error )
2023-08-14 14:16:47 -07:00
GetActiveWorkspaceBuildsByTemplateID ( ctx context . Context , templateID uuid . UUID ) ([] WorkspaceBuild , error )
2023-11-28 20:19:32 +04:00
// For PG Coordinator HTMLDebug
GetAllTailnetCoordinators ( ctx context . Context ) ([] TailnetCoordinator , error )
GetAllTailnetPeers ( ctx context . Context ) ([] TailnetPeer , error )
GetAllTailnetTunnels ( ctx context . Context ) ([] TailnetTunnel , error )
2026-02-06 09:52:17 -07:00
// Atomic read+delete prevents replicas that flush between a separate read and
// reset from having their data deleted before the next snapshot. Uses a common
// table expression with DELETE...RETURNING so the rows we sum are exactly the
// rows we delete. Stale rows are excluded from the sum but still deleted.
GetAndResetBoundaryUsageSummary ( ctx context . Context , maxStalenessMs int64 ) ( GetAndResetBoundaryUsageSummaryRow , error )
2024-05-31 10:59:28 -06:00
GetAnnouncementBanners ( ctx context . Context ) ( string , error )
2023-09-27 17:02:18 +02:00
GetApplicationName ( ctx context . Context ) ( string , error )
2022-09-07 11:38:19 -05:00
// GetAuditLogsBefore retrieves `row_limit` number of audit logs before the provided
2022-05-02 14:30:46 -05:00
// ID.
2022-09-07 11:38:19 -05:00
GetAuditLogsOffset ( ctx context . Context , arg GetAuditLogsOffsetParams ) ([] GetAuditLogsOffsetRow , error )
2026-01-21 15:18:43 +02:00
// GetAuthenticatedWorkspaceAgentAndBuildByAuthToken returns an authenticated
// workspace agent and its associated build. During normal operation, this is
// the latest build. During shutdown, this may be the previous START build while
// the STOP build is executing, allowing shutdown scripts to authenticate (see
// issue #19467).
GetAuthenticatedWorkspaceAgentAndBuildByAuthToken ( ctx context . Context , authToken uuid . UUID ) ( GetAuthenticatedWorkspaceAgentAndBuildByAuthTokenRow , error )
2022-06-01 09:07:50 -05:00
// This function returns roles for authorization purposes. Implied member roles
// are included.
2026-07-27 20:43:57 -05:00
// Must stay semantically in sync with GetActiveUsersAuthorizationRoles
// (implied member roles, org default roles, groups);
// TestGetActiveUsersAuthorizationRolesParity enforces this.
2022-06-01 09:07:50 -05:00
GetAuthorizationUserRoles ( ctx context . Context , userID uuid . UUID ) ( GetAuthorizationUserRolesRow , error )
2026-06-12 13:33:12 +02:00
// Returns read-only root chat candidates for state-machine-backed
// auto-archive. Activity is computed across the root family. The query
// limits roots, not total family members.
GetAutoArchiveInactiveChatCandidates ( ctx context . Context , arg GetAutoArchiveInactiveChatCandidatesParams ) ([] GetAutoArchiveInactiveChatCandidatesRow , error )
2026-05-25 11:14:36 +02:00
GetBoundaryLogByID ( ctx context . Context , id uuid . UUID ) ( BoundaryLog , error )
2026-06-18 20:50:17 +02:00
GetBoundarySessionByID ( ctx context . Context , id uuid . UUID ) ( GetBoundarySessionByIDRow , error )
2026-05-18 22:32:05 +01:00
GetChatACLByID ( ctx context . Context , id uuid . UUID ) ( GetChatACLByIDRow , error )
2026-04-30 14:53:08 +02:00
// GetChatAdvisorConfig returns the deployment-wide runtime configuration
// for the experimental chat advisor as a JSON blob. Callers unmarshal the
// result into codersdk.AdvisorConfig. Returns '{}' when unset so zero
// values apply by default.
GetChatAdvisorConfig ( ctx context . Context ) ( string , error )
2026-04-24 14:18:28 +01:00
// Auto-archive window in days. 0 disables.
GetChatAutoArchiveDays ( ctx context . Context , defaultAutoArchiveDays int32 ) ( int32 , error )
2026-02-27 11:50:56 -05:00
GetChatByID ( ctx context . Context , id uuid . UUID ) ( Chat , error )
2026-06-12 13:33:12 +02:00
GetChatByIDForShare ( ctx context . Context , id uuid . UUID ) ( Chat , error )
2026-02-27 11:50:56 -05:00
GetChatByIDForUpdate ( ctx context . Context , id uuid . UUID ) ( Chat , error )
2026-05-04 20:30:50 +02:00
GetChatComputerUseProvider ( ctx context . Context ) ( string , error )
2026-04-13 15:06:06 +02:00
// GetChatDebugLoggingAllowUsers returns the runtime admin setting that
// allows users to opt into chat debug logging when the deployment does
// not already force debug logging on globally.
GetChatDebugLoggingAllowUsers ( ctx context . Context ) ( bool , error )
2026-05-05 22:37:13 +02:00
// Chat debug run retention window in days. 0 disables.
GetChatDebugRetentionDays ( ctx context . Context , defaultDebugRetentionDays int32 ) ( int32 , error )
2026-04-13 15:06:06 +02:00
GetChatDebugRunByID ( ctx context . Context , id uuid . UUID ) ( ChatDebugRun , error )
// Returns the most recent debug runs for a chat, ordered newest-first.
// Callers must supply an explicit limit to avoid unbounded result sets.
GetChatDebugRunsByChatID ( ctx context . Context , arg GetChatDebugRunsByChatIDParams ) ([] ChatDebugRun , error )
GetChatDebugStepsByRunID ( ctx context . Context , runID uuid . UUID ) ([] ChatDebugStep , error )
2026-03-18 09:35:13 +01:00
GetChatDesktopEnabled ( ctx context . Context ) ( bool , error )
2026-02-27 11:50:56 -05:00
GetChatDiffStatusByChatID ( ctx context . Context , chatID uuid . UUID ) ( ChatDiffStatus , error )
2026-04-17 21:56:11 +10:00
// Returns aggregate PR counts across all agent chats for telemetry.
// Deduplicates by PR URL so forked chats referencing the same pull
// request are counted once (using the most recently refreshed state).
// Total is derived from the three recognized state buckets and
// always equals open + merged + closed; other non-NULL states are
// intentionally excluded from these aggregates.
GetChatDiffStatusSummary ( ctx context . Context ) ( GetChatDiffStatusSummaryRow , error )
2026-02-27 11:50:56 -05:00
GetChatDiffStatusesByChatIDs ( ctx context . Context , chatIds [] uuid . UUID ) ([] ChatDiffStatus , error )
2026-06-12 13:33:12 +02:00
// Returns the chat IDs of every chat in a family (root + all children)
// in deterministic order. The id parameter must be the root id; the
// query does not walk up from a child.
GetChatFamilyIDsByRootID ( ctx context . Context , id uuid . UUID ) ([] uuid . UUID , error )
2026-03-06 21:05:26 +02:00
GetChatFileByID ( ctx context . Context , id uuid . UUID ) ( ChatFile , error )
2026-07-08 21:37:30 +02:00
// GetChatFileDataPrefixesByIDs returns a bounded prefix of each
// file's content, keeping full blobs out of server memory. Owner and
// organization columns support row-level authorization.
GetChatFileDataPrefixesByIDs ( ctx context . Context , arg GetChatFileDataPrefixesByIDsParams ) ([] GetChatFileDataPrefixesByIDsRow , error )
2026-04-07 12:05:29 +01:00
// GetChatFileMetadataByChatID returns lightweight file metadata for
// all files linked to a chat. The data column is excluded to avoid
// loading file content.
GetChatFileMetadataByChatID ( ctx context . Context , chatID uuid . UUID ) ([] GetChatFileMetadataByChatIDRow , error )
2026-03-06 21:05:26 +02:00
GetChatFilesByIDs ( ctx context . Context , ids [] uuid . UUID ) ([] ChatFile , error )
2026-07-18 20:45:13 +02:00
GetChatGatewayAPIKey ( ctx context . Context , arg GetChatGatewayAPIKeyParams ) ( APIKey , error )
2026-06-12 13:33:12 +02:00
GetChatHeartbeat ( ctx context . Context , arg GetChatHeartbeatParams ) ( ChatHeartbeat , error )
2026-03-26 13:32:41 +01:00
// GetChatIncludeDefaultSystemPrompt preserves the legacy default
// for deployments created before the explicit include-default toggle.
// When the toggle is unset, a non-empty custom prompt implies false;
// otherwise the setting defaults to true.
GetChatIncludeDefaultSystemPrompt ( ctx context . Context ) ( bool , error )
2026-02-27 11:50:56 -05:00
GetChatMessageByID ( ctx context . Context , id int64 ) ( ChatMessage , error )
2026-04-08 09:47:44 -04:00
// Aggregates message-level metrics per chat for messages created
// after the given timestamp. Uses message created_at so that
// ongoing activity in long-running chats is captured each window.
GetChatMessageSummariesPerChat ( ctx context . Context , createdAfter time . Time ) ([] GetChatMessageSummariesPerChatRow , error )
2026-07-29 09:17:42 +02:00
// Ordered by id to match the @after_id cursor. created_at is the transaction
// start time, so it can disagree with append order when a transaction takes the
// chat row lock later than one that started after it.
2026-03-02 16:31:04 -05:00
GetChatMessagesByChatID ( ctx context . Context , arg GetChatMessagesByChatIDParams ) ([] ChatMessage , error )
2026-03-27 01:47:19 +01:00
GetChatMessagesByChatIDAscPaginated ( ctx context . Context , arg GetChatMessagesByChatIDAscPaginatedParams ) ([] ChatMessage , error )
2026-03-16 09:40:59 -07:00
GetChatMessagesByChatIDDescPaginated ( ctx context . Context , arg GetChatMessagesByChatIDDescPaginatedParams ) ([] ChatMessage , error )
2026-07-29 09:17:42 +02:00
// Stream deltas and reset snapshots must use the same message order.
2026-06-12 13:33:12 +02:00
GetChatMessagesByRevisionForStream ( ctx context . Context , arg GetChatMessagesByRevisionForStreamParams ) ([] ChatMessage , error )
2026-07-29 14:04:59 +02:00
// The compaction boundary and final ordering must use the same key so tool
// results remain after their assistant calls.
2026-02-27 11:50:56 -05:00
GetChatMessagesForPromptByChatID ( ctx context . Context , chatID uuid . UUID ) ([] ChatMessage , error )
GetChatModelConfigByID ( ctx context . Context , id uuid . UUID ) ( ChatModelConfig , error )
2026-08-24 11:20:25 +01:00
GetChatModelConfigs ( ctx context . Context , organizationID uuid . UUID ) ([] ChatModelConfig , error )
// All live configs in one organization, unfiltered. Consumed ONLY by
// ensureDefaultChatModelConfig's default-election read inside the write
// transaction; authorization is the caller's update-in-org check that every
// path reaching the election already requires. No @authorize_filter.
GetChatModelConfigsByOrganization ( ctx context . Context , organizationID uuid . UUID ) ([] ChatModelConfig , error )
2026-07-01 15:59:55 +03:00
// deleted = false guarantees ai_provider_id is non-null, so INNER JOIN is safe.
2026-04-08 09:47:44 -04:00
GetChatModelConfigsForTelemetry ( ctx context . Context ) ([] GetChatModelConfigsForTelemetryRow , error )
2026-08-24 12:20:26 +02:00
GetChatOrganizationModelOverride ( ctx context . Context , arg GetChatOrganizationModelOverrideParams ) ( ChatOrganizationModelOverride , error )
GetChatOrganizationModelOverrides ( ctx context . Context , organizationID uuid . UUID ) ([] ChatOrganizationModelOverride , error )
// Returns every non-deleted organization's override for one context together
// with the resolved model and provider, for bulk consumers such as telemetry.
// model_available mirrors GetEnabledChatModelConfigByID: it is false when the
// referenced config or its provider is disabled or deleted.
GetChatOrganizationModelOverridesByContext ( ctx context . Context , argContext string ) ([] GetChatOrganizationModelOverridesByContextRow , error )
2026-05-05 00:57:51 +02:00
// GetChatPersonalModelOverridesEnabled returns whether users may configure
// personal chat model overrides. It defaults to false when unset.
GetChatPersonalModelOverridesEnabled ( ctx context . Context ) ( bool , error )
2026-04-16 11:12:01 +02:00
GetChatPlanModeInstructions ( ctx context . Context ) ( string , error )
2026-08-18 16:55:43 +02:00
// Pool fullness distinguishes capacity waits from worker pickup delays.
GetChatQueuedForCapacity ( ctx context . Context , arg GetChatQueuedForCapacityParams ) ( bool , error )
2026-06-12 13:33:12 +02:00
GetChatQueuedMessageByID ( ctx context . Context , arg GetChatQueuedMessageByIDParams ) ( ChatQueuedMessage , error )
// Returns the queue head (lowest position, then lowest id).
GetChatQueuedMessageHead ( ctx context . Context , chatID uuid . UUID ) ( ChatQueuedMessage , error )
2026-02-27 11:50:56 -05:00
GetChatQueuedMessages ( ctx context . Context , chatID uuid . UUID ) ([] ChatQueuedMessage , error )
2026-06-12 13:33:12 +02:00
// Returns queued messages in state-machine order (position ASC, id ASC).
GetChatQueuedMessagesByPosition ( ctx context . Context , chatID uuid . UUID ) ([] ChatQueuedMessage , error )
2026-04-08 11:08:09 +01:00
// Returns the chat retention period in days. Chats archived longer
// than this and orphaned chat files older than this are purged by
// dbpurge. Returns 30 (days) when no value has been configured.
// A value of 0 disables chat purging entirely.
GetChatRetentionDays ( ctx context . Context ) ( int32 , error )
2026-08-24 11:53:47 +01:00
// GetChatSiteConfigValue returns raw text and row presence for an audited chat site configuration.
GetChatSiteConfigValue ( ctx context . Context , configKey string ) ( GetChatSiteConfigValueRow , error )
2026-06-12 13:33:12 +02:00
GetChatStreamSyncRows ( ctx context . Context , ids [] uuid . UUID ) ([] GetChatStreamSyncRowsRow , error )
2026-03-10 11:46:53 +00:00
GetChatSystemPrompt ( ctx context . Context ) ( string , error )
2026-03-26 13:32:41 +01:00
// GetChatSystemPromptConfig returns both chat system prompt settings in a
// single read to avoid torn reads between separate site-config lookups.
// The include-default fallback preserves the legacy behavior where a
// non-empty custom prompt implied opting out before the explicit toggle
// existed.
GetChatSystemPromptConfig ( ctx context . Context ) ( GetChatSystemPromptConfigRow , error )
2026-08-24 12:20:26 +02:00
GetChatUserModelOverride ( ctx context . Context , arg GetChatUserModelOverrideParams ) ( ChatUserModelOverride , error )
GetChatUserModelOverrides ( ctx context . Context , arg GetChatUserModelOverridesParams ) ([] ChatUserModelOverride , error )
2026-05-14 12:43:12 +02:00
// Returns the concatenated text of each user-visible user prompt in a
// chat, newest first. Used by the composer to populate the up/down
// arrow prompt-history cycle. Non-text parts (tool calls, files,
// attachments, ...) are excluded; messages whose text payload is
// entirely whitespace are dropped so cycling never lands on a blank
// entry. The jsonb_typeof guard skips legacy V0 rows whose content is
// a scalar JSON string (predates migration 000434) so the lateral
// jsonb_array_elements never raises "cannot extract elements from a
// scalar". Backed by idx_chat_messages_user_prompts.
GetChatUserPromptsByChatID ( ctx context . Context , arg GetChatUserPromptsByChatIDParams ) ([] GetChatUserPromptsByChatIDRow , error )
2026-08-18 16:55:43 +02:00
// Returns a bounded, pool-interleaved set of chats that workers may acquire.
// Interrupting chats finish active work first. Requires-action chats follow so
// their runner can enforce the action deadline before new generations start.
2026-06-12 13:33:12 +02:00
GetChatWorkerAcquisitionCandidates ( ctx context . Context , arg GetChatWorkerAcquisitionCandidatesParams ) ([] GetChatWorkerAcquisitionCandidatesRow , error )
2026-03-20 17:38:39 +00:00
// Returns the global TTL for chat workspaces as a Go duration string.
// Returns "0s" (disabled) when no value has been configured.
GetChatWorkspaceTTL ( ctx context . Context ) ( string , error )
2026-03-27 12:15:04 -04:00
GetChats ( ctx context . Context , arg GetChatsParams ) ([] GetChatsRow , error )
2026-05-18 22:32:05 +01:00
GetChatsByChatFileID ( ctx context . Context , fileID uuid . UUID ) ([] Chat , error )
2026-06-12 13:33:12 +02:00
GetChatsByIDsForRunnerSync ( ctx context . Context , ids [] uuid . UUID ) ([] Chat , error )
2026-03-26 11:30:12 +00:00
GetChatsByWorkspaceIDs ( ctx context . Context , ids [] uuid . UUID ) ([] Chat , error )
2026-04-08 09:47:44 -04:00
// Retrieves chats updated after the given timestamp for telemetry
// snapshot collection. Uses updated_at so that long-running chats
// still appear in each snapshot window while they are active.
GetChatsUpdatedAfter ( ctx context . Context , updatedAfter time . Time ) ([] GetChatsUpdatedAfterRow , error )
2026-04-20 13:19:59 +03:00
// Fetches child chats of the given parents, optionally filtered by
// archive state (NULL = all, true/false = match). The archive
// invariant (parent archived implies child archived) is enforced
// at write time, not here.
GetChildChatsByParentIDs ( ctx context . Context , arg GetChildChatsByParentIDsParams ) ([] GetChildChatsByParentIDsRow , error )
2026-09-02 11:29:35 +02:00
GetCodernautsEnabled ( ctx context . Context ) ( bool , error )
2025-07-15 14:36:06 +10:00
GetConnectionLogsOffset ( ctx context . Context , arg GetConnectionLogsOffsetParams ) ([] GetConnectionLogsOffsetRow , error )
2024-09-17 18:08:18 +01:00
GetCryptoKeyByFeatureAndSequence ( ctx context . Context , arg GetCryptoKeyByFeatureAndSequenceParams ) ( CryptoKey , error )
GetCryptoKeys ( ctx context . Context ) ([] CryptoKey , error )
2024-09-26 21:01:49 +01:00
GetCryptoKeysByFeature ( ctx context . Context , feature CryptoKeyFeature ) ([] CryptoKey , error )
2023-09-06 12:06:26 +01:00
GetDBCryptKeys ( ctx context . Context ) ([] DBCryptKey , error )
2022-10-17 08:43:30 -05:00
GetDERPMeshKey ( ctx context . Context ) ( string , error )
2026-06-12 13:33:12 +02:00
// Returns the current database timestamp. Used so transitions that
// record deadlines or heartbeats rely on a clock that is consistent
// with the database rather than the caller's local clock.
GetDatabaseNow ( ctx context . Context ) ( time . Time , error )
2026-08-24 10:30:01 +01:00
GetDefaultChatModelConfig ( ctx context . Context , organizationID uuid . UUID ) ( ChatModelConfig , error )
2024-02-16 08:28:36 -06:00
GetDefaultOrganization ( ctx context . Context ) ( Organization , error )
2023-06-08 10:30:15 -05:00
GetDefaultProxyConfig ( ctx context . Context ) ( GetDefaultProxyConfigRow , error )
2022-06-17 00:26:40 -05:00
GetDeploymentID ( ctx context . Context ) ( string , error )
2026-09-10 14:07:03 +02:00
// The session count sum runs in its own subquery: decomposing session_counts
// in the FROM clause would emit one row per app name and multiply the byte and
// latency aggregates below. Summing per app name and folding the names into
// families in Go keeps a session reported under a new name counted.
GetDeploymentWorkspaceAgentStats ( ctx context . Context , createdAt time . Time ) ( GetDeploymentWorkspaceAgentStatsRow , error )
GetDeploymentWorkspaceAgentUsageStats ( ctx context . Context , createdAt time . Time ) ( GetDeploymentWorkspaceAgentUsageStatsRow , error )
2023-03-08 21:05:45 -06:00
GetDeploymentWorkspaceStats ( ctx context . Context ) ( GetDeploymentWorkspaceStatsRow , error )
2024-12-11 13:38:13 +02:00
GetEligibleProvisionerDaemonsByProvisionerJobIDs ( ctx context . Context , provisionerJobIds [] uuid . UUID ) ([] GetEligibleProvisionerDaemonsByProvisionerJobIDsRow , error )
2026-04-16 17:08:02 +02:00
// Providers can be disabled independently of their model configs.
// Check both to ensure the selected config is actually usable.
GetEnabledChatModelConfigByID ( ctx context . Context , id uuid . UUID ) ( ChatModelConfig , error )
2026-08-24 10:30:01 +01:00
GetEnabledChatModelConfigsByOrganization ( ctx context . Context , organizationID uuid . UUID ) ([] GetEnabledChatModelConfigsByOrganizationRow , error )
2026-08-19 20:04:13 +02:00
GetEnabledMCPServerConfigsByOrganization ( ctx context . Context , organizationID uuid . UUID ) ([] MCPServerConfig , error )
GetEnabledMCPServerConfigsByOrganizationAndIDs ( ctx context . Context , arg GetEnabledMCPServerConfigsByOrganizationAndIDsParams ) ([] MCPServerConfig , error )
2026-06-04 15:28:13 -07:00
// GetExternalAgentTokensByTemplateID returns the auth tokens for all
// non-deleted external agents on the latest build of every running workspace
// of the given template. "Running" means the latest build has
// transition=start and job_status=succeeded (matches the workspace-status
// definition used by coderd/database/queries/workspaces.sql).
// An owner_id of '00000000-0000-0000-0000-000000000000' (uuid.Nil) means
// "all owners"; any other value restricts results to workspaces owned by
// that user.
GetExternalAgentTokensByTemplateID ( ctx context . Context , arg GetExternalAgentTokensByTemplateIDParams ) ([] GetExternalAgentTokensByTemplateIDRow , error )
2023-09-29 14:13:20 -05:00
GetExternalAuthLink ( ctx context . Context , arg GetExternalAuthLinkParams ) ( ExternalAuthLink , error )
GetExternalAuthLinksByUserID ( ctx context . Context , userID uuid . UUID ) ([] ExternalAuthLink , error )
2024-09-18 09:11:44 +02:00
GetFailedWorkspaceBuildsByTemplateID ( ctx context . Context , arg GetFailedWorkspaceBuildsByTemplateIDParams ) ([] GetFailedWorkspaceBuildsByTemplateIDRow , error )
2022-10-13 18:02:52 -05:00
GetFileByHashAndCreator ( ctx context . Context , arg GetFileByHashAndCreatorParams ) ( File , error )
GetFileByID ( ctx context . Context , id uuid . UUID ) ( File , error )
2023-03-27 09:21:41 -05:00
// Get all templates that use a file.
GetFileTemplates ( ctx context . Context , fileID uuid . UUID ) ([] GetFileTemplatesRow , error )
2025-03-03 10:12:48 +01:00
// Fetches inbox notifications for a user filtered by templates and targets
// param user_id: The user ID
// param templates: The template IDs to filter by - the template_id = ANY(@templates::UUID[]) condition checks if the template_id is in the @templates array
// param targets: The target IDs to filter by - the targets @> COALESCE(@targets, ARRAY[]::UUID[]) condition checks if the targets array (from the DB) contains all the elements in the @targets array
// param read_status: The read status to filter by - can be any of 'ALL', 'UNREAD', 'READ'
// param created_at_opt: The created_at timestamp to filter by. This parameter is usd for pagination - it fetches notifications created before the specified timestamp if it is not the zero value
// param limit_opt: The limit of notifications to fetch. If the limit is not specified, it defaults to 25
GetFilteredInboxNotificationsByUserID ( ctx context . Context , arg GetFilteredInboxNotificationsByUserIDParams ) ([] InboxNotification , error )
2026-08-19 20:04:13 +02:00
GetForcedMCPServerConfigsByOrganization ( ctx context . Context , organizationID uuid . UUID ) ([] MCPServerConfig , error )
2022-04-05 19:18:26 -05:00
GetGitSSHKey ( ctx context . Context , userID uuid . UUID ) ( GitSSHKey , error )
2026-06-16 11:01:43 +02:00
GetGroupAIBudget ( ctx context . Context , groupID uuid . UUID ) ( GroupAIBudget , error )
2022-10-10 15:37:06 -05:00
GetGroupByID ( ctx context . Context , id uuid . UUID ) ( Group , error )
GetGroupByOrgAndName ( ctx context . Context , arg GetGroupByOrgAndNameParams ) ( Group , error )
2025-03-25 14:18:06 +02:00
GetGroupMembers ( ctx context . Context , includeSystem bool ) ([] GroupMember , error )
2026-07-20 13:04:37 +01:00
// Returns each user's AI spend attributed to the queried group, on or after
// period_start until NOW. Only current members of the queried group are
2026-08-26 16:17:07 +01:00
// returned. effective_spend_limit_micros and effective_limit_source describe
// the user's effective budget when its group belongs to the queried group's
// organization. The effective group falls back to the Everyone group, and
// effective_group_id is null only when that group belongs to a different
// organization than the queried group.
2026-07-20 13:04:37 +01:00
// The period_start parameter is normalized to its UTC calendar day.
// TODO(AIGOV-527): unify effective group resolution in a single place.
// Spend is aggregated for the queried group, not the user's effective group.
GetGroupMembersAISpend ( ctx context . Context , arg GetGroupMembersAISpendParams ) ([] GetGroupMembersAISpendRow , error )
2025-03-25 14:18:06 +02:00
GetGroupMembersByGroupID ( ctx context . Context , arg GetGroupMembersByGroupIDParams ) ([] GroupMember , error )
2026-03-20 12:43:03 -08:00
GetGroupMembersByGroupIDPaginated ( ctx context . Context , arg GetGroupMembersByGroupIDPaginatedParams ) ([] GetGroupMembersByGroupIDPaginatedRow , error )
2024-08-13 16:20:24 +02:00
// Returns the total count of members in a group. Shows the total
// count even if the caller does not have read access to ResourceGroupMember.
// They only need ResourceGroup read access.
2025-03-25 14:18:06 +02:00
GetGroupMembersCountByGroupID ( ctx context . Context , arg GetGroupMembersCountByGroupIDParams ) ( int64 , error )
2026-05-20 17:40:50 -05:00
// Returns the total member count for each of the given group IDs in a
// single query. Used to avoid N+1 lookups when listing many groups. Like
// GetGroupMembersCountByGroupID, the count is returned even when the
// caller does not have read access to individual group members.
GetGroupMembersCountByGroupIDs ( ctx context . Context , arg GetGroupMembersCountByGroupIDsParams ) ([] GetGroupMembersCountByGroupIDsRow , error )
// A limit of 0 means "no limit".
2024-08-29 10:55:00 -06:00
GetGroups ( ctx context . Context , arg GetGroupsParams ) ([] GetGroupsRow , error )
2026-08-10 13:23:14 -07:00
GetGroupsByOrganizationIDPaginated ( ctx context . Context , arg GetGroupsByOrganizationIDPaginatedParams ) ([] GetGroupsByOrganizationIDPaginatedRow , error )
2023-11-23 17:18:12 +01:00
GetHealthSettings ( ctx context . Context ) ( string , error )
2026-06-10 10:01:20 -04:00
// Returns the highest group AI budget across the groups the user belongs to,
2026-07-23 09:26:25 +01:00
// breaking ties by the earliest organization membership. Implements the
// "highest" budget policy. group_members_expanded is a UNION of group_members
// and organization_members, so the implicit "Everyone" group
// (group_id == organization_id) is included. Returns no rows when the user has
// no budgeted groups. Callers should treat sql.ErrNoRows as "no group budget".
2026-06-10 10:01:20 -04:00
GetHighestGroupAIBudgetByUser ( ctx context . Context , userID uuid . UUID ) ( GetHighestGroupAIBudgetByUserRow , error )
2025-03-03 10:12:48 +01:00
GetInboxNotificationByID ( ctx context . Context , id uuid . UUID ) ( InboxNotification , error )
// Fetches inbox notifications for a user filtered by templates and targets
// param user_id: The user ID
// param read_status: The read status to filter by - can be any of 'ALL', 'UNREAD', 'READ'
// param created_at_opt: The created_at timestamp to filter by. This parameter is usd for pagination - it fetches notifications created before the specified timestamp if it is not the zero value
// param limit_opt: The limit of notifications to fetch. If the limit is not specified, it defaults to 25
GetInboxNotificationsByUserID ( ctx context . Context , arg GetInboxNotificationsByUserIDParams ) ([] InboxNotification , error )
2026-07-29 09:17:42 +02:00
// The returned id becomes both an AfterID cursor and last_read_message_id, so
// "last" must use id order.
2026-03-10 15:14:15 +00:00
GetLastChatMessageByRole ( ctx context . Context , arg GetLastChatMessageByRoleParams ) ( ChatMessage , error )
2022-12-01 19:43:28 +02:00
GetLastUpdateCheck ( ctx context . Context ) ( string , error )
2024-09-17 18:08:18 +01:00
GetLatestCryptoKeyByFeature ( ctx context . Context , feature CryptoKeyFeature ) ( CryptoKey , error )
2026-06-15 09:38:52 -07:00
GetLatestWorkspaceAgentContextSnapshot ( ctx context . Context , workspaceAgentID uuid . UUID ) ( WorkspaceAgentContextSnapshot , error )
2025-11-25 16:56:42 +02:00
GetLatestWorkspaceAppStatusByAppID ( ctx context . Context , appID uuid . UUID ) ( WorkspaceAppStatus , error )
2026-07-14 11:48:31 +10:00
// id DESC is a stability tiebreaker, not an insertion-order signal: back-to-back
// inserts can share a created_at on platforms with coarse time.Now() resolution,
// and id is a random UUID, so this only guarantees a deterministic pick, not the
// later row. Callers must not depend on sub-microsecond recency here.
2025-03-31 10:55:44 -04:00
GetLatestWorkspaceAppStatusesByWorkspaceIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceAppStatus , error )
2023-03-10 10:39:02 -06:00
GetLatestWorkspaceBuildByWorkspaceID ( ctx context . Context , workspaceID uuid . UUID ) ( WorkspaceBuild , error )
2026-04-17 22:47:08 -04:00
GetLatestWorkspaceBuildWithStatusByWorkspaceID ( ctx context . Context , workspaceID uuid . UUID ) ( GetLatestWorkspaceBuildWithStatusByWorkspaceIDRow , error )
2023-03-10 10:39:02 -06:00
GetLatestWorkspaceBuildsByWorkspaceIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceBuild , error )
2023-02-14 08:27:06 -06:00
GetLicenseByID ( ctx context . Context , id int32 ) ( License , error )
2022-08-24 11:44:22 -07:00
GetLicenses ( ctx context . Context ) ([] License , error )
2023-01-04 15:31:45 -06:00
GetLogoURL ( ctx context . Context ) ( string , error )
2026-03-19 10:07:36 -04:00
GetMCPServerConfigByID ( ctx context . Context , id uuid . UUID ) ( MCPServerConfig , error )
2026-08-19 20:04:13 +02:00
GetMCPServerConfigByIDForUpdate ( ctx context . Context , id uuid . UUID ) ( MCPServerConfig , error )
GetMCPServerConfigByOrganizationAndSlug ( ctx context . Context , arg GetMCPServerConfigByOrganizationAndSlugParams ) ( MCPServerConfig , error )
GetMCPServerConfigsByOrganization ( ctx context . Context , organizationID uuid . UUID ) ([] MCPServerConfig , error )
2026-03-19 10:07:36 -04:00
GetMCPServerUserToken ( ctx context . Context , arg GetMCPServerUserTokenParams ) ( MCPServerUserToken , error )
2026-08-19 21:36:59 +02:00
GetMCPServerUserTokenByID ( ctx context . Context , id uuid . UUID ) ( MCPServerUserToken , error )
2026-03-19 10:07:36 -04:00
GetMCPServerUserTokensByUserID ( ctx context . Context , userID uuid . UUID ) ([] MCPServerUserToken , error )
2026-07-07 09:18:30 -07:00
// Must be called from within a transaction. The row lock is released
// when the transaction ends.
GetNextPendingWorkspaceBuildOrchestrationForUpdate ( ctx context . Context ) ( WorkspaceBuildOrchestration , error )
2024-07-08 15:38:50 +02:00
GetNotificationMessagesByStatus ( ctx context . Context , arg GetNotificationMessagesByStatusParams ) ([] NotificationMessage , error )
2024-09-18 09:11:44 +02:00
// Fetch the notification report generator log indicating recent activity.
GetNotificationReportGeneratorLogByTemplate ( ctx context . Context , templateID uuid . UUID ) ( NotificationReportGeneratorLog , error )
2024-08-05 16:18:45 +02:00
GetNotificationTemplateByID ( ctx context . Context , id uuid . UUID ) ( NotificationTemplate , error )
GetNotificationTemplatesByKind ( ctx context . Context , kind NotificationTemplateKind ) ([] NotificationTemplate , error )
2024-07-10 16:15:06 +02:00
GetNotificationsSettings ( ctx context . Context ) ( string , error )
2026-07-28 16:59:33 -07:00
GetOAuth2DCREnabled ( ctx context . Context ) ( bool , error )
2025-02-25 16:31:33 +01:00
GetOAuth2GithubDefaultEligible ( ctx context . Context ) ( bool , error )
2025-07-03 18:33:47 +02:00
// RFC 7591/7592 Dynamic Client Registration queries
GetOAuth2ProviderAppByClientID ( ctx context . Context , id uuid . UUID ) ( OAuth2ProviderApp , error )
2023-12-21 12:38:42 -09:00
GetOAuth2ProviderAppByID ( ctx context . Context , id uuid . UUID ) ( OAuth2ProviderApp , error )
2024-02-20 15:58:43 -08:00
GetOAuth2ProviderAppCodeByID ( ctx context . Context , id uuid . UUID ) ( OAuth2ProviderAppCode , error )
GetOAuth2ProviderAppCodeByPrefix ( ctx context . Context , secretPrefix [] byte ) ( OAuth2ProviderAppCode , error )
2023-12-21 12:38:42 -09:00
GetOAuth2ProviderAppSecretByID ( ctx context . Context , id uuid . UUID ) ( OAuth2ProviderAppSecret , error )
2024-02-20 15:58:43 -08:00
GetOAuth2ProviderAppSecretByPrefix ( ctx context . Context , secretPrefix [] byte ) ( OAuth2ProviderAppSecret , error )
2023-12-21 12:38:42 -09:00
GetOAuth2ProviderAppSecretsByAppID ( ctx context . Context , appID uuid . UUID ) ([] OAuth2ProviderAppSecret , error )
2025-07-02 17:49:00 +02:00
GetOAuth2ProviderAppTokenByAPIKeyID ( ctx context . Context , apiKeyID string ) ( OAuth2ProviderAppToken , error )
2024-02-20 15:58:43 -08:00
GetOAuth2ProviderAppTokenByPrefix ( ctx context . Context , hashPrefix [] byte ) ( OAuth2ProviderAppToken , error )
2023-12-21 12:38:42 -09:00
GetOAuth2ProviderApps ( ctx context . Context ) ([] OAuth2ProviderApp , error )
2026-08-05 10:41:06 -07:00
// Joins directly on oauth2_provider_app_tokens.app_id rather than through
// app_secret_id, since app_secret_id is NULL for public (secretless) clients
// and would silently exclude their tokens from this listing.
2024-02-20 15:58:43 -08:00
GetOAuth2ProviderAppsByUserID ( ctx context . Context , userID uuid . UUID ) ([] GetOAuth2ProviderAppsByUserIDRow , error )
2026-08-11 13:53:15 +02:00
// Locks candidate rows against foreign-key inserts for the transaction.
GetOldUnlinkedChatFileIDs ( ctx context . Context , arg GetOldUnlinkedChatFileIDsParams ) ([] uuid . UUID , error )
2022-04-01 14:42:36 -05:00
GetOrganizationByID ( ctx context . Context , id uuid . UUID ) ( Organization , error )
2025-02-24 17:59:41 +00:00
GetOrganizationByName ( ctx context . Context , arg GetOrganizationByNameParams ) ( Organization , error )
2026-07-20 12:54:52 +01:00
// Returns AI spend limits and aggregate spend for groups in @group_ids that
2026-07-29 09:16:37 +01:00
// belong to @organization_id, on or after period_start until NOW.
// spend_limit_micros is the per-member limit, null when the group has no budget.
// total_spend_limit_micros is the combined budget of the members attributed to
2026-09-09 09:29:57 +01:00
// the group, with each member's override replacing their share. System users
// are excluded. It is null when the group has no budget.
2026-07-20 12:54:52 +01:00
// The period_start parameter is normalized to its UTC calendar day.
2026-07-29 09:16:37 +01:00
// TODO(AIGOV-527): unify effective group resolution in a single place.
2026-07-20 12:54:52 +01:00
GetOrganizationGroupsAISpend ( ctx context . Context , arg GetOrganizationGroupsAISpendParams ) ([] GetOrganizationGroupsAISpendRow , error )
2022-04-28 09:10:17 -05:00
GetOrganizationIDsByMemberIDs ( ctx context . Context , ids [] uuid . UUID ) ([] GetOrganizationIDsByMemberIDsRow , error )
2025-03-25 15:31:24 -04:00
GetOrganizationResourceCountByID ( ctx context . Context , organizationID uuid . UUID ) ( GetOrganizationResourceCountByIDRow , error )
2024-08-28 13:24:28 -05:00
GetOrganizations ( ctx context . Context , arg GetOrganizationsParams ) ([] Organization , error )
2025-02-24 17:59:41 +00:00
GetOrganizationsByUserID ( ctx context . Context , arg GetOrganizationsByUserIDParams ) ([] Organization , error )
2025-10-29 14:24:29 +00:00
// GetOrganizationsWithPrebuildStatus returns organizations with prebuilds configured and their
// membership status for the prebuilds system user (org membership, group existence, group membership).
GetOrganizationsWithPrebuildStatus ( ctx context . Context , arg GetOrganizationsWithPrebuildStatusParams ) ([] GetOrganizationsWithPrebuildStatusRow , error )
2026-07-28 09:22:58 +01:00
// Returns, per effective group, the number of users at or over their spend
2026-09-09 09:29:57 +01:00
// limit since period_start. Only non-system users with an enforceable limit
// (override or budgeted group) count, and the unlimited Everyone fallback does not.
2026-07-28 09:22:58 +01:00
// TODO(AIGOV-527): unify effective group resolution in a single place.
GetOverBudgetUsersPerGroup ( ctx context . Context , periodStart time . Time ) ([] GetOverBudgetUsersPerGroupRow , error )
2022-02-08 12:00:44 -06:00
GetParameterSchemasByJobID ( ctx context . Context , jobID uuid . UUID ) ([] ParameterSchema , error )
2025-04-03 10:58:30 +02:00
GetPrebuildMetrics ( ctx context . Context ) ([] GetPrebuildMetricsRow , error )
2025-07-02 17:05:42 +02:00
GetPrebuildsSettings ( ctx context . Context ) ( string , error )
2025-04-03 10:58:30 +02:00
GetPresetByID ( ctx context . Context , presetID uuid . UUID ) ( GetPresetByIDRow , error )
2025-02-11 13:55:09 +02:00
GetPresetByWorkspaceBuildID ( ctx context . Context , workspaceBuildID uuid . UUID ) ( TemplateVersionPreset , error )
2025-04-07 10:35:28 +02:00
GetPresetParametersByPresetID ( ctx context . Context , presetID uuid . UUID ) ([] TemplateVersionPresetParameter , error )
2025-02-11 13:55:09 +02:00
GetPresetParametersByTemplateVersionID ( ctx context . Context , templateVersionID uuid . UUID ) ([] TemplateVersionPresetParameter , error )
2025-05-21 15:16:38 -04:00
// GetPresetsAtFailureLimit groups workspace builds by preset ID.
// Each preset is associated with exactly one template version ID.
// For each preset, the query checks the last hard_limit builds.
// If all of them failed, the preset is considered to have hit the hard failure limit.
// The query returns a list of preset IDs that have reached this failure threshold.
// Only active template versions with configured presets are considered.
// For each preset, check the last hard_limit builds.
// If all of them failed, the preset is considered to have hit the hard failure limit.
GetPresetsAtFailureLimit ( ctx context . Context , hardLimit int64 ) ([] GetPresetsAtFailureLimitRow , error )
2025-04-03 10:58:30 +02:00
// GetPresetsBackoff groups workspace builds by preset ID.
// Each preset is associated with exactly one template version ID.
// For each group, the query checks up to N of the most recent jobs that occurred within the
// lookback period, where N equals the number of desired instances for the corresponding preset.
// If at least one of the job within a group has failed, we should backoff on the corresponding preset ID.
// Query returns a list of preset IDs for which we should backoff.
// Only active template versions with configured presets are considered.
// We also return the number of failed workspace builds that occurred during the lookback period.
//
// NOTE:
// - To **decide whether to back off**, we look at up to the N most recent builds (within the defined lookback period).
// - To **calculate the number of failed builds**, we consider all builds within the defined lookback period.
//
// The number of failed builds is used downstream to determine the backoff duration.
GetPresetsBackoff ( ctx context . Context , lookback time . Time ) ([] GetPresetsBackoffRow , error )
2025-02-11 13:55:09 +02:00
GetPresetsByTemplateVersionID ( ctx context . Context , templateVersionID uuid . UUID ) ([] TemplateVersionPreset , error )
2022-12-06 11:15:03 -03:00
GetPreviousTemplateVersion ( ctx context . Context , arg GetPreviousTemplateVersionParams ) ( TemplateVersion , error )
2022-01-31 23:36:15 -06:00
GetProvisionerDaemons ( ctx context . Context ) ([] ProvisionerDaemon , error )
2024-11-15 11:33:22 +02:00
GetProvisionerDaemonsByOrganization ( ctx context . Context , arg GetProvisionerDaemonsByOrganizationParams ) ([] ProvisionerDaemon , error )
2025-02-14 17:26:46 +02:00
// Current job information.
// Previous job information.
2025-01-14 18:40:26 +02:00
GetProvisionerDaemonsWithStatusByOrganization ( ctx context . Context , arg GetProvisionerDaemonsWithStatusByOrganizationParams ) ([] GetProvisionerDaemonsWithStatusByOrganizationRow , error )
2022-01-29 17:38:32 -06:00
GetProvisionerJobByID ( ctx context . Context , id uuid . UUID ) ( ProvisionerJob , error )
2025-05-20 15:22:44 +02:00
// Gets a single provisioner job by ID for update.
// This is used to securely reap jobs that have been hung/pending for a long time.
GetProvisionerJobByIDForUpdate ( ctx context . Context , id uuid . UUID ) ( ProvisionerJob , error )
2025-09-08 15:40:14 +02:00
// Gets a provisioner job by ID with exclusive lock.
// Blocks until the row is available for update.
GetProvisionerJobByIDWithLock ( ctx context . Context , id uuid . UUID ) ( ProvisionerJob , error )
2024-09-16 16:31:05 -03:00
GetProvisionerJobTimingsByJobID ( ctx context . Context , jobID uuid . UUID ) ([] ProvisionerJobTiming , error )
2026-08-24 16:17:55 +02:00
// Fetches provisioner jobs by their IDs without computing queue position or
// queue size. Callers that do not need the queue position should prefer this
// over GetProvisionerJobsByIDsWithQueuePosition, whose window functions over
// pending jobs and provisioner daemons are comparatively expensive.
GetProvisionerJobsByIDs ( ctx context . Context , ids [] uuid . UUID ) ([] ProvisionerJob , error )
2025-05-28 08:21:16 -04:00
GetProvisionerJobsByIDsWithQueuePosition ( ctx context . Context , arg GetProvisionerJobsByIDsWithQueuePositionParams ) ([] GetProvisionerJobsByIDsWithQueuePositionRow , error )
2025-01-20 11:18:53 +02:00
GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner ( ctx context . Context , arg GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerParams ) ([] GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow , error )
2022-06-17 00:26:40 -05:00
GetProvisionerJobsCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] ProvisionerJob , error )
2025-05-20 15:22:44 +02:00
// To avoid repeatedly attempting to reap the same jobs, we randomly order and limit to @max_jobs.
GetProvisionerJobsToBeReaped ( ctx context . Context , arg GetProvisionerJobsToBeReapedParams ) ([] ProvisionerJob , error )
2024-07-25 17:08:12 -04:00
GetProvisionerKeyByHashedSecret ( ctx context . Context , hashedSecret [] byte ) ( ProvisionerKey , error )
2024-07-16 13:27:12 -04:00
GetProvisionerKeyByID ( ctx context . Context , id uuid . UUID ) ( ProvisionerKey , error )
GetProvisionerKeyByName ( ctx context . Context , arg GetProvisionerKeyByNameParams ) ( ProvisionerKey , error )
2023-03-23 14:09:13 -05:00
GetProvisionerLogsAfterID ( ctx context . Context , arg GetProvisionerLogsAfterIDParams ) ([] ProvisionerJobLog , error )
2024-08-21 09:25:20 -05:00
GetQuotaAllowanceForUser ( ctx context . Context , arg GetQuotaAllowanceForUserParams ) ( int64 , error )
GetQuotaConsumedForUser ( ctx context . Context , arg GetQuotaConsumedForUserParams ) ( int64 , error )
2025-08-28 15:00:26 +01:00
// Count regular workspaces: only those whose first successful 'start' build
// was not initiated by the prebuild system user.
GetRegularWorkspaceCreateMetrics ( ctx context . Context ) ([] GetRegularWorkspaceCreateMetricsRow , error )
2023-07-26 09:21:04 -07:00
GetReplicaByID ( ctx context . Context , id uuid . UUID ) ( Replica , error )
2022-10-17 08:43:30 -05:00
GetReplicasUpdatedAfter ( ctx context . Context , updatedAt time . Time ) ([] Replica , error )
2025-04-03 10:58:30 +02:00
GetRunningPrebuiltWorkspaces ( ctx context . Context ) ([] GetRunningPrebuiltWorkspacesRow , error )
2024-09-09 14:14:52 -05:00
GetRuntimeConfig ( ctx context . Context , key string ) ( string , error )
2026-05-06 19:11:56 +03:00
// Find chats that appear stuck and need recovery:
2026-04-08 11:54:44 -04:00
// 1. Running chats whose heartbeat has expired (worker crash).
2026-05-06 19:11:56 +03:00
// 2. requires_action chats past the timeout threshold (client
// disappeared).
// 3. Waiting chats with a non-empty queue and stale updated_at
// (deferred-promote stranding when the worker dies before its
// post-cancel cleanup runs).
2026-02-27 11:50:56 -05:00
GetStaleChats ( ctx context . Context , staleThreshold time . Time ) ([] Chat , error )
2023-11-15 10:13:27 +04:00
GetTailnetPeers ( ctx context . Context , id uuid . UUID ) ([] TailnetPeer , error )
2026-04-03 14:22:58 -05:00
GetTailnetTunnelPeerBindingsBatch ( ctx context . Context , ids [] uuid . UUID ) ([] GetTailnetTunnelPeerBindingsBatchRow , error )
GetTailnetTunnelPeerIDsBatch ( ctx context . Context , ids [] uuid . UUID ) ([] GetTailnetTunnelPeerIDsBatchRow , error )
2025-10-13 12:25:58 +03:00
GetTaskByID ( ctx context . Context , id uuid . UUID ) ( Task , error )
2025-11-05 14:28:34 +00:00
GetTaskByOwnerIDAndName ( ctx context . Context , arg GetTaskByOwnerIDAndNameParams ) ( Task , error )
2025-10-13 12:25:58 +03:00
GetTaskByWorkspaceID ( ctx context . Context , workspaceID uuid . UUID ) ( Task , error )
2026-01-27 11:09:24 +02:00
GetTaskSnapshot ( ctx context . Context , taskID uuid . UUID ) ( TaskSnapshot , error )
2025-01-31 13:55:46 +01:00
GetTelemetryItem ( ctx context . Context , key string ) ( TelemetryItem , error )
GetTelemetryItems ( ctx context . Context ) ([] TelemetryItem , error )
2026-02-24 17:04:42 +00:00
// Returns all data needed to build task lifecycle events for telemetry
// in a single round-trip. For each task whose workspace is in the
// given set, fetches:
// - the latest workspace app binding (task_workspace_apps)
// - the most recent stop and start builds (workspace_builds)
// - the last "working" app status (workspace_app_statuses)
// - the first app status after resume, for active workspaces
//
// Assumptions:
// - 1:1 relationship between tasks and workspaces. All builds on the
// workspace are considered task-related.
// - Idle duration approximation: If the agent reports "working", does
// work, then reports "done", we miss that working time.
// - lws and active_dur join across all historical app IDs for the task,
// because each resume cycle provisions a new app ID. This ensures
// pre-pause statuses contribute to idle duration and active duration.
GetTelemetryTaskEvents ( ctx context . Context , arg GetTelemetryTaskEventsParams ) ([] GetTelemetryTaskEventsRow , error )
2023-08-21 15:08:58 +03:00
// GetTemplateAppInsights returns the aggregate usage of each app in a given
// timeframe. The result can be filtered on template_ids, meaning only user data
// from workspaces based on those templates will be included.
GetTemplateAppInsights ( ctx context . Context , arg GetTemplateAppInsightsParams ) ([] GetTemplateAppInsightsRow , error )
2024-03-25 17:42:02 +02:00
// GetTemplateAppInsightsByTemplate is used for Prometheus metrics. Keep
// in sync with GetTemplateAppInsights and UpsertTemplateUsageStats.
2023-11-07 17:14:59 +01:00
GetTemplateAppInsightsByTemplate ( ctx context . Context , arg GetTemplateAppInsightsByTemplateParams ) ([] GetTemplateAppInsightsByTemplateRow , error )
2025-09-01 09:31:21 -07:00
GetTemplateAverageBuildTime ( ctx context . Context , templateID uuid . NullUUID ) ( GetTemplateAverageBuildTimeRow , error )
2022-04-06 12:42:40 -05:00
GetTemplateByID ( ctx context . Context , id uuid . UUID ) ( Template , error )
GetTemplateByOrganizationAndName ( ctx context . Context , arg GetTemplateByOrganizationAndNameParams ) ( Template , error )
2024-03-25 15:33:31 +02:00
// GetTemplateInsights returns the aggregate user-produced usage of all
// workspaces in a given timeframe. The template IDs, active users, and
// usage_seconds all reflect any usage in the template, including apps.
//
// When combining data from multiple templates, we must make a guess at
// how the user behaved for the 30 minute interval. In this case we make
// the assumption that if the user used two workspaces for 15 minutes,
// they did so sequentially, thus we sum the usage up to a maximum of
// 30 minutes with LEAST(SUM(n), 30).
2023-07-21 21:00:19 +03:00
GetTemplateInsights ( ctx context . Context , arg GetTemplateInsightsParams ) ( GetTemplateInsightsRow , error )
2023-09-15 14:01:00 +02:00
// GetTemplateInsightsByInterval returns all intervals between start and end
// time, if end time is a partial interval, it will be included in the results and
// that interval will be shorter than a full one. If there is no data for a selected
// interval/template, it will be included in the results with 0 active users.
GetTemplateInsightsByInterval ( ctx context . Context , arg GetTemplateInsightsByIntervalParams ) ([] GetTemplateInsightsByIntervalRow , error )
2024-03-25 17:42:02 +02:00
// GetTemplateInsightsByTemplate is used for Prometheus metrics. Keep
// in sync with GetTemplateInsights and UpsertTemplateUsageStats.
2023-10-19 10:45:12 +02:00
GetTemplateInsightsByTemplate ( ctx context . Context , arg GetTemplateInsightsByTemplateParams ) ([] GetTemplateInsightsByTemplateRow , error )
2023-08-03 17:43:23 +03:00
// GetTemplateParameterInsights does for each template in a given timeframe,
// look for the latest workspace build (for every workspace) that has been
// created in the timeframe and return the aggregate usage counts of parameter
// values.
GetTemplateParameterInsights ( ctx context . Context , arg GetTemplateParameterInsightsParams ) ([] GetTemplateParameterInsightsRow , error )
2025-04-03 10:58:30 +02:00
// GetTemplatePresetsWithPrebuilds retrieves template versions with configured presets and prebuilds.
// It also returns the number of desired instances for each preset.
// If template_id is specified, only template versions associated with that template will be returned.
GetTemplatePresetsWithPrebuilds ( ctx context . Context , templateID uuid . NullUUID ) ([] GetTemplatePresetsWithPrebuildsRow , error )
2026-06-18 13:41:47 +08:00
// GetTemplateRankingSignalsByOwnerID returns raw template-ranking signals for
// one owner: in-window active and recently-deleted workspace counts, the last
// in-window usage, and distinct active developers per template. The affinity
// score is computed in Go (see listtemplates.go) so the ranking policy and
// its confidence thresholds live in one place.
GetTemplateRankingSignalsByOwnerID ( ctx context . Context , arg GetTemplateRankingSignalsByOwnerIDParams ) ([] GetTemplateRankingSignalsByOwnerIDRow , error )
2024-03-22 18:33:34 +02:00
GetTemplateUsageStats ( ctx context . Context , arg GetTemplateUsageStatsParams ) ([] TemplateUsageStat , error )
2022-04-06 12:42:40 -05:00
GetTemplateVersionByID ( ctx context . Context , id uuid . UUID ) ( TemplateVersion , error )
GetTemplateVersionByJobID ( ctx context . Context , jobID uuid . UUID ) ( TemplateVersion , error )
GetTemplateVersionByTemplateIDAndName ( ctx context . Context , arg GetTemplateVersionByTemplateIDAndNameParams ) ( TemplateVersion , error )
2023-01-17 11:22:11 +01:00
GetTemplateVersionParameters ( ctx context . Context , templateVersionID uuid . UUID ) ([] TemplateVersionParameter , error )
2025-04-01 14:47:30 -07:00
GetTemplateVersionTerraformValues ( ctx context . Context , templateVersionID uuid . UUID ) ( TemplateVersionTerraformValue , error )
2023-02-15 18:24:15 +01:00
GetTemplateVersionVariables ( ctx context . Context , templateVersionID uuid . UUID ) ([] TemplateVersionVariable , error )
2024-05-20 15:30:19 +02:00
GetTemplateVersionWorkspaceTags ( ctx context . Context , templateVersionID uuid . UUID ) ([] TemplateVersionWorkspaceTag , error )
2022-11-28 16:53:56 -03:00
GetTemplateVersionsByIDs ( ctx context . Context , ids [] uuid . UUID ) ([] TemplateVersion , error )
2022-05-10 10:44:09 +03:00
GetTemplateVersionsByTemplateID ( ctx context . Context , arg GetTemplateVersionsByTemplateIDParams ) ([] TemplateVersion , error )
2022-06-17 00:26:40 -05:00
GetTemplateVersionsCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] TemplateVersion , error )
GetTemplates ( ctx context . Context ) ([] Template , error )
2022-06-14 08:46:33 -05:00
GetTemplatesWithFilter ( ctx context . Context , arg GetTemplatesWithFilterParams ) ([] Template , error )
2026-07-30 15:37:45 +08:00
// Computes hb_agent_runtime_v1 usage event payloads. Deliberately includes
// soft-deleted messages and messages from all chats.
GetTotalChatMessageRuntimeMsInRange ( ctx context . Context , arg GetTotalChatMessageRuntimeMsInRangeParams ) ( int64 , error )
2025-08-30 03:39:37 +10:00
// Gets the total number of managed agents created between two dates. Uses the
// aggregate table to avoid large scans or a complex index on the usage_events
// table.
//
// This has the trade off that we can't count accurately between two exact
// timestamps. The provided timestamps will be converted to UTC and truncated to
// the events that happened on and between the two dates. Both dates are
// inclusive.
GetTotalUsageDCManagedAgentsV1 ( ctx context . Context , arg GetTotalUsageDCManagedAgentsV1Params ) ( int64 , error )
2026-08-18 12:40:33 +07:00
// Gets the total Coder Agent runtime in milliseconds between two timestamps.
// The start bound is inclusive and the end bound is exclusive.
//
// Unlike GetTotalUsageDCManagedAgentsV1 this reads usage_events directly
// rather than the usage_events_daily rollup: hb_agent_runtime_v1 is exactly
// one row per hourly bucket deployment-wide, with created_at at the bucket
// start, enforced by the unique partial index
// idx_usage_events_agent_runtime (which also keeps SUM from counting a
// bucket twice and serves this query). The result is bucket-granular: a
// bucket counts entirely against the period containing its start. See
// enterprise/coderd/usage/generator.go for what a bucket holds. If a
// usage_events retention policy ever lands, this must move to the daily
// rollup and accept day-granularity bounds.
GetTotalUsageHBAgentRuntimeV1 ( ctx context . Context , arg GetTotalUsageHBAgentRuntimeV1Params ) ( int64 , error )
2022-08-29 16:45:40 -07:00
GetUnexpiredLicenses ( ctx context . Context ) ([] License , error )
2026-08-27 17:04:13 -04:00
// Returns the models used since the given time that hold no price, most used
// first. openai-compat providers cannot be priced, so their models are excluded.
GetUnpricedAIModelsSince ( ctx context . Context , arg GetUnpricedAIModelsSinceParams ) ([] GetUnpricedAIModelsSinceRow , error )
2026-08-28 15:44:31 +07:00
// Counts unpublished usage events in the last 60 days:
// pending: created within the last 30 days (still eligible to publish)
// expired: created 30-60 days ago (too old to publish; Tallyman would reject)
// Events older than 60 days are ignored so this query stays bounded and the
// expired gauge can recover to zero.
GetUsageEventsStats ( ctx context . Context , now time . Time ) ( GetUsageEventsStatsRow , error )
2026-06-16 11:01:43 +02:00
GetUserAIBudgetOverride ( ctx context . Context , userID uuid . UUID ) ( UserAIBudgetOverride , error )
GetUserAIProviderKeyByProviderID ( ctx context . Context , arg GetUserAIProviderKeyByProviderIDParams ) ( UserAIProviderKey , error )
2026-05-22 02:16:01 +02:00
// GetUserAIProviderKeys is used by dbcrypt key rotation. Request paths should use
// user-scoped lookups instead of this bulk accessor.
2026-06-16 11:01:43 +02:00
GetUserAIProviderKeys ( ctx context . Context ) ([] UserAIProviderKey , error )
GetUserAIProviderKeysByUserID ( ctx context . Context , userID uuid . UUID ) ([] UserAIProviderKey , error )
2026-03-26 17:36:40 +07:00
// Returns user IDs from the provided list that are consuming an AI seat.
// Filters to active, non-deleted, non-system users to match the canonical
// seat count query (GetActiveAISeatCount).
GetUserAISeatStates ( ctx context . Context , userIds [] uuid . UUID ) ([] uuid . UUID , error )
2026-07-02 16:29:25 +01:00
// Total spend for (user_id, effective_group_id) on or after period_start until NOW.
// The period_start parameter is normalized to its UTC calendar day.
GetUserAISpendSince ( ctx context . Context , arg GetUserAISpendSinceParams ) ( GetUserAISpendSinceRow , error )
2023-09-26 18:42:16 +02:00
// GetUserActivityInsights returns the ranking with top active users.
2024-03-25 16:16:41 +02:00
// The result can be filtered on template_ids, meaning only user data
// from workspaces based on those templates will be included.
// Note: The usage_seconds and usage_seconds_cumulative differ only when
// requesting deployment-wide (or multiple template) data. Cumulative
// produces a bloated value if a user has used multiple templates
2023-09-26 18:42:16 +02:00
// simultaneously.
GetUserActivityInsights ( ctx context . Context , arg GetUserActivityInsightsParams ) ([] GetUserActivityInsightsRow , error )
2026-05-12 10:09:34 +02:00
GetUserAgentChatSendShortcut ( ctx context . Context , userID uuid . UUID ) ( string , error )
2026-05-14 11:44:05 +07:00
GetUserAppearanceSettings ( ctx context . Context , userID uuid . UUID ) ( GetUserAppearanceSettingsRow , error )
2022-01-20 07:46:51 -06:00
GetUserByEmailOrUsername ( ctx context . Context , arg GetUserByEmailOrUsernameParams ) ( User , error )
2022-04-01 14:42:36 -05:00
GetUserByID ( ctx context . Context , id uuid . UUID ) ( User , error )
2026-03-24 00:48:18 +01:00
GetUserChatCompactionThreshold ( ctx context . Context , arg GetUserChatCompactionThresholdParams ) ( string , error )
2026-03-10 08:17:52 -07:00
GetUserChatCustomPrompt ( ctx context . Context , userID uuid . UUID ) ( string , error )
2026-04-13 15:06:06 +02:00
GetUserChatDebugLoggingEnabled ( ctx context . Context , userID uuid . UUID ) ( bool , error )
2026-05-07 20:15:28 +01:00
GetUserCodeDiffDisplayMode ( ctx context . Context , userID uuid . UUID ) ( string , error )
2025-03-25 14:18:06 +02:00
GetUserCount ( ctx context . Context , includeSystem bool ) ( int64 , error )
2026-07-23 09:26:25 +01:00
// Returns the "Everyone" group (id == organization_id) to attribute a user's
// spend to when no override or budgeted group applies. Prefers the default org,
// then the earliest organization membership. Returns no rows when the user has
// no organization membership.
GetUserEveryoneFallbackGroup ( ctx context . Context , userID uuid . UUID ) ( uuid . UUID , error )
2026-07-18 20:45:13 +02:00
GetUserForChatSyntheticAPIKeyByID ( ctx context . Context , id uuid . UUID ) ( User , error )
2023-07-21 21:00:19 +03:00
// GetUserLatencyInsights returns the median and 95th percentile connection
// latency that users have experienced. The result can be filtered on
// template_ids, meaning only user data from workspaces based on those templates
// will be included.
GetUserLatencyInsights ( ctx context . Context , arg GetUserLatencyInsightsParams ) ([] GetUserLatencyInsightsRow , error )
2022-08-17 18:00:53 -05:00
GetUserLinkByLinkedID ( ctx context . Context , linkedID string ) ( UserLink , error )
GetUserLinkByUserIDLoginType ( ctx context . Context , arg GetUserLinkByUserIDLoginTypeParams ) ( UserLink , error )
2023-09-06 12:06:26 +01:00
GetUserLinksByUserID ( ctx context . Context , userID uuid . UUID ) ([] UserLink , error )
2024-08-05 16:18:45 +02:00
GetUserNotificationPreferences ( ctx context . Context , userID uuid . UUID ) ([] NotificationPreference , error )
2026-04-29 12:57:47 -06:00
GetUserSecretByID ( ctx context . Context , id uuid . UUID ) ( UserSecret , error )
2025-08-07 15:58:59 -04:00
GetUserSecretByUserIDAndName ( ctx context . Context , arg GetUserSecretByUserIDAndNameParams ) ( UserSecret , error )
2026-09-02 12:21:36 -04:00
GetUserSecretByUserIDAndNameForUpdate ( ctx context . Context , arg GetUserSecretByUserIDAndNameForUpdateParams ) ( UserSecret , error )
2026-05-05 09:56:39 -07:00
// Returns deployment-wide aggregates for the telemetry snapshot.
//
// The denominator for both user-level counts and the per-user
// distribution is active non-system users. Specifically:
//
// * deleted = false: Coder soft-deletes by flipping users.deleted
2026-05-11 08:07:30 -07:00
// rather than removing rows. The delete_deleted_user_resources()
// trigger now removes their user_secrets, but soft-deleted users
// are still excluded here so they don't dilute the percentile
// distribution as zero-secret entries.
2026-05-05 09:56:39 -07:00
// * status = 'active': dormant users (no recent activity) and
// suspended users (explicitly disabled) cannot use secrets, so
// they shouldn't dilute the percentile distribution as
// zero-secret entries.
// * is_system = false: internal subjects like the prebuilds user
// never use secrets in the normal flow.
//
// Status transitions move users in and out of this denominator, so a
// snapshot's UsersWithSecrets can drop without any secret being
// deleted.
//
// The percentile distribution is computed across all active non-system
// users, including those with zero secrets, so the percentiles reflect
// deployment-wide adoption rather than only the power-user subset.
// percentile_disc returns an actual integer count from the underlying
// values rather than interpolating between rows.
GetUserSecretsTelemetrySummary ( ctx context . Context ) ( GetUserSecretsTelemetrySummaryRow , error )
2026-05-14 14:25:07 +01:00
GetUserShellToolDisplayMode ( ctx context . Context , userID uuid . UUID ) ( string , error )
2026-05-20 00:09:09 +02:00
GetUserSkillByUserIDAndName ( ctx context . Context , arg GetUserSkillByUserIDAndNameParams ) ( UserSkill , error )
2025-01-13 13:08:16 +02:00
// GetUserStatusCounts returns the count of users in each status over time.
// The time range is inclusively defined by the start_time and end_time parameters.
GetUserStatusCounts ( ctx context . Context , arg GetUserStatusCountsParams ) ([] GetUserStatusCountsRow , error )
2026-04-24 12:29:08 +01:00
GetUserThinkingDisplayMode ( ctx context . Context , userID uuid . UUID ) ( string , error )
2024-01-30 16:02:21 -06:00
GetUserWorkspaceBuildParameters ( ctx context . Context , arg GetUserWorkspaceBuildParametersParams ) ([] GetUserWorkspaceBuildParametersRow , error )
2022-12-16 01:04:24 +10:00
// This will never return deleted users.
2022-11-14 17:22:57 -05:00
GetUsers ( ctx context . Context , arg GetUsersParams ) ([] GetUsersRow , error )
2022-10-10 13:03:54 -05:00
// This shouldn't check for deleted, because it's frequently used
// to look up references to actions. eg. a user could build a workspace
// for another user, then be deleted... we still want them to appear!
GetUsersByIDs ( ctx context . Context , ids [] uuid . UUID ) ([] User , error )
2025-03-27 10:03:53 +00:00
GetWebpushSubscriptionsByUserID ( ctx context . Context , userID uuid . UUID ) ([] WebpushSubscription , error )
GetWebpushVAPIDKeys ( ctx context . Context ) ( GetWebpushVAPIDKeysRow , error )
2025-08-25 06:11:18 -06:00
GetWorkspaceACLByID ( ctx context . Context , id uuid . UUID ) ( GetWorkspaceACLByIDRow , error )
2026-01-19 12:36:33 +00:00
GetWorkspaceAgentAndWorkspaceByID ( ctx context . Context , id uuid . UUID ) ( GetWorkspaceAgentAndWorkspaceByIDRow , error )
2022-04-11 16:06:15 -05:00
GetWorkspaceAgentByID ( ctx context . Context , id uuid . UUID ) ( WorkspaceAgent , error )
2025-03-20 19:09:39 +02:00
GetWorkspaceAgentDevcontainersByAgentID ( ctx context . Context , workspaceAgentID uuid . UUID ) ([] WorkspaceAgentDevcontainer , error )
2023-06-20 14:41:55 +03:00
GetWorkspaceAgentLifecycleStateByID ( ctx context . Context , id uuid . UUID ) ( GetWorkspaceAgentLifecycleStateByIDRow , error )
2023-09-25 16:47:17 -05:00
GetWorkspaceAgentLogSourcesByAgentIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceAgentLogSource , error )
2023-07-28 09:57:23 -06:00
GetWorkspaceAgentLogsAfter ( ctx context . Context , arg GetWorkspaceAgentLogsAfterParams ) ([] WorkspaceAgentLog , error )
2023-10-13 16:37:55 +03:00
GetWorkspaceAgentMetadata ( ctx context . Context , arg GetWorkspaceAgentMetadataParams ) ([] WorkspaceAgentMetadatum , error )
2024-02-13 09:31:20 -05:00
GetWorkspaceAgentPortShare ( ctx context . Context , arg GetWorkspaceAgentPortShareParams ) ( WorkspaceAgentPortShare , error )
2024-10-14 09:31:03 -03:00
GetWorkspaceAgentScriptTimingsByBuildID ( ctx context . Context , id uuid . UUID ) ([] GetWorkspaceAgentScriptTimingsByBuildIDRow , error )
2026-04-29 12:24:26 -08:00
GetWorkspaceAgentScriptsByAgentIDs ( ctx context . Context , ids [] uuid . UUID ) ([] GetWorkspaceAgentScriptsByAgentIDsRow , error )
2026-09-10 14:07:03 +02:00
GetWorkspaceAgentStats ( ctx context . Context , createdAt time . Time ) ([] GetWorkspaceAgentStatsRow , error )
GetWorkspaceAgentStatsAndLabels ( ctx context . Context , createdAt time . Time ) ([] GetWorkspaceAgentStatsAndLabelsRow , error )
GetWorkspaceAgentUsageStats ( ctx context . Context , createdAt time . Time ) ([] GetWorkspaceAgentUsageStatsRow , error )
GetWorkspaceAgentUsageStatsAndLabels ( ctx context . Context , createdAt time . Time ) ([] GetWorkspaceAgentUsageStatsAndLabelsRow , error )
2026-04-16 13:59:09 +02:00
GetWorkspaceAgentsByInstanceID ( ctx context . Context , authInstanceID string ) ([] WorkspaceAgent , error )
2025-05-29 12:15:47 +01:00
GetWorkspaceAgentsByParentID ( ctx context . Context , parentID uuid . UUID ) ([] WorkspaceAgent , error )
2022-04-11 16:06:15 -05:00
GetWorkspaceAgentsByResourceIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceAgent , error )
2025-05-14 14:15:36 +02:00
GetWorkspaceAgentsByWorkspaceAndBuildNumber ( ctx context . Context , arg GetWorkspaceAgentsByWorkspaceAndBuildNumberParams ) ([] WorkspaceAgent , error )
2022-06-17 00:26:40 -05:00
GetWorkspaceAgentsCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] WorkspaceAgent , error )
2025-10-17 13:40:10 -07:00
GetWorkspaceAgentsForMetrics ( ctx context . Context ) ([] GetWorkspaceAgentsForMetricsRow , error )
2023-03-31 00:24:51 +11:00
GetWorkspaceAgentsInLatestBuildByWorkspaceID ( ctx context . Context , workspaceID uuid . UUID ) ([] WorkspaceAgent , error )
2026-07-14 13:50:25 +01:00
GetWorkspaceAgentsInLatestBuildByWorkspaceIDs ( ctx context . Context , workspaceIds [] uuid . UUID ) ([] GetWorkspaceAgentsInLatestBuildByWorkspaceIDsRow , error )
2022-10-29 03:41:31 +10:00
GetWorkspaceAppByAgentIDAndSlug ( ctx context . Context , arg GetWorkspaceAppByAgentIDAndSlugParams ) ( WorkspaceApp , error )
2025-03-31 10:55:44 -04:00
GetWorkspaceAppStatusesByAppIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceAppStatus , error )
2022-06-04 15:13:37 -05:00
GetWorkspaceAppsByAgentID ( ctx context . Context , agentID uuid . UUID ) ([] WorkspaceApp , error )
GetWorkspaceAppsByAgentIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceApp , error )
2022-06-17 00:26:40 -05:00
GetWorkspaceAppsCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] WorkspaceApp , error )
2026-05-12 14:55:56 +02:00
GetWorkspaceBuildAgentsByInstanceID ( ctx context . Context , authInstanceID string ) ([] GetWorkspaceBuildAgentsByInstanceIDRow , error )
2023-03-10 10:39:02 -06:00
GetWorkspaceBuildByID ( ctx context . Context , id uuid . UUID ) ( WorkspaceBuild , error )
GetWorkspaceBuildByJobID ( ctx context . Context , jobID uuid . UUID ) ( WorkspaceBuild , error )
GetWorkspaceBuildByWorkspaceIDAndBuildNumber ( ctx context . Context , arg GetWorkspaceBuildByWorkspaceIDAndBuildNumberParams ) ( WorkspaceBuild , error )
2026-02-06 16:26:02 -06:00
// Returns build metadata for e2e workspace build duration metrics.
// Also checks if all agents are ready and returns the worst status.
GetWorkspaceBuildMetricsByResourceID ( ctx context . Context , id uuid . UUID ) ( GetWorkspaceBuildMetricsByResourceIDRow , error )
2023-01-17 11:22:11 +01:00
GetWorkspaceBuildParameters ( ctx context . Context , workspaceBuildID uuid . UUID ) ([] WorkspaceBuildParameter , error )
2026-02-23 22:46:17 -06:00
// Fetches the provisioner state of a workspace build, joined through to the
// template so that dbauthz can enforce policy.ActionUpdate on the template.
// Provisioner state contains sensitive Terraform state and should only be
// accessible to template administrators.
GetWorkspaceBuildProvisionerStateByID ( ctx context . Context , workspaceBuildID uuid . UUID ) ( GetWorkspaceBuildProvisionerStateByIDRow , error )
2024-09-18 09:11:44 +02:00
GetWorkspaceBuildStatsByTemplates ( ctx context . Context , since time . Time ) ([] GetWorkspaceBuildStatsByTemplatesRow , error )
2023-03-10 10:39:02 -06:00
GetWorkspaceBuildsByWorkspaceID ( ctx context . Context , arg GetWorkspaceBuildsByWorkspaceIDParams ) ([] WorkspaceBuild , error )
GetWorkspaceBuildsCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] WorkspaceBuild , error )
2024-10-22 09:20:54 -05:00
GetWorkspaceByAgentID ( ctx context . Context , agentID uuid . UUID ) ( Workspace , error )
2022-01-29 17:38:32 -06:00
GetWorkspaceByID ( ctx context . Context , id uuid . UUID ) ( Workspace , error )
2022-04-25 16:11:03 -05:00
GetWorkspaceByOwnerIDAndName ( ctx context . Context , arg GetWorkspaceByOwnerIDAndNameParams ) ( Workspace , error )
2025-05-20 21:20:56 +01:00
GetWorkspaceByResourceID ( ctx context . Context , resourceID uuid . UUID ) ( Workspace , error )
2023-02-14 08:27:06 -06:00
GetWorkspaceByWorkspaceAppID ( ctx context . Context , workspaceAppID uuid . UUID ) ( Workspace , error )
2024-11-16 21:56:19 +01:00
GetWorkspaceModulesByJobID ( ctx context . Context , jobID uuid . UUID ) ([] WorkspaceModule , error )
GetWorkspaceModulesCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] WorkspaceModule , error )
2023-04-04 15:07:29 -05:00
GetWorkspaceProxies ( ctx context . Context ) ([] WorkspaceProxy , error )
2023-04-17 14:57:21 -05:00
// Finds a workspace proxy that has an access URL or app hostname that matches
// the provided hostname. This is to check if a hostname matches any workspace
// proxy.
//
// The hostname must be sanitized to only contain [a-zA-Z0-9.-] before calling
// this query. The scheme, port and path should be stripped.
//
2023-04-20 16:59:45 -07:00
GetWorkspaceProxyByHostname ( ctx context . Context , arg GetWorkspaceProxyByHostnameParams ) ( WorkspaceProxy , error )
2023-04-04 15:07:29 -05:00
GetWorkspaceProxyByID ( ctx context . Context , id uuid . UUID ) ( WorkspaceProxy , error )
2023-04-20 09:48:47 -05:00
GetWorkspaceProxyByName ( ctx context . Context , name string ) ( WorkspaceProxy , error )
2022-03-07 11:40:54 -06:00
GetWorkspaceResourceByID ( ctx context . Context , id uuid . UUID ) ( WorkspaceResource , error )
2022-08-01 16:53:05 -05:00
GetWorkspaceResourceMetadataByResourceIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceResourceMetadatum , error )
2022-08-18 10:57:46 -05:00
GetWorkspaceResourceMetadataCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] WorkspaceResourceMetadatum , error )
2022-03-07 11:40:54 -06:00
GetWorkspaceResourcesByJobID ( ctx context . Context , jobID uuid . UUID ) ([] WorkspaceResource , error )
2022-09-16 14:54:23 -04:00
GetWorkspaceResourcesByJobIDs ( ctx context . Context , ids [] uuid . UUID ) ([] WorkspaceResource , error )
2022-06-17 00:26:40 -05:00
GetWorkspaceResourcesCreatedAfter ( ctx context . Context , createdAt time . Time ) ([] WorkspaceResource , error )
2023-12-07 10:53:15 -05:00
GetWorkspaceUniqueOwnerCountByTemplateIDs ( ctx context . Context , templateIds [] uuid . UUID ) ([] GetWorkspaceUniqueOwnerCountByTemplateIDsRow , error )
2024-03-22 14:22:47 -05:00
// build_params is used to filter by build parameters if present.
// It has to be a CTE because the set returning function 'unnest' cannot
// be used in a WHERE clause.
2022-11-16 10:16:37 -05:00
GetWorkspaces ( ctx context . Context , arg GetWorkspacesParams ) ([] GetWorkspacesRow , error )
2024-11-01 14:36:12 +11:00
GetWorkspacesAndAgentsByOwnerID ( ctx context . Context , ownerID uuid . UUID ) ([] GetWorkspacesAndAgentsByOwnerIDRow , error )
2024-12-02 21:02:36 +00:00
GetWorkspacesByTemplateID ( ctx context . Context , templateID uuid . UUID ) ([] WorkspaceTable , error )
2026-06-26 01:25:23 -05:00
// Returns workspaces the lifecycle executor must act on this tick. An
// "action" is a state transition (autostart/autostop/dormancy/delete), a
// dormancy mark (which has no build transition), or a one-time autostop
// reminder notification (which only stamps a marker, no transition).
GetWorkspacesEligibleForLifecycleAction ( ctx context . Context , now time . Time ) ([] GetWorkspacesEligibleForLifecycleActionRow , error )
2025-10-17 13:40:10 -07:00
GetWorkspacesForWorkspaceMetrics ( ctx context . Context ) ([] GetWorkspacesForWorkspaceMetricsRow , error )
2026-06-24 12:09:22 -05:00
// Reports whether the given file is referenced as cached module files by any
// template version in the given organization. Used to authorize provisioner
// module-file downloads so a daemon cannot read another organization's cached
// Terraform module source.
HasTemplateVersionsUsingCachedModuleFileInOrg ( ctx context . Context , arg HasTemplateVersionsUsingCachedModuleFileInOrgParams ) ( bool , error )
2026-06-15 14:41:00 -07:00
// Stamps the pinned hash and error on every not-yet-hydrated chat for
2026-06-17 00:10:07 -07:00
// an agent (context_aggregate_hash IS NULL) and copies the agent's
// current context resources onto those chats in the same statement, so
// a chat's pinned hash and pinned bodies are always written together.
// Runs as a side effect of an agent push and of chat-create hydration,
// so chats created before the agent was ready pick up the snapshot
2026-07-18 21:52:02 +02:00
// without a dirty marker. The ON CONFLICT upsert is defensive: a
2026-06-17 00:10:07 -07:00
// not-yet-hydrated chat has no pinned rows, so it normally inserts.
// Does not bump chats.updated_at; the resource upsert's ON CONFLICT branch
// sets chat_context_resources.updated_at on the rows it rewrites.
2026-07-18 21:52:02 +02:00
// Returns the hydrated chat IDs so callers can notify watchers of every
// chat the statement pinned.
HydrateAgentChatsContext ( ctx context . Context , arg HydrateAgentChatsContextParams ) ([] uuid . UUID , error )
2026-06-12 13:33:12 +02:00
// Increments generation_attempt and returns the resulting value.
IncrementChatGenerationAttempt ( ctx context . Context , id uuid . UUID ) ( int64 , error )
2026-07-02 16:29:25 +01:00
// Adds cost_micros to the spend for (user_id, effective_group_id, day).
// The day parameter is normalized to its UTC calendar day before storage.
IncrementUserAIDailySpend ( ctx context . Context , arg IncrementUserAIDailySpendParams ) ( AIUserDailySpend , error )
2025-09-16 21:31:17 +02:00
InsertAIBridgeInterception ( ctx context . Context , arg InsertAIBridgeInterceptionParams ) ( AIBridgeInterception , error )
2026-03-17 13:41:10 +02:00
InsertAIBridgeModelThought ( ctx context . Context , arg InsertAIBridgeModelThoughtParams ) ( AIBridgeModelThought , error )
2025-09-26 16:20:33 +02:00
InsertAIBridgeTokenUsage ( ctx context . Context , arg InsertAIBridgeTokenUsageParams ) ( AIBridgeTokenUsage , error )
InsertAIBridgeToolUsage ( ctx context . Context , arg InsertAIBridgeToolUsageParams ) ( AIBridgeToolUsage , error )
InsertAIBridgeUserPrompt ( ctx context . Context , arg InsertAIBridgeUserPromptParams ) ( AIBridgeUserPrompt , error )
2026-06-02 13:25:44 +02:00
InsertAIGatewayKey ( ctx context . Context , arg InsertAIGatewayKeyParams ) ( InsertAIGatewayKeyRow , error )
2026-05-14 16:10:46 +02:00
InsertAIProvider ( ctx context . Context , arg InsertAIProviderParams ) ( AIProvider , error )
InsertAIProviderKey ( ctx context . Context , arg InsertAIProviderKeyParams ) ( AIProviderKey , error )
2022-01-20 07:46:51 -06:00
InsertAPIKey ( ctx context . Context , arg InsertAPIKeyParams ) ( APIKey , error )
2026-06-17 00:10:07 -07:00
// Copies an agent's current context resources onto a single chat. Pair
// with DeleteChatContextResourcesByChatID (clear-then-copy, in a
// transaction) to re-pin a chat to its agent's latest snapshot from the
// refresh endpoint and on agent rebinding.
InsertAgentContextResourcesIntoChat ( ctx context . Context , arg InsertAgentContextResourcesIntoChatParams ) error
2022-10-10 15:37:06 -05:00
// We use the organization_id as the id
// for simplicity since all users is
// every member of the org.
InsertAllUsersGroup ( ctx context . Context , organizationID uuid . UUID ) ( Group , error )
2022-05-02 14:30:46 -05:00
InsertAuditLog ( ctx context . Context , arg InsertAuditLogParams ) ( AuditLog , error )
2026-05-29 12:50:39 +02:00
InsertBoundaryLogs ( ctx context . Context , arg InsertBoundaryLogsParams ) ([] BoundaryLog , error )
2026-05-25 11:14:36 +02:00
InsertBoundarySession ( ctx context . Context , arg InsertBoundarySessionParams ) ( BoundarySession , error )
2026-02-27 11:50:56 -05:00
InsertChat ( ctx context . Context , arg InsertChatParams ) ( Chat , error )
2026-05-05 22:37:13 +02:00
// updated_at is the retention clock used by DeleteOldChatDebugRuns.
// Set it on every write to keep retention semantics correct.
2026-04-13 15:06:06 +02:00
InsertChatDebugRun ( ctx context . Context , arg InsertChatDebugRunParams ) ( ChatDebugRun , error )
2026-04-17 16:27:53 +02:00
// The CTE atomically locks the parent run via UPDATE, bumps its
// updated_at (eliminating a separate TouchChatDebugRunUpdatedAt
// call), and enforces the finalization guard: if the run is already
// finished, the UPDATE returns zero rows, the INSERT gets no source
// rows, and sql.ErrNoRows is returned. The UPDATE also serializes
// with concurrent FinalizeStale under READ COMMITTED isolation.
2026-04-13 15:06:06 +02:00
InsertChatDebugStep ( ctx context . Context , arg InsertChatDebugStepParams ) ( ChatDebugStep , error )
2026-03-06 21:05:26 +02:00
InsertChatFile ( ctx context . Context , arg InsertChatFileParams ) ( InsertChatFileRow , error )
2026-07-29 09:17:42 +02:00
// Returns the inserted rows in input array order. Ids are allocated before the
// insert and the k-th smallest is assigned to input index k, so callers may
// index the result positionally.
InsertChatMessages ( ctx context . Context , arg InsertChatMessagesParams ) ([] InsertChatMessagesRow , error )
2026-02-27 11:50:56 -05:00
InsertChatModelConfig ( ctx context . Context , arg InsertChatModelConfigParams ) ( ChatModelConfig , error )
2026-06-12 13:33:12 +02:00
// Legacy queue insertion path. When no caller-supplied creator exists,
// preserve the created_by invariant by attributing the queued row to the
// chat owner.
2026-02-27 11:50:56 -05:00
InsertChatQueuedMessage ( ctx context . Context , arg InsertChatQueuedMessageParams ) ( ChatQueuedMessage , error )
2026-06-12 13:33:12 +02:00
// Inserts a queued message that carries a position (from the default
// sequence) and an explicit created_by reference. Use this when the
// queued-message creator differs from the chat owner.
InsertChatQueuedMessageWithCreator ( ctx context . Context , arg InsertChatQueuedMessageWithCreatorParams ) ( ChatQueuedMessage , error )
2024-09-17 18:08:18 +01:00
InsertCryptoKey ( ctx context . Context , arg InsertCryptoKeyParams ) ( CryptoKey , error )
2024-08-13 12:53:47 -05:00
InsertCustomRole ( ctx context . Context , arg InsertCustomRoleParams ) ( CustomRole , error )
2023-09-06 12:06:26 +01:00
InsertDBCryptKey ( ctx context . Context , arg InsertDBCryptKeyParams ) error
2022-10-17 08:43:30 -05:00
InsertDERPMeshKey ( ctx context . Context , value string ) error
2022-06-17 00:26:40 -05:00
InsertDeploymentID ( ctx context . Context , value string ) error
2023-09-29 14:13:20 -05:00
InsertExternalAuthLink ( ctx context . Context , arg InsertExternalAuthLinkParams ) ( ExternalAuthLink , error )
2022-02-07 15:32:37 -06:00
InsertFile ( ctx context . Context , arg InsertFileParams ) ( File , error )
2022-04-05 19:18:26 -05:00
InsertGitSSHKey ( ctx context . Context , arg InsertGitSSHKeyParams ) ( GitSSHKey , error )
2022-10-10 15:37:06 -05:00
InsertGroup ( ctx context . Context , arg InsertGroupParams ) ( Group , error )
InsertGroupMember ( ctx context . Context , arg InsertGroupMemberParams ) error
2025-03-03 10:12:48 +01:00
InsertInboxNotification ( ctx context . Context , arg InsertInboxNotificationParams ) ( InboxNotification , error )
2022-08-22 15:02:50 -07:00
InsertLicense ( ctx context . Context , arg InsertLicenseParams ) ( License , error )
2026-03-19 10:07:36 -04:00
InsertMCPServerConfig ( ctx context . Context , arg InsertMCPServerConfigParams ) ( MCPServerConfig , error )
2025-02-04 18:45:33 +01:00
InsertMemoryResourceMonitor ( ctx context . Context , arg InsertMemoryResourceMonitorParams ) ( WorkspaceAgentMemoryResourceMonitor , error )
2023-08-08 11:37:49 -05:00
// Inserts any group by name that does not exist. All new groups are given
// a random uuid, are inserted into the same organization. They have the default
// values for avatar, display name, and quota allowance (all zero values).
// If the name conflicts, do nothing.
InsertMissingGroups ( ctx context . Context , arg InsertMissingGroupsParams ) ([] Group , error )
2023-12-21 12:38:42 -09:00
InsertOAuth2ProviderApp ( ctx context . Context , arg InsertOAuth2ProviderAppParams ) ( OAuth2ProviderApp , error )
2024-02-20 15:58:43 -08:00
InsertOAuth2ProviderAppCode ( ctx context . Context , arg InsertOAuth2ProviderAppCodeParams ) ( OAuth2ProviderAppCode , error )
2023-12-21 12:38:42 -09:00
InsertOAuth2ProviderAppSecret ( ctx context . Context , arg InsertOAuth2ProviderAppSecretParams ) ( OAuth2ProviderAppSecret , error )
2024-02-20 15:58:43 -08:00
InsertOAuth2ProviderAppToken ( ctx context . Context , arg InsertOAuth2ProviderAppTokenParams ) ( OAuth2ProviderAppToken , error )
2022-01-22 23:58:10 -06:00
InsertOrganization ( ctx context . Context , arg InsertOrganizationParams ) ( Organization , error )
InsertOrganizationMember ( ctx context . Context , arg InsertOrganizationMemberParams ) ( OrganizationMember , error )
2025-02-11 13:55:09 +02:00
InsertPreset ( ctx context . Context , arg InsertPresetParams ) ( TemplateVersionPreset , error )
InsertPresetParameters ( ctx context . Context , arg InsertPresetParametersParams ) ([] TemplateVersionPresetParameter , error )
2025-06-19 11:08:48 -04:00
InsertPresetPrebuildSchedule ( ctx context . Context , arg InsertPresetPrebuildScheduleParams ) ( TemplateVersionPresetPrebuildSchedule , error )
2022-01-29 17:38:32 -06:00
InsertProvisionerJob ( ctx context . Context , arg InsertProvisionerJobParams ) ( ProvisionerJob , error )
2022-02-07 15:32:37 -06:00
InsertProvisionerJobLogs ( ctx context . Context , arg InsertProvisionerJobLogsParams ) ([] ProvisionerJobLog , error )
2024-08-21 14:18:58 +02:00
InsertProvisionerJobTimings ( ctx context . Context , arg InsertProvisionerJobTimingsParams ) ([] ProvisionerJobTiming , error )
2024-07-16 13:27:12 -04:00
InsertProvisionerKey ( ctx context . Context , arg InsertProvisionerKeyParams ) ( ProvisionerKey , error )
2022-10-17 08:43:30 -05:00
InsertReplica ( ctx context . Context , arg InsertReplicaParams ) ( Replica , error )
2025-10-13 12:25:58 +03:00
InsertTask ( ctx context . Context , arg InsertTaskParams ) ( TaskTable , error )
2025-01-31 13:55:46 +01:00
InsertTelemetryItemIfNotExists ( ctx context . Context , arg InsertTelemetryItemIfNotExistsParams ) error
2025-10-28 03:16:41 +11:00
// Inserts a new lock row into the telemetry_locks table. Replicas should call
// this function prior to attempting to generate or publish a heartbeat event to
// the telemetry service.
// If the query returns a duplicate primary key error, the replica should not
// attempt to generate or publish the event to the telemetry service.
InsertTelemetryLock ( ctx context . Context , arg InsertTelemetryLockParams ) error
2023-07-19 16:07:33 -04:00
InsertTemplate ( ctx context . Context , arg InsertTemplateParams ) error
2023-07-25 09:14:38 -04:00
InsertTemplateVersion ( ctx context . Context , arg InsertTemplateVersionParams ) error
2023-01-17 11:22:11 +01:00
InsertTemplateVersionParameter ( ctx context . Context , arg InsertTemplateVersionParameterParams ) ( TemplateVersionParameter , error )
2025-03-24 10:01:50 -06:00
InsertTemplateVersionTerraformValuesByJobID ( ctx context . Context , arg InsertTemplateVersionTerraformValuesByJobIDParams ) error
2023-02-15 18:24:15 +01:00
InsertTemplateVersionVariable ( ctx context . Context , arg InsertTemplateVersionVariableParams ) ( TemplateVersionVariable , error )
2024-05-20 15:30:19 +02:00
InsertTemplateVersionWorkspaceTag ( ctx context . Context , arg InsertTemplateVersionWorkspaceTagParams ) ( TemplateVersionWorkspaceTag , error )
2025-08-16 01:31:00 +10:00
// Duplicate events are ignored intentionally to allow for multiple replicas to
// publish heartbeat events.
InsertUsageEvent ( ctx context . Context , arg InsertUsageEventParams ) error
2022-01-20 07:46:51 -06:00
InsertUser ( ctx context . Context , arg InsertUserParams ) ( User , error )
2024-09-11 13:43:50 -05:00
// InsertUserGroupsByID adds a user to all provided groups, if they exist.
// If there is a conflict, the user is already a member
InsertUserGroupsByID ( ctx context . Context , arg InsertUserGroupsByIDParams ) ([] uuid . UUID , error )
2022-08-17 18:00:53 -05:00
InsertUserLink ( ctx context . Context , arg InsertUserLinkParams ) ( UserLink , error )
2026-05-20 00:09:09 +02:00
InsertUserSkill ( ctx context . Context , arg InsertUserSkillParams ) ( UserSkill , error )
2025-02-04 18:45:33 +01:00
InsertVolumeResourceMonitor ( ctx context . Context , arg InsertVolumeResourceMonitorParams ) ( WorkspaceAgentVolumeResourceMonitor , error )
2026-04-26 14:49:10 -07:00
// Inserts or updates a webpush subscription. The (user_id, endpoint) pair
// is unique; re-subscribing the same endpoint replaces the keys instead of
// inserting a duplicate row. This is the recovery path after a PWA reinstall
// on iOS, where the browser may keep the same endpoint with rotated keys.
2025-03-27 10:03:53 +00:00
InsertWebpushSubscription ( ctx context . Context , arg InsertWebpushSubscriptionParams ) ( WebpushSubscription , error )
2024-10-22 09:20:54 -05:00
InsertWorkspace ( ctx context . Context , arg InsertWorkspaceParams ) ( WorkspaceTable , error )
2022-03-07 11:40:54 -06:00
InsertWorkspaceAgent ( ctx context . Context , arg InsertWorkspaceAgentParams ) ( WorkspaceAgent , error )
2025-03-20 19:09:39 +02:00
InsertWorkspaceAgentDevcontainers ( ctx context . Context , arg InsertWorkspaceAgentDevcontainersParams ) ([] WorkspaceAgentDevcontainer , error )
2023-09-25 16:47:17 -05:00
InsertWorkspaceAgentLogSources ( ctx context . Context , arg InsertWorkspaceAgentLogSourcesParams ) ([] WorkspaceAgentLogSource , error )
2023-07-28 09:57:23 -06:00
InsertWorkspaceAgentLogs ( ctx context . Context , arg InsertWorkspaceAgentLogsParams ) ([] WorkspaceAgentLog , error )
2023-03-31 15:26:19 -05:00
InsertWorkspaceAgentMetadata ( ctx context . Context , arg InsertWorkspaceAgentMetadataParams ) error
2024-10-14 09:31:03 -03:00
InsertWorkspaceAgentScriptTimings ( ctx context . Context , arg InsertWorkspaceAgentScriptTimingsParams ) ( WorkspaceAgentScriptTiming , error )
2023-09-25 16:47:17 -05:00
InsertWorkspaceAgentScripts ( ctx context . Context , arg InsertWorkspaceAgentScriptsParams ) ([] WorkspaceAgentScript , error )
2023-08-04 17:00:42 +01:00
InsertWorkspaceAgentStats ( ctx context . Context , arg InsertWorkspaceAgentStatsParams ) error
2023-08-16 15:22:00 +03:00
InsertWorkspaceAppStats ( ctx context . Context , arg InsertWorkspaceAppStatsParams ) error
2025-03-31 10:55:44 -04:00
InsertWorkspaceAppStatus ( ctx context . Context , arg InsertWorkspaceAppStatusParams ) ( WorkspaceAppStatus , error )
2023-07-25 09:14:38 -04:00
InsertWorkspaceBuild ( ctx context . Context , arg InsertWorkspaceBuildParams ) error
2026-07-07 09:18:30 -07:00
InsertWorkspaceBuildOrchestration ( ctx context . Context , arg InsertWorkspaceBuildOrchestrationParams ) ( WorkspaceBuildOrchestration , error )
2023-01-17 11:22:11 +01:00
InsertWorkspaceBuildParameters ( ctx context . Context , arg InsertWorkspaceBuildParametersParams ) error
2024-11-16 21:56:19 +01:00
InsertWorkspaceModule ( ctx context . Context , arg InsertWorkspaceModuleParams ) ( WorkspaceModule , error )
2023-04-04 15:07:29 -05:00
InsertWorkspaceProxy ( ctx context . Context , arg InsertWorkspaceProxyParams ) ( WorkspaceProxy , error )
2022-03-07 11:40:54 -06:00
InsertWorkspaceResource ( ctx context . Context , arg InsertWorkspaceResourceParams ) ( WorkspaceResource , error )
2022-12-14 13:08:22 -06:00
InsertWorkspaceResourceMetadata ( ctx context . Context , arg InsertWorkspaceResourceMetadataParams ) ([] WorkspaceResourceMetadatum , error )
2026-06-12 13:33:12 +02:00
// Returns true when there is no heartbeat row for (chat_id, runner_id)
// or the existing row is older than @stale_seconds seconds by database
// time. chatstate calls this in a single query so the staleness check
// is atomic and does not depend on the caller's local clock.
IsChatHeartbeatStale ( ctx context . Context , arg IsChatHeartbeatStaleParams ) ( bool , error )
2026-09-10 13:40:16 +10:00
// LinkChatFilesAfterLock requires the chat row lock. When the batch would
// exceed the cap, the oldest files on the chat are deleted to make room; the
// cascade removes their links. A file links to at most one chat, so no other
// chat can lose a file here. The batch is rejected only when the batch itself
// exceeds the cap.
2026-08-11 13:53:15 +02:00
LinkChatFilesAfterLock ( ctx context . Context , arg LinkChatFilesAfterLockParams ) ( int32 , error )
2026-03-28 08:18:28 +11:00
ListAIBridgeClients ( ctx context . Context , arg ListAIBridgeClientsParams ) ([] string , error )
2025-11-24 18:09:04 +05:00
// Finds all unique AI Bridge interception telemetry summaries combinations
2025-10-28 03:16:41 +11:00
// (provider, model, client) in the given timeframe for telemetry reporting.
ListAIBridgeInterceptionsTelemetrySummaries ( ctx context . Context , arg ListAIBridgeInterceptionsTelemetrySummariesParams ) ([] ListAIBridgeInterceptionsTelemetrySummariesRow , error )
2026-03-26 18:09:53 +02:00
ListAIBridgeModelThoughtsByInterceptionIDs ( ctx context . Context , interceptionIds [] uuid . UUID ) ([] AIBridgeModelThought , error )
2026-02-26 02:40:45 +11:00
ListAIBridgeModels ( ctx context . Context , arg ListAIBridgeModelsParams ) ([] string , error )
2026-08-03 11:34:27 +02:00
// Returns the individual Agent Firewall network calls made during an AI
// session, ordered chronologically. All protocols are included, unlike
// GetAIBridgeSessionTopDomains which considers only HTTP egress, so the list
// covers the same events the network_calls summary in ListAIBridgeSessions
// counts. The list is capped at @limit_ rows, so its length equals the summary
// total only for sessions at or below the cap. The summary stays authoritative
// for whole-session totals.
//
// Windowing mirrors that summary and GetAIBridgeSessionTopDomains: each
// interception's boundary logs fall in the open interval (this seq, next
// interception's seq) within the same firewall session. The exclusive lower
// bound drops the interception's own LLM-provider call. next_seq considers all
// interceptions in the firewall session so windows never bleed across AI
// sessions that share one firewall session, and falls back to the maximum
// sequence_number for the last interception so the window stays an
// index-satisfiable range.
// created_at leads because a session can span several firewall sessions, whose
// sequence numbers are independent streams. id breaks remaining ties so the row
// that lands on the limit boundary is stable across identical requests.
ListAIBridgeSessionNetworkCalls ( ctx context . Context , arg ListAIBridgeSessionNetworkCallsParams ) ([] BoundaryLog , error )
2026-03-26 18:09:53 +02:00
// Returns all interceptions belonging to paginated threads within a session.
// Threads are paginated by (started_at, thread_id) cursor.
ListAIBridgeSessionThreads ( ctx context . Context , arg ListAIBridgeSessionThreadsParams ) ([] ListAIBridgeSessionThreadsRow , error )
2026-03-24 08:58:47 +02:00
// Returns paginated sessions with aggregated metadata, token counts, and
// the most recent user prompt. A "session" is a logical grouping of
// interceptions that share the same session_id (set by the client).
2026-03-31 14:42:23 +02:00
//
// Pagination-first strategy: identify the page of sessions cheaply via a
// single GROUP BY scan, then do expensive lateral joins (tokens, prompts,
// first-interception metadata) only for the ~page-size result set.
2026-07-30 13:09:46 +02:00
// The last interception in a session has no next row, so next_seq uses
// the largest sequence_number instead of NULL. The lookup stays a plain
// range, so the (session_id, sequence_number) index answers it alone.
// With NULL and an OR check, the index cannot bound the range: each
// interception reads every log to the end of the session and throws
// most of them away.
2026-03-24 08:58:47 +02:00
ListAIBridgeSessions ( ctx context . Context , arg ListAIBridgeSessionsParams ) ([] ListAIBridgeSessionsRow , error )
2025-09-26 16:20:33 +02:00
ListAIBridgeTokenUsagesByInterceptionIDs ( ctx context . Context , interceptionIds [] uuid . UUID ) ([] AIBridgeTokenUsage , error )
ListAIBridgeToolUsagesByInterceptionIDs ( ctx context . Context , interceptionIds [] uuid . UUID ) ([] AIBridgeToolUsage , error )
ListAIBridgeUserPromptsByInterceptionIDs ( ctx context . Context , interceptionIds [] uuid . UUID ) ([] AIBridgeUserPrompt , error )
2026-06-02 13:25:44 +02:00
ListAIGatewayKeys ( ctx context . Context ) ([] ListAIGatewayKeysRow , error )
2026-05-25 11:14:36 +02:00
// Lists boundary logs for a session, sorted by sequence number ascending.
2026-06-22 13:56:29 +02:00
// Supports an inclusive lower bound (seq_after) and an exclusive upper bound
// (seq_before) for fetching events between two known interceptions.
2026-05-25 11:14:36 +02:00
ListBoundaryLogsBySessionID ( ctx context . Context , arg ListBoundaryLogsBySessionIDParams ) ([] BoundaryLog , error )
2026-06-17 00:10:07 -07:00
// Lists a chat's pinned context resources, ordered deterministically by
// source.
ListChatContextResourcesByChatID ( ctx context . Context , chatID uuid . UUID ) ([] ChatContextResource , error )
2024-07-16 13:27:12 -04:00
ListProvisionerKeysByOrganization ( ctx context . Context , organizationID uuid . UUID ) ([] ProvisionerKey , error )
2024-09-16 16:02:08 -04:00
ListProvisionerKeysByOrganizationExcludeReserved ( ctx context . Context , organizationID uuid . UUID ) ([] ProvisionerKey , error )
2025-10-14 17:33:30 +01:00
ListTasks ( ctx context . Context , arg ListTasksParams ) ([] Task , error )
2026-07-30 15:37:45 +08:00
// Used by the usage generator to find missing heartbeat buckets.
ListUsageEventCreatedAtsByTypeSince ( ctx context . Context , arg ListUsageEventCreatedAtsByTypeSinceParams ) ([] time . Time , error )
2026-03-24 00:48:18 +01:00
ListUserChatCompactionThresholds ( ctx context . Context , userID uuid . UUID ) ([] UserConfig , error )
2026-04-07 09:03:28 -06:00
// Returns metadata only (no value or value_key_id) for the
// REST API list and get endpoints.
ListUserSecrets ( ctx context . Context , userID uuid . UUID ) ([] ListUserSecretsRow , error )
// Returns all columns including the secret value. Used by the
// provisioner (build-time injection) and the agent manifest
// (runtime injection).
ListUserSecretsWithValues ( ctx context . Context , userID uuid . UUID ) ([] UserSecret , error )
2026-05-20 00:09:09 +02:00
ListUserSkillMetadataByUserID ( ctx context . Context , userID uuid . UUID ) ([] ListUserSkillMetadataByUserIDRow , error )
2026-06-15 09:38:52 -07:00
ListWorkspaceAgentContextResources ( ctx context . Context , workspaceAgentID uuid . UUID ) ([] WorkspaceAgentContextResource , error )
2024-02-13 09:31:20 -05:00
ListWorkspaceAgentPortShares ( ctx context . Context , workspaceID uuid . UUID ) ([] WorkspaceAgentPortShare , error )
2026-06-12 13:33:12 +02:00
// Locks the chat row with FOR UPDATE and atomically increments its
// snapshot_version, returning the post-bump chat. This is the single
// entry point ChatMachine.Update uses to acquire the row lock and
// allocate a new snapshot version in one round trip.
LockChatAndBumpSnapshotVersion ( ctx context . Context , id uuid . UUID ) ( Chat , error )
2026-08-11 13:53:15 +02:00
LockChatByID ( ctx context . Context , id uuid . UUID ) ( uuid . UUID , error )
2026-08-11 11:04:51 -05:00
// Locks the provisioner key row with FOR KEY SHARE for the remainder of the
// current transaction. FOR KEY SHARE conflicts with DELETE, so while the lock
// is held the key cannot be deleted, and a committed deletion is observed as
// no rows by later calls.
LockProvisionerKeyByIDForShare ( ctx context . Context , id uuid . UUID ) ( uuid . UUID , error )
2025-03-20 13:41:54 +01:00
MarkAllInboxNotificationsAsRead ( ctx context . Context , arg MarkAllInboxNotificationsAsReadParams ) error
2026-06-15 14:41:00 -07:00
// Flips active, already-hydrated chats for an agent to dirty when the
// agent's latest snapshot hash differs from the chat's pinned hash. The
// pinned hash is intentionally left untouched; the refresh endpoint
// re-pins it. Returns the chats that transitioned so the caller can
// emit watch events after the transaction commits.
MarkChatsContextDirtyByAgent ( ctx context . Context , arg MarkChatsContextDirtyByAgentParams ) ([] MarkChatsContextDirtyByAgentRow , error )
2026-07-16 13:43:05 +02:00
// Records a permanent refresh failure (e.g. revoked grant) and clears
// the dead token material so it is never attached to a request again.
// The updated_at predicate provides optimistic concurrency: if another
// request refreshed or replaced the token since it was read, this
// update matches zero rows and returns sql.ErrNoRows.
MarkMCPServerUserTokenRefreshFailure ( ctx context . Context , arg MarkMCPServerUserTokenRefreshFailureParams ) ( MCPServerUserToken , error )
2024-11-21 13:04:00 -06:00
OIDCClaimFieldValues ( ctx context . Context , arg OIDCClaimFieldValuesParams ) ([] string , error )
2024-11-18 14:31:39 -06:00
// OIDCClaimFields returns a list of distinct keys in the the merged_claims fields.
// This query is used to generate the list of available sync fields for idp sync settings.
OIDCClaimFields ( ctx context . Context , organizationID uuid . UUID ) ([] string , error )
2024-06-12 09:23:48 -10:00
// Arguments are optional with uuid.Nil to ignore.
// - Use just 'organization_id' to get all members of an org
// - Use just 'user_id' to get all orgs a user is a member of
// - Use both to get a specific org member row
OrganizationMembers ( ctx context . Context , arg OrganizationMembersParams ) ([] OrganizationMembersRow , error )
2025-03-10 14:42:07 -04:00
PaginatedOrganizationMembers ( ctx context . Context , arg PaginatedOrganizationMembersParams ) ([] PaginatedOrganizationMembersRow , error )
2026-03-26 16:52:02 -04:00
// Under READ COMMITTED, concurrent pin operations for the same
// owner may momentarily produce duplicate pin_order values because
// each CTE snapshot does not see the other's writes. The next
// pin/unpin/reorder operation's ROW_NUMBER() self-heals the
// sequence, so this is acceptable.
PinChatByID ( ctx context . Context , id uuid . UUID ) error
2026-02-27 11:50:56 -05:00
PopNextQueuedMessage ( ctx context . Context , chatID uuid . UUID ) ( ChatQueuedMessage , error )
2024-03-05 13:47:01 -05:00
ReduceWorkspaceAgentShareLevelToAuthenticatedByTemplate ( ctx context . Context , templateID uuid . UUID ) error
2023-04-20 09:48:47 -05:00
RegisterWorkspaceProxy ( ctx context . Context , arg RegisterWorkspaceProxyParams ) ( WorkspaceProxy , error )
2026-08-25 09:08:52 -04:00
ReindexStaleChatMessagesSearchTsv ( ctx context . Context , batchSize int32 ) ( int64 , error )
2026-08-19 14:00:31 -07:00
// The lease is only removed if it is the current lease.
ReleaseExternalAuthLinkRefreshLease ( ctx context . Context , arg ReleaseExternalAuthLinkRefreshLeaseParams ) error
2024-09-11 13:43:50 -05:00
RemoveUserFromGroups ( ctx context . Context , arg RemoveUserFromGroupsParams ) ([] uuid . UUID , error )
2026-05-06 19:11:56 +03:00
// Mutates only created_at on the target row; ids are unchanged so
// consumers can keep tracking queued messages by id.
ReorderChatQueuedMessageToFront ( ctx context . Context , arg ReorderChatQueuedMessageToFrontParams ) ( int64 , error )
2026-06-12 13:33:12 +02:00
// Sets the target queued message's position to one less than the
// current minimum position for that chat, moving it to the head.
ReorderChatQueuedMessageToHead ( ctx context . Context , arg ReorderChatQueuedMessageToHeadParams ) ( int64 , error )
2023-09-06 12:06:26 +01:00
RevokeDBCryptKey ( ctx context . Context , activeKeyDigest string ) error
2025-08-16 01:31:00 +10:00
// Note that this selects from the CTE, not the original table. The CTE is named
// the same as the original table to trick sqlc into reusing the existing struct
// for the table.
// The CTE and the reorder is required because UPDATE doesn't guarantee order.
SelectUsageEventsForPublishing ( ctx context . Context , now time . Time ) ([] UsageEvent , error )
2026-06-15 14:41:00 -07:00
// Pins a single chat to the supplied context snapshot hash and error
// and clears any dirty marker. Used by chat-create hydration and the
// refresh endpoint. Does not bump updated_at: context pinning is
// background state and must not reorder chat lists.
SetChatContextSnapshot ( ctx context . Context , arg SetChatContextSnapshotParams ) error
2026-03-18 14:37:09 -04:00
SoftDeleteChatMessageByID ( ctx context . Context , id int64 ) error
SoftDeleteChatMessagesAfterID ( ctx context . Context , arg SoftDeleteChatMessagesAfterIDParams ) error
2026-04-09 10:33:00 -04:00
SoftDeleteContextFileMessages ( ctx context . Context , chatID uuid . UUID ) error
2026-05-18 08:33:29 -04:00
// Marks agents from all prior builds of this workspace as deleted,
// preserving only agents belonging to @current_build_id. Called from
// provisionerdserver when a workspace build completes, after the new
// build's agents have been inserted, so running agents are not
// deleted while a build is still queued or provisioning.
2026-06-15 09:38:52 -07:00
//
// Agent context rows (workspace_agent_context_snapshots and
// workspace_agent_context_resources) only describe live agents, and
// agents are never un-deleted, so they are hard-deleted here instead
// of accumulating alongside the soft-deleted agent rows.
2026-05-18 08:33:29 -04:00
SoftDeletePriorWorkspaceAgents ( ctx context . Context , arg SoftDeletePriorWorkspaceAgentsParams ) error
// Marks every non-deleted agent belonging to the given workspace as
// deleted. Called alongside UpdateWorkspaceDeletedByID when a workspace
// itself is soft-deleted, so the agent instance-identity auth path
// (which filters on workspace_agents.deleted) doesn't keep seeing
// orphaned rows.
2026-06-15 09:38:52 -07:00
//
// Agent context rows are hard-deleted for the same reason as in
// SoftDeletePriorWorkspaceAgents.
2026-05-18 08:33:29 -04:00
SoftDeleteWorkspaceAgentsByWorkspaceID ( ctx context . Context , workspaceID uuid . UUID ) error
2026-09-02 13:38:14 +02:00
// MCP resources bypass context drift and are live-synced on each push.
// Changed chats are locked in ID order so concurrent clear-then-copy re-pins
// cannot interleave with the replacement.
SyncAgentChatsContextMCPResources ( ctx context . Context , agentID uuid . UUID ) ([] uuid . UUID , error )
2026-04-17 16:27:53 +02:00
// Overrides updated_at on the parent run without touching any
// other column. Used by tests that need to stamp a run with a
// specific timestamp after the InsertChatDebugStep CTE has
// already bumped it to NOW(), so stale-row finalization paths
// can be exercised deterministically. The chatdebug service
// itself does not call this: heartbeats go through
// TouchChatDebugStepAndRun, and step creation updates the parent
// run via the InsertChatDebugStep CTE.
TouchChatDebugRunUpdatedAt ( ctx context . Context , arg TouchChatDebugRunUpdatedAtParams ) error
// Atomically bumps updated_at on both the step and its parent run
// in a single statement. This prevents FinalizeStale from
// interleaving between the two touches and finalizing a run whose
// step heartbeat was just written.
//
// The step UPDATE joins through touched_run (via FROM) and reads
// its RETURNING rows. Per the PostgreSQL WITH semantics, RETURNING
// is the only way to communicate values between a data-modifying
// CTE and the main query, and consuming those rows forces the run
// UPDATE to complete before the step UPDATE. That matches the
// lock order used by FinalizeStaleChatDebugRows and avoids a
// deadlock between concurrent heartbeats and stale sweeps. The
// join also constrains the step update to the specified run so a
// mismatched (run_id, step_id) pair cannot silently refresh an
// unrelated step.
TouchChatDebugStepAndRun ( ctx context . Context , arg TouchChatDebugStepAndRunParams ) error
2023-03-08 06:38:11 +11:00
// Non blocking lock. Returns true if the lock was acquired, false otherwise.
//
// This must be called from within a transaction. The lock will be automatically
// released when the transaction ends.
TryAcquireLock ( ctx context . Context , pgTryAdvisoryXactLock int64 ) ( bool , error )
2026-04-01 15:30:25 +11:00
UnarchiveChatByID ( ctx context . Context , id uuid . UUID ) ([] Chat , error )
2023-10-10 10:52:42 -05:00
// This will always work regardless of the current state of the template version.
UnarchiveTemplateVersion ( ctx context . Context , arg UnarchiveTemplateVersionParams ) error
2024-01-24 13:39:19 +00:00
UnfavoriteWorkspace ( ctx context . Context , id uuid . UUID ) error
2026-06-16 12:46:10 -07:00
// Resets linked_id to '' for OIDC links where the linked_id is non-empty
// and does not begin with the expected issuer prefix. This allows users to
// re-authenticate under a new OIDC provider.
UnlinkOIDCUsersByIssuerMismatch ( ctx context . Context , expectedPrefix string ) ( int64 , error )
2026-03-26 16:52:02 -04:00
UnpinChatByID ( ctx context . Context , id uuid . UUID ) error
2026-08-24 10:30:01 +01:00
UnsetDefaultChatModelConfigs ( ctx context . Context , organizationID uuid . UUID ) error
2025-10-27 09:51:37 +01:00
UpdateAIBridgeInterceptionEnded ( ctx context . Context , arg UpdateAIBridgeInterceptionEndedParams ) ( AIBridgeInterception , error )
2026-06-26 18:45:37 +02:00
// Records heartbeat liveness for an active Gateway DRPC session. The database sets the
2026-06-26 18:16:01 +02:00
// timestamp so it stays consistent regardless of clock drift between API
// replicas.
2026-06-26 18:45:37 +02:00
UpdateAIGatewayKeyLastHeartbeatAt ( ctx context . Context , id uuid . UUID ) ( int64 , error )
2026-05-14 16:10:46 +02:00
UpdateAIProvider ( ctx context . Context , arg UpdateAIProviderParams ) ( AIProvider , error )
2022-01-20 07:46:51 -06:00
UpdateAPIKeyByID ( ctx context . Context , arg UpdateAPIKeyByIDParams ) error
2026-05-18 22:32:05 +01:00
UpdateChatACLByID ( ctx context . Context , arg UpdateChatACLByIDParams ) error
2026-03-26 17:22:38 +11:00
UpdateChatBuildAgentBinding ( ctx context . Context , arg UpdateChatBuildAgentBindingParams ) ( Chat , error )
2026-02-27 11:50:56 -05:00
UpdateChatByID ( ctx context . Context , arg UpdateChatByIDParams ) ( Chat , error )
2026-04-13 15:06:06 +02:00
// Uses COALESCE so that passing NULL from Go means "keep the
2026-04-17 16:27:53 +02:00
// existing value." This is intentional: debug rows follow a
2026-04-13 15:06:06 +02:00
// write-once-finalize pattern where fields are set at creation
2026-04-17 16:27:53 +02:00
// or finalization and never cleared back to NULL. The @now
// parameter keeps updated_at under the caller's clock.
2026-05-05 22:37:13 +02:00
// updated_at is also the retention clock used by DeleteOldChatDebugRuns.
2026-04-17 16:27:53 +02:00
//
// finished_at is enforced as write-once at the SQL level: once
// populated it cannot be overwritten by a later call. Callers
// that issue a summary or status refresh after the run has
// already finalized therefore cannot corrupt the original
// completion timestamp, which keeps duration and ordering
// calculations stable regardless of how many times the row is
// updated.
2026-04-13 15:06:06 +02:00
UpdateChatDebugRun ( ctx context . Context , arg UpdateChatDebugRunParams ) ( ChatDebugRun , error )
// Uses COALESCE so that passing NULL from Go means "keep the
2026-04-17 16:27:53 +02:00
// existing value." This is intentional: debug rows follow a
2026-04-13 15:06:06 +02:00
// write-once-finalize pattern where fields are set at creation
2026-04-17 16:27:53 +02:00
// or finalization and never cleared back to NULL. The @now
// parameter keeps updated_at under the caller's clock, matching
// the injectable quartz.Clock used by FinalizeStale sweeps.
2026-04-13 15:06:06 +02:00
UpdateChatDebugStep ( ctx context . Context , arg UpdateChatDebugStepParams ) ( ChatDebugStep , error )
2026-06-12 13:33:12 +02:00
// Atomically updates the execution-state-managed fields on a chat:
2026-07-21 10:58:08 +02:00
// status, archived, last_error, ownership identifiers, the
// requires-action deadline, and the manual compaction request marker.
// Callers compose this with transition mutations inside a single
// ChatMachine.Update transaction.
2026-08-12 20:38:57 +02:00
//
// grant_history_epoch gives a turn that inserts no history the same
// fresh retry budget and message part episode keys a history change
// would grant, mirroring the chat_messages trigger postcondition.
2026-06-12 13:33:12 +02:00
UpdateChatExecutionState ( ctx context . Context , arg UpdateChatExecutionStateParams ) ( Chat , error )
2026-04-07 10:25:46 -04:00
// Bumps the heartbeat timestamp for the given set of chat IDs,
// provided they are still running and owned by the specified
// worker. Returns the IDs that were actually updated so the
// caller can detect stolen or completed chats via set-difference.
UpdateChatHeartbeats ( ctx context . Context , arg UpdateChatHeartbeatsParams ) ([] uuid . UUID , error )
2026-03-25 13:26:26 -04:00
UpdateChatLabelsByID ( ctx context . Context , arg UpdateChatLabelsByIDParams ) ( Chat , error )
2026-03-27 01:47:19 +01:00
UpdateChatLastModelConfigByID ( ctx context . Context , arg UpdateChatLastModelConfigByIDParams ) ( Chat , error )
2026-03-27 12:15:04 -04:00
// Updates the last read message ID for a chat. This is used to track
// which messages the owner has seen, enabling unread indicators.
UpdateChatLastReadMessageID ( ctx context . Context , arg UpdateChatLastReadMessageIDParams ) error
2026-05-06 16:43:35 +02:00
// Updates the cached last completed turn summary for sidebar display.
// Empty or whitespace-only summaries are stored as NULL here so direct
// query callers cannot accidentally persist blank sidebar text.
2026-06-12 13:33:12 +02:00
// This intentionally preserves updated_at. The staleness guard uses
// history_version so worker lifecycle transitions that do not change the
// active message history cannot reject final turn summary writes.
2026-05-06 16:43:35 +02:00
// Two summary workers using the same freshness marker are last-write-wins.
UpdateChatLastTurnSummary ( ctx context . Context , arg UpdateChatLastTurnSummaryParams ) ( int64 , error )
2026-03-19 10:07:36 -04:00
UpdateChatMCPServerIDs ( ctx context . Context , arg UpdateChatMCPServerIDsParams ) ( Chat , error )
2026-02-27 11:50:56 -05:00
UpdateChatModelConfig ( ctx context . Context , arg UpdateChatModelConfigParams ) ( ChatModelConfig , error )
2026-08-24 10:43:45 +01:00
UpdateChatModelConfigACLByID ( ctx context . Context , arg UpdateChatModelConfigACLByIDParams ) ( ChatModelConfig , error )
2026-03-26 16:52:02 -04:00
UpdateChatPinOrder ( ctx context . Context , arg UpdateChatPinOrderParams ) error
2026-04-16 11:12:01 +02:00
UpdateChatPlanModeByID ( ctx context . Context , arg UpdateChatPlanModeByIDParams ) ( Chat , error )
2026-06-12 13:33:12 +02:00
// Stores the client-visible retry payload. retry_state_version is
// assigned by trigger from the current snapshot_version.
UpdateChatRetryState ( ctx context . Context , arg UpdateChatRetryStateParams ) ( Chat , error )
2026-02-27 11:50:56 -05:00
UpdateChatStatus ( ctx context . Context , arg UpdateChatStatusParams ) ( Chat , error )
2026-07-23 23:36:23 +08:00
// The history_version fence lets background summary writes ignore worker-only
// updates while losing to newer message history.
UpdateChatSummary ( ctx context . Context , arg UpdateChatSummaryParams ) ( int64 , error )
2026-04-20 20:00:46 +07:00
UpdateChatTitleByID ( ctx context . Context , arg UpdateChatTitleByIDParams ) ( Chat , error )
2026-03-26 17:22:38 +11:00
UpdateChatWorkspaceBinding ( ctx context . Context , arg UpdateChatWorkspaceBindingParams ) ( Chat , error )
2024-09-17 18:08:18 +01:00
UpdateCryptoKeyDeletesAt ( ctx context . Context , arg UpdateCryptoKeyDeletesAtParams ) ( CryptoKey , error )
2024-08-13 12:53:47 -05:00
UpdateCustomRole ( ctx context . Context , arg UpdateCustomRoleParams ) ( CustomRole , error )
2026-05-14 16:10:46 +02:00
// Updates only the encrypted columns (api_key, api_key_key_id) and
// the updated_at timestamp on a row. Used by the dbcrypt key
// rotation utility to re-encrypt or decrypt rows in place.
UpdateEncryptedAIProviderKey ( ctx context . Context , arg UpdateEncryptedAIProviderKeyParams ) ( AIProviderKey , error )
// Updates only the encrypted columns (settings, settings_key_id) and
// the updated_at timestamp on a row, regardless of its deleted flag.
// Used by the dbcrypt key rotation utility to re-encrypt or decrypt
// rows in place.
UpdateEncryptedAIProviderSettings ( ctx context . Context , arg UpdateEncryptedAIProviderSettingsParams ) ( AIProvider , error )
2026-06-16 11:01:43 +02:00
UpdateEncryptedUserAIProviderKey ( ctx context . Context , arg UpdateEncryptedUserAIProviderKeyParams ) ( UserAIProviderKey , error )
2026-08-19 14:00:31 -07:00
// If a refresh lease is provided, the row is only updated if the lease matches.
2023-09-29 14:13:20 -05:00
UpdateExternalAuthLink ( ctx context . Context , arg UpdateExternalAuthLinkParams ) ( ExternalAuthLink , error )
2022-10-14 16:25:46 -05:00
UpdateGitSSHKey ( ctx context . Context , arg UpdateGitSSHKeyParams ) ( GitSSHKey , error )
2022-10-10 15:37:06 -05:00
UpdateGroupByID ( ctx context . Context , arg UpdateGroupByIDParams ) ( Group , error )
2023-08-02 16:31:25 +02:00
UpdateInactiveUsersToDormant ( ctx context . Context , arg UpdateInactiveUsersToDormantParams ) ([] UpdateInactiveUsersToDormantRow , error )
2025-03-03 10:12:48 +01:00
UpdateInboxNotificationReadStatus ( ctx context . Context , arg UpdateInboxNotificationReadStatusParams ) error
2026-03-19 10:07:36 -04:00
UpdateMCPServerConfig ( ctx context . Context , arg UpdateMCPServerConfigParams ) ( MCPServerConfig , error )
2026-08-19 21:25:18 +02:00
UpdateMCPServerConfigACLByID ( ctx context . Context , arg UpdateMCPServerConfigACLByIDParams ) error
2026-07-20 00:14:03 +02:00
// Refresh persistence must not recreate a token deleted by disconnect.
// The optimistic lock also prevents stale refreshes from replacing newer tokens.
UpdateMCPServerUserTokenFromRefresh ( ctx context . Context , arg UpdateMCPServerUserTokenFromRefreshParams ) ( MCPServerUserToken , error )
2022-04-29 09:04:19 -05:00
UpdateMemberRoles ( ctx context . Context , arg UpdateMemberRolesParams ) ( OrganizationMember , error )
2025-02-17 16:56:52 +00:00
UpdateMemoryResourceMonitor ( ctx context . Context , arg UpdateMemoryResourceMonitorParams ) error
2024-08-05 16:18:45 +02:00
UpdateNotificationTemplateMethodByID ( ctx context . Context , arg UpdateNotificationTemplateMethodByIDParams ) ( NotificationTemplate , error )
2025-07-03 18:33:47 +02:00
UpdateOAuth2ProviderAppByClientID ( ctx context . Context , arg UpdateOAuth2ProviderAppByClientIDParams ) ( OAuth2ProviderApp , error )
2023-12-21 12:38:42 -09:00
UpdateOAuth2ProviderAppByID ( ctx context . Context , arg UpdateOAuth2ProviderAppByIDParams ) ( OAuth2ProviderApp , error )
2024-05-21 12:46:31 -06:00
UpdateOrganization ( ctx context . Context , arg UpdateOrganizationParams ) ( Organization , error )
2025-02-24 17:59:41 +00:00
UpdateOrganizationDeletedByID ( ctx context . Context , arg UpdateOrganizationDeletedByIDParams ) error
2026-01-14 09:47:50 -08:00
UpdateOrganizationWorkspaceSharingSettings ( ctx context . Context , arg UpdateOrganizationWorkspaceSharingSettingsParams ) ( Organization , error )
2025-10-24 15:27:49 +01:00
// Cancels all pending provisioner jobs for prebuilt workspaces on a specific preset from an
// inactive template version.
// This is an optimization to clean up stale pending jobs.
2025-10-29 10:37:28 +00:00
UpdatePrebuildProvisionerJobWithCancel ( ctx context . Context , arg UpdatePrebuildProvisionerJobWithCancelParams ) ([] UpdatePrebuildProvisionerJobWithCancelRow , error )
2025-05-21 15:16:38 -04:00
UpdatePresetPrebuildStatus ( ctx context . Context , arg UpdatePresetPrebuildStatusParams ) error
2025-11-20 17:12:25 +01:00
UpdatePresetsLastInvalidatedAt ( ctx context . Context , arg UpdatePresetsLastInvalidatedAtParams ) ([] UpdatePresetsLastInvalidatedAtRow , error )
2023-12-18 16:44:52 +00:00
UpdateProvisionerDaemonLastSeenAt ( ctx context . Context , arg UpdateProvisionerDaemonLastSeenAtParams ) error
2022-01-29 17:38:32 -06:00
UpdateProvisionerJobByID ( ctx context . Context , arg UpdateProvisionerJobByIDParams ) error
2025-07-30 19:09:53 -05:00
UpdateProvisionerJobLogsLength ( ctx context . Context , arg UpdateProvisionerJobLogsLengthParams ) error
UpdateProvisionerJobLogsOverflowed ( ctx context . Context , arg UpdateProvisionerJobLogsOverflowedParams ) error
2022-03-22 13:17:50 -06:00
UpdateProvisionerJobWithCancelByID ( ctx context . Context , arg UpdateProvisionerJobWithCancelByIDParams ) error
2022-02-03 19:13:22 -06:00
UpdateProvisionerJobWithCompleteByID ( ctx context . Context , arg UpdateProvisionerJobWithCompleteByIDParams ) error
2025-05-20 15:22:44 +02:00
UpdateProvisionerJobWithCompleteWithStartedAtByID ( ctx context . Context , arg UpdateProvisionerJobWithCompleteWithStartedAtByIDParams ) error
2022-10-17 08:43:30 -05:00
UpdateReplica ( ctx context . Context , arg UpdateReplicaParams ) ( Replica , error )
2026-05-01 15:00:08 -05:00
UpdateTailnetPeerStatusByCoordinator ( ctx context . Context , arg UpdateTailnetPeerStatusByCoordinatorParams ) ([] uuid . UUID , error )
2025-11-25 11:13:32 +00:00
UpdateTaskPrompt ( ctx context . Context , arg UpdateTaskPromptParams ) ( TaskTable , error )
2025-10-23 19:12:09 +03:00
UpdateTaskWorkspaceID ( ctx context . Context , arg UpdateTaskWorkspaceIDParams ) ( TaskTable , error )
2023-07-19 16:07:33 -04:00
UpdateTemplateACLByID ( ctx context . Context , arg UpdateTemplateACLByIDParams ) error
2023-10-18 17:07:21 -05:00
UpdateTemplateAccessControlByID ( ctx context . Context , arg UpdateTemplateAccessControlByIDParams ) error
2022-04-06 12:42:40 -05:00
UpdateTemplateActiveVersionByID ( ctx context . Context , arg UpdateTemplateActiveVersionByIDParams ) error
UpdateTemplateDeletedByID ( ctx context . Context , arg UpdateTemplateDeletedByIDParams ) error
2023-07-19 16:07:33 -04:00
UpdateTemplateMetaByID ( ctx context . Context , arg UpdateTemplateMetaByIDParams ) error
UpdateTemplateScheduleByID ( ctx context . Context , arg UpdateTemplateScheduleByIDParams ) error
2023-07-25 09:14:38 -04:00
UpdateTemplateVersionByID ( ctx context . Context , arg UpdateTemplateVersionByIDParams ) error
2022-05-17 15:00:48 -05:00
UpdateTemplateVersionDescriptionByJobID ( ctx context . Context , arg UpdateTemplateVersionDescriptionByJobIDParams ) error
2023-09-29 14:13:20 -05:00
UpdateTemplateVersionExternalAuthProvidersByJobID ( ctx context . Context , arg UpdateTemplateVersionExternalAuthProvidersByJobIDParams ) error
2025-08-19 10:29:51 +02:00
UpdateTemplateVersionFlagsByJobID ( ctx context . Context , arg UpdateTemplateVersionFlagsByJobIDParams ) error
2023-08-22 15:15:13 -05:00
UpdateTemplateWorkspacesLastUsedAt ( ctx context . Context , arg UpdateTemplateWorkspacesLastUsedAtParams ) error
2025-08-16 01:31:00 +10:00
UpdateUsageEventsPostPublish ( ctx context . Context , arg UpdateUsageEventsPostPublishParams ) error
2026-06-16 11:01:43 +02:00
UpdateUserAIProviderKey ( ctx context . Context , arg UpdateUserAIProviderKeyParams ) ( UserAIProviderKey , error )
2026-05-12 10:09:34 +02:00
UpdateUserAgentChatSendShortcut ( ctx context . Context , arg UpdateUserAgentChatSendShortcutParams ) ( string , error )
2026-03-24 00:48:18 +01:00
UpdateUserChatCompactionThreshold ( ctx context . Context , arg UpdateUserChatCompactionThresholdParams ) ( UserConfig , error )
2026-03-10 08:17:52 -07:00
UpdateUserChatCustomPrompt ( ctx context . Context , arg UpdateUserChatCustomPromptParams ) ( UserConfig , error )
2026-05-07 20:15:28 +01:00
UpdateUserCodeDiffDisplayMode ( ctx context . Context , arg UpdateUserCodeDiffDisplayModeParams ) ( string , error )
2024-02-20 13:19:38 -06:00
UpdateUserDeletedByID ( ctx context . Context , id uuid . UUID ) error
2024-08-02 11:49:36 -05:00
UpdateUserGithubComUserID ( ctx context . Context , arg UpdateUserGithubComUserIDParams ) error
2024-10-04 11:53:25 +01:00
UpdateUserHashedOneTimePasscode ( ctx context . Context , arg UpdateUserHashedOneTimePasscodeParams ) error
2022-05-06 09:20:08 -05:00
UpdateUserHashedPassword ( ctx context . Context , arg UpdateUserHashedPasswordParams ) error
2022-09-26 10:31:03 -05:00
UpdateUserLastSeenAt ( ctx context . Context , arg UpdateUserLastSeenAtParams ) ( User , error )
2022-08-17 18:00:53 -05:00
UpdateUserLink ( ctx context . Context , arg UpdateUserLinkParams ) ( UserLink , error )
2026-06-04 14:36:56 -04:00
// Backfills linked_id for legacy user_links that were created before
// linked_id tracking was added. Only updates when linked_id is empty
// to avoid overwriting a valid binding.
UpdateUserLinkedID ( ctx context . Context , arg UpdateUserLinkedIDParams ) ( UserLink , error )
2023-06-30 08:38:48 -04:00
UpdateUserLoginType ( ctx context . Context , arg UpdateUserLoginTypeParams ) ( User , error )
2024-08-05 16:18:45 +02:00
UpdateUserNotificationPreferences ( ctx context . Context , arg UpdateUserNotificationPreferencesParams ) ( int64 , error )
2022-04-12 11:05:21 -03:00
UpdateUserProfile ( ctx context . Context , arg UpdateUserProfileParams ) ( User , error )
2023-07-20 06:35:41 -07:00
UpdateUserQuietHoursSchedule ( ctx context . Context , arg UpdateUserQuietHoursScheduleParams ) ( User , error )
2022-04-29 09:04:19 -05:00
UpdateUserRoles ( ctx context . Context , arg UpdateUserRolesParams ) ( User , error )
2026-04-07 09:03:28 -06:00
UpdateUserSecretByUserIDAndName ( ctx context . Context , arg UpdateUserSecretByUserIDAndNameParams ) ( UserSecret , error )
2026-05-14 14:25:07 +01:00
UpdateUserShellToolDisplayMode ( ctx context . Context , arg UpdateUserShellToolDisplayModeParams ) ( string , error )
2026-05-20 00:09:09 +02:00
UpdateUserSkillByUserIDAndName ( ctx context . Context , arg UpdateUserSkillByUserIDAndNameParams ) ( UserSkill , error )
2022-04-26 09:00:07 -05:00
UpdateUserStatus ( ctx context . Context , arg UpdateUserStatusParams ) ( User , error )
2025-04-07 14:30:10 +02:00
UpdateUserTerminalFont ( ctx context . Context , arg UpdateUserTerminalFontParams ) ( UserConfig , error )
2026-05-14 11:44:05 +07:00
UpdateUserThemeDark ( ctx context . Context , arg UpdateUserThemeDarkParams ) ( UserConfig , error )
UpdateUserThemeLight ( ctx context . Context , arg UpdateUserThemeLightParams ) ( UserConfig , error )
UpdateUserThemeMode ( ctx context . Context , arg UpdateUserThemeModeParams ) ( UserConfig , error )
2025-04-07 14:30:10 +02:00
UpdateUserThemePreference ( ctx context . Context , arg UpdateUserThemePreferenceParams ) ( UserConfig , error )
2026-04-24 12:29:08 +01:00
UpdateUserThinkingDisplayMode ( ctx context . Context , arg UpdateUserThinkingDisplayModeParams ) ( string , error )
2025-02-17 16:56:52 +00:00
UpdateVolumeResourceMonitor ( ctx context . Context , arg UpdateVolumeResourceMonitorParams ) error
2024-10-22 09:20:54 -05:00
UpdateWorkspace ( ctx context . Context , arg UpdateWorkspaceParams ) ( WorkspaceTable , error )
2025-07-31 09:05:09 -06:00
UpdateWorkspaceACLByID ( ctx context . Context , arg UpdateWorkspaceACLByIDParams ) error
2022-03-22 13:17:50 -06:00
UpdateWorkspaceAgentConnectionByID ( ctx context . Context , arg UpdateWorkspaceAgentConnectionByIDParams ) error
2026-04-10 10:11:22 -04:00
UpdateWorkspaceAgentDirectoryByID ( ctx context . Context , arg UpdateWorkspaceAgentDirectoryByIDParams ) error
2026-02-04 15:33:48 +00:00
UpdateWorkspaceAgentDisplayAppsByID ( ctx context . Context , arg UpdateWorkspaceAgentDisplayAppsByIDParams ) error
2023-01-24 14:24:27 +02:00
UpdateWorkspaceAgentLifecycleStateByID ( ctx context . Context , arg UpdateWorkspaceAgentLifecycleStateByIDParams ) error
2023-07-28 09:57:23 -06:00
UpdateWorkspaceAgentLogOverflowByID ( ctx context . Context , arg UpdateWorkspaceAgentLogOverflowByIDParams ) error
2023-03-31 15:26:19 -05:00
UpdateWorkspaceAgentMetadata ( ctx context . Context , arg UpdateWorkspaceAgentMetadataParams ) error
2023-02-07 15:35:09 -06:00
UpdateWorkspaceAgentStartupByID ( ctx context . Context , arg UpdateWorkspaceAgentStartupByIDParams ) error
2022-09-23 15:51:04 -04:00
UpdateWorkspaceAppHealthByID ( ctx context . Context , arg UpdateWorkspaceAppHealthByIDParams ) error
2023-10-06 13:27:12 +04:00
UpdateWorkspaceAutomaticUpdates ( ctx context . Context , arg UpdateWorkspaceAutomaticUpdatesParams ) error
2022-04-07 10:03:35 +01:00
UpdateWorkspaceAutostart ( ctx context . Context , arg UpdateWorkspaceAutostartParams ) error
2023-07-25 09:14:38 -04:00
UpdateWorkspaceBuildCostByID ( ctx context . Context , arg UpdateWorkspaceBuildCostByIDParams ) error
2023-09-22 16:22:07 +01:00
UpdateWorkspaceBuildDeadlineByID ( ctx context . Context , arg UpdateWorkspaceBuildDeadlineByIDParams ) error
2025-08-19 10:29:51 +02:00
UpdateWorkspaceBuildFlagsByID ( ctx context . Context , arg UpdateWorkspaceBuildFlagsByIDParams ) error
2026-06-26 01:25:23 -05:00
// Stamps the deadline value that an autostop reminder was last sent for. Once
// this equals the build's deadline the reminder is considered handled and the
// lifecycle executor will not send another for this deadline, which makes the
// reminder idempotent and HA-safe. It re-arms automatically when the deadline
// changes (e.g. an activity bump).
UpdateWorkspaceBuildNotifiedAutostopDeadline ( ctx context . Context , arg UpdateWorkspaceBuildNotifiedAutostopDeadlineParams ) error
2026-07-07 09:18:30 -07:00
UpdateWorkspaceBuildOrchestrationCanceledByID ( ctx context . Context , arg UpdateWorkspaceBuildOrchestrationCanceledByIDParams ) ( WorkspaceBuildOrchestration , error )
UpdateWorkspaceBuildOrchestrationCompletedByID ( ctx context . Context , arg UpdateWorkspaceBuildOrchestrationCompletedByIDParams ) ( WorkspaceBuildOrchestration , error )
UpdateWorkspaceBuildOrchestrationFailedByID ( ctx context . Context , arg UpdateWorkspaceBuildOrchestrationFailedByIDParams ) ( WorkspaceBuildOrchestration , error )
UpdateWorkspaceBuildOrchestrationRetryByID ( ctx context . Context , arg UpdateWorkspaceBuildOrchestrationRetryByIDParams ) ( WorkspaceBuildOrchestration , error )
2023-09-22 16:22:07 +01:00
UpdateWorkspaceBuildProvisionerStateByID ( ctx context . Context , arg UpdateWorkspaceBuildProvisionerStateByIDParams ) error
2022-03-22 13:17:50 -06:00
UpdateWorkspaceDeletedByID ( ctx context . Context , arg UpdateWorkspaceDeletedByIDParams ) error
2024-10-22 09:20:54 -05:00
UpdateWorkspaceDormantDeletingAt ( ctx context . Context , arg UpdateWorkspaceDormantDeletingAtParams ) ( WorkspaceTable , error )
2022-09-01 19:08:51 -05:00
UpdateWorkspaceLastUsedAt ( ctx context . Context , arg UpdateWorkspaceLastUsedAtParams ) error
2024-12-02 21:02:36 +00:00
UpdateWorkspaceNextStartAt ( ctx context . Context , arg UpdateWorkspaceNextStartAtParams ) error
2023-05-09 13:46:50 -05:00
// This allows editing the properties of a workspace proxy.
UpdateWorkspaceProxy ( ctx context . Context , arg UpdateWorkspaceProxyParams ) ( WorkspaceProxy , error )
2023-04-04 15:07:29 -05:00
UpdateWorkspaceProxyDeleted ( ctx context . Context , arg UpdateWorkspaceProxyDeletedParams ) error
2022-05-19 20:09:27 +01:00
UpdateWorkspaceTTL ( ctx context . Context , arg UpdateWorkspaceTTLParams ) error
2024-10-22 09:20:54 -05:00
UpdateWorkspacesDormantDeletingAtByTemplateID ( ctx context . Context , arg UpdateWorkspacesDormantDeletingAtByTemplateIDParams ) ([] WorkspaceTable , error )
2024-12-06 11:01:39 +00:00
UpdateWorkspacesTTLByTemplateID ( ctx context . Context , arg UpdateWorkspacesTTLByTemplateIDParams ) error
2026-08-20 11:36:58 +01:00
// Upsert a batch of model prices from a JSON array, all recorded under the
// given source. Each element must have provider, model, and the four price
// fields, and null prices are written as SQL NULL.
// Each source keeps its own row, so the price book and a custom price never
// overwrite each other. A conflicting row is only rewritten when a price
// differs, so updated_at records when a price last changed. Prices are
// nullable and a NULL on either side counts as a difference.
UpsertAIModelPrices ( ctx context . Context , arg UpsertAIModelPricesParams ) error
2026-03-16 15:30:25 -05:00
// Returns true if a new rows was inserted, false otherwise.
UpsertAISeatState ( ctx context . Context , arg UpsertAISeatStateParams ) ( bool , error )
2024-05-31 10:59:28 -06:00
UpsertAnnouncementBanners ( ctx context . Context , value string ) error
2023-09-27 17:02:18 +02:00
UpsertApplicationName ( ctx context . Context , value string ) error
2026-02-02 09:11:54 -07:00
// Upserts boundary usage statistics for a replica. On INSERT (new period), uses
// delta values for unique counts (only data since last flush). On UPDATE, uses
// cumulative values for unique counts (accurate period totals). Request counts
// are always deltas, accumulated in DB. Returns true if insert, false if update.
2026-01-27 13:29:21 -07:00
UpsertBoundaryUsageStats ( ctx context . Context , arg UpsertBoundaryUsageStatsParams ) ( bool , error )
2026-04-30 14:53:08 +02:00
// UpsertChatAdvisorConfig stores the deployment-wide runtime configuration
// for the experimental chat advisor. Callers marshal codersdk.AdvisorConfig
// to JSON before invoking this query.
UpsertChatAdvisorConfig ( ctx context . Context , value string ) error
2026-04-24 14:18:28 +01:00
UpsertChatAutoArchiveDays ( ctx context . Context , autoArchiveDays int32 ) error
2026-05-04 20:30:50 +02:00
UpsertChatComputerUseProvider ( ctx context . Context , provider string ) error
2026-04-13 15:06:06 +02:00
// UpsertChatDebugLoggingAllowUsers updates the runtime admin setting that
// allows users to opt into chat debug logging.
UpsertChatDebugLoggingAllowUsers ( ctx context . Context , allowUsers bool ) error
2026-05-05 22:37:13 +02:00
UpsertChatDebugRetentionDays ( ctx context . Context , debugRetentionDays int32 ) error
2026-03-18 09:35:13 +01:00
UpsertChatDesktopEnabled ( ctx context . Context , enableDesktop bool ) error
2026-02-27 11:50:56 -05:00
UpsertChatDiffStatus ( ctx context . Context , arg UpsertChatDiffStatusParams ) ( ChatDiffStatus , error )
UpsertChatDiffStatusReference ( ctx context . Context , arg UpsertChatDiffStatusReferenceParams ) ( ChatDiffStatus , error )
2026-06-12 13:33:12 +02:00
// Upserts a heartbeat row for the (chat_id, runner_id) lease. Uses
// database time so callers do not depend on a local clock.
UpsertChatHeartbeat ( ctx context . Context , arg UpsertChatHeartbeatParams ) error
2026-03-26 13:32:41 +01:00
UpsertChatIncludeDefaultSystemPrompt ( ctx context . Context , includeDefaultSystemPrompt bool ) error
2026-08-24 12:20:26 +02:00
UpsertChatOrganizationModelOverride ( ctx context . Context , arg UpsertChatOrganizationModelOverrideParams ) error
2026-05-05 00:57:51 +02:00
// UpsertChatPersonalModelOverridesEnabled updates whether users may configure
// personal chat model overrides.
UpsertChatPersonalModelOverridesEnabled ( ctx context . Context , enabled bool ) error
2026-04-16 11:12:01 +02:00
UpsertChatPlanModeInstructions ( ctx context . Context , value string ) error
2026-04-08 11:08:09 +01:00
UpsertChatRetentionDays ( ctx context . Context , retentionDays int32 ) error
2026-03-10 11:46:53 +00:00
UpsertChatSystemPrompt ( ctx context . Context , value string ) error
2026-08-24 12:20:26 +02:00
UpsertChatUserModelOverride ( ctx context . Context , arg UpsertChatUserModelOverrideParams ) error
2026-03-20 17:38:39 +00:00
UpsertChatWorkspaceTTL ( ctx context . Context , workspaceTtl string ) error
2026-09-02 11:29:35 +02:00
UpsertCodernautsEnabled ( ctx context . Context , enabled bool ) error
2023-06-08 10:30:15 -05:00
// The default proxy is implied and not actually stored in the database.
// So we need to store it's configuration here for display purposes.
// The functional values are immutable and controlled implicitly.
UpsertDefaultProxy ( ctx context . Context , arg UpsertDefaultProxyParams ) error
2026-06-16 11:01:43 +02:00
UpsertGroupAIBudget ( ctx context . Context , arg UpsertGroupAIBudgetParams ) ( GroupAIBudget , error )
2023-11-23 17:18:12 +01:00
UpsertHealthSettings ( ctx context . Context , value string ) error
2023-03-27 19:55:10 -05:00
UpsertLastUpdateCheck ( ctx context . Context , value string ) error
UpsertLogoURL ( ctx context . Context , value string ) error
2026-03-19 10:07:36 -04:00
UpsertMCPServerUserToken ( ctx context . Context , arg UpsertMCPServerUserTokenParams ) ( MCPServerUserToken , error )
2024-09-18 09:11:44 +02:00
// Insert or update notification report generator logs with recent activity.
UpsertNotificationReportGeneratorLog ( ctx context . Context , arg UpsertNotificationReportGeneratorLogParams ) error
2024-07-10 16:15:06 +02:00
UpsertNotificationsSettings ( ctx context . Context , value string ) error
2026-07-28 16:59:33 -07:00
UpsertOAuth2DCREnabled ( ctx context . Context , enabled bool ) error
2025-02-25 16:31:33 +01:00
UpsertOAuth2GithubDefaultEligible ( ctx context . Context , eligible bool ) error
2025-07-02 17:05:42 +02:00
UpsertPrebuildsSettings ( ctx context . Context , value string ) error
2023-12-13 12:31:40 +00:00
UpsertProvisionerDaemon ( ctx context . Context , arg UpsertProvisionerDaemonParams ) ( ProvisionerDaemon , error )
2024-09-09 14:14:52 -05:00
UpsertRuntimeConfig ( ctx context . Context , arg UpsertRuntimeConfigParams ) error
2023-06-21 16:20:58 +04:00
UpsertTailnetCoordinator ( ctx context . Context , id uuid . UUID ) ( TailnetCoordinator , error )
2023-11-15 10:13:27 +04:00
UpsertTailnetPeer ( ctx context . Context , arg UpsertTailnetPeerParams ) ( TailnetPeer , error )
UpsertTailnetTunnel ( ctx context . Context , arg UpsertTailnetTunnelParams ) ( TailnetTunnel , error )
2026-01-27 11:09:24 +02:00
UpsertTaskSnapshot ( ctx context . Context , arg UpsertTaskSnapshotParams ) error
2025-10-13 12:25:58 +03:00
UpsertTaskWorkspaceApp ( ctx context . Context , arg UpsertTaskWorkspaceAppParams ) ( TaskWorkspaceApp , error )
2025-01-31 13:55:46 +01:00
UpsertTelemetryItem ( ctx context . Context , arg UpsertTelemetryItemParams ) error
2024-03-22 18:33:34 +02:00
// This query aggregates the workspace_agent_stats and workspace_app_stats data
// into a single table for efficient storage and querying. Half-hour buckets are
// used to store the data, and the minutes are summed for each user and template
// combination. The result is stored in the template_usage_stats table.
2026-09-10 13:54:11 +02:00
UpsertTemplateUsageStats ( ctx context . Context , appFamilies json . RawMessage ) error
2026-06-16 11:01:43 +02:00
UpsertUserAIBudgetOverride ( ctx context . Context , arg UpsertUserAIBudgetOverrideParams ) ( UserAIBudgetOverride , error )
2026-05-22 02:16:01 +02:00
// UpsertUserAIProviderKey preserves the original id and created_at when the
// user/provider pair already exists. On conflict, callers provide id and
// created_at for the insert path only.
2026-06-16 11:01:43 +02:00
UpsertUserAIProviderKey ( ctx context . Context , arg UpsertUserAIProviderKeyParams ) ( UserAIProviderKey , error )
2026-04-13 15:06:06 +02:00
UpsertUserChatDebugLoggingEnabled ( ctx context . Context , arg UpsertUserChatDebugLoggingEnabledParams ) error
2025-03-27 10:03:53 +00:00
UpsertWebpushVAPIDKeys ( ctx context . Context , arg UpsertWebpushVAPIDKeysParams ) error
2026-06-15 09:38:52 -07:00
UpsertWorkspaceAgentContextResource ( ctx context . Context , arg UpsertWorkspaceAgentContextResourceParams ) ( WorkspaceAgentContextResource , error )
UpsertWorkspaceAgentContextSnapshot ( ctx context . Context , arg UpsertWorkspaceAgentContextSnapshotParams ) ( WorkspaceAgentContextSnapshot , error )
2024-02-13 09:31:20 -05:00
UpsertWorkspaceAgentPortShare ( ctx context . Context , arg UpsertWorkspaceAgentPortShareParams ) ( WorkspaceAgentPortShare , error )
2025-06-23 20:50:44 +02:00
UpsertWorkspaceApp ( ctx context . Context , arg UpsertWorkspaceAppParams ) ( WorkspaceApp , error )
2025-03-18 13:50:52 +02:00
//
2025-03-20 16:10:45 +02:00
// The returned boolean, new_or_stale, can be used to deduce if a new session
// was started. This means that a new row was inserted (no previous session) or
// the updated_at is older than stale interval.
UpsertWorkspaceAppAuditSession ( ctx context . Context , arg UpsertWorkspaceAppAuditSessionParams ) ( bool , error )
2026-03-18 09:30:22 -05:00
UsageEventExistsByID ( ctx context . Context , id string ) ( bool , error )
2025-08-07 10:14:58 -06:00
ValidateGroupIDs ( ctx context . Context , groupIds [] uuid . UUID ) ( ValidateGroupIDsRow , error )
ValidateUserIDs ( ctx context . Context , userIds [] uuid . UUID ) ( ValidateUserIDsRow , error )
2022-01-05 09:20:56 -06:00
}
2022-10-10 15:37:06 -05:00
var _ sqlcQuerier = ( * sqlQuerier )( nil )