Skip to content

chore(coderd/database): drop deferred chat spend and cost columns #27600

Description

@ibetitsmike

Context

The chat-cost stack (#27328, #27329, #27330) removed native chat usage limits and native chat cost tracking, leaving AI Gateway data and budgets as the only path. Three physical columns, one table, and one index were deliberately left in place for one release so a replica still running the previous release keeps working during a rolling upgrade.

users.sql and groups.sql use SELECT *, so sqlc bakes every column into explicit column lists in GetUserByID, GetUserByEmailOrUsername, GetUsersByIDs, GetGroupByID, GetGroupByOrgAndName, and GetGroups. Dropping the users and groups columns in the same release would have failed broad authorization, audit, and API-key reads on an old replica, not just the usage-limit admin screens. Dropping chat_messages.total_cost_micros would have broken InsertChatMessages, and therefore every chat message insert.

chat_usage_limit_config and idx_chat_messages_owner_spend were kept for the same reason: an old replica still serves getMyChatUsageLimitStatus, which reads that table through chatd.ResolveUsageLimitStatus and runs GetUserChatSpendInPeriod behind that index. Dropping the table would 500 that handler (it tolerates only sql.ErrNoRows); dropping the index would leave a per-minute-polled path scanning chat_messages.

Nothing in the application reads any of these as of #27330.

Scope

Drop in a single migration:

  • users.chat_spend_limit_micros and users_chat_spend_limit_micros_check
  • groups.chat_spend_limit_micros and groups_chat_spend_limit_micros_check
  • chat_messages.total_cost_micros
  • chat_usage_limit_config (table, plus its sequence and three check constraints)
  • idx_chat_messages_owner_spend

Then:

  • Delete the two "chat_spend_limit_micros": ActionTrack entries in enterprise/audit/table.go (the &database.User{} and &database.AuditableGroup{} maps). They exist only because entry() exits the process at package init for any JSON-tagged field without an action, so they must go with the columns.
  • Remove the &i.ChatSpendLimitMicros scan from GetAuthorizedUsers in coderd/database/modelqueries.go, which is hand-maintained and must match generated GetUsers.
  • make gen, then confirm check_constraint.go loses both check constants and the three chat_usage_limit_config ones, unique_constraint.go loses its primary key, and models.go loses both fields and the now-unused ChatUsageLimitConfig struct.
  • Deleting a migration does not invalidate the mtime-gated dump.sql target, so if the drop is ever reverted, touch a migration that creates the object before regenerating.

Notes

  • Choose the migration number at authoring time against origin/main, not now. Also note that stacked PRs target their parent branch, so a duplicate migration number passes CI green; compare against origin/main directly before pushing.
  • Operators who still want their old native caps should read these columns out of the database before this lands. feat: remove native chat usage limits in favor of AI Gateway budgets #27329 did not migrate configured values into group_ai_budgets: period semantics do not map (native supported day/week/month, gateway budgets are month-only), group resolution picks the highest budget where native limits took the minimum, and user_ai_budget_overrides.group_id is NOT NULL so a groupless native user override has no destination.

Mux filed this issue on Mike's behalf.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions