Skip to content

refactor: rename Ai* database identifiers to AI* (AIGOV-369)#26327

Draft
dannykopping wants to merge 5 commits into
mainfrom
danny/aigov-369-change-ai-references-in-coderddatabasemodelsgo-to-ai
Draft

refactor: rename Ai* database identifiers to AI* (AIGOV-369)#26327
dannykopping wants to merge 5 commits into
mainfrom
danny/aigov-369-change-ai-references-in-coderddatabasemodelsgo-to-ai

Conversation

@dannykopping

Copy link
Copy Markdown
Contributor

Adds ai to the sqlc gen.go.initialisms list so generated identifiers follow Go's initialism convention. The sqlc default was ["id"], which produced AiProviderType, AiSeat, AiModelPrice, ApiKeyScopeAiSeatCreate, etc. With ai added, the token uppercases to AI wherever it appears as a standalone underscore-separated part of a SQL identifier (ai_provider_type, ai_seat, ai_gateway_key, ai_model_price, plus every enum value and column that contains a standalone ai token).

make gen propagates the rename through sqlc, typegen (RBAC/codersdk), swagger, audit doc, and TypeScript artifacts. Hand-written call sites in coderd/, enterprise/, cli/, and the audit/dbgen helpers are updated to reference the new identifier names.

Single-token names like aibridge (one SQL token, not ai_bridge) are out of scope and keep their existing casing, so ApiKeyScopeAibridgeInterception* and AiSeatUsageReasonAibridge are unchanged.

On-the-wire string values (enum values, RBAC resource type strings, JSON tags) are unchanged. Only the Go identifier names move, so the HTTP/JSON API surface is unaffected.

Refs: AIGOV-369

Implementation plan
1. coderd/database/sqlc.yaml: add `ai` to `gen.go.initialisms` (default
   was just `["id"]`).
2. `make gen` regenerates sqlc DB code, typegen-driven RBAC/codersdk
   files, swagger, audit doc, and TypeScript types.
3. Hand-written call sites updated via a Perl pattern
   `(?<![A-Z])Ai(?=Budget|GatewayKey|ModelPrice|Provider|Seat)` -> `AI`.
   The look-behind avoids matching base64 strings sandwiched between
   uppercase letters; the look-ahead constrains to the specific DB
   identifier roots that are renamed. Excludes `*.pb.go`,
   `coderd/azureidentity/*.go`, and `coderd/oauthpki/okidcpki_test.go`
   (test certificate/JWT data).
4. Existing sqlc renames such as `ai_provider: AIProvider` are kept
   unchanged to minimize churn even though they're now redundant.

🤖 Generated with Coder Agents

Adds "ai" to the sqlc gen.go.initialisms list in
coderd/database/sqlc.yaml so generated identifiers follow Go's
initialism convention. Previously the default initialism list was just
["id"], producing Ai-prefixed names like AiProviderType, AiSeat,
AiModelPrice, ApiKeyScopeAiSeatCreate, etc. With "ai" added, sqlc
uppercases the token to AI wherever it appears as a standalone
underscore-separated part of a SQL identifier:

  AiProviderTypeOpenai       -> AIProviderTypeOpenai
  ApiKeyScopeAiSeatCreate    -> ApiKeyScopeAISeatCreate
  GroupAiBudget              -> GroupAIBudget
  UserAiProviderKey          -> UserAIProviderKey
  ResourceTypeAiSeat         -> ResourceTypeAISeat
  NullAiSeatUsageReason      -> NullAISeatUsageReason
  AllAiSeatUsageReasonValues -> AllAISeatUsageReasonValues

Single-token names like "aibridge" (one SQL token, not "ai_bridge") are
unaffected, so ApiKeyScopeAibridgeInterception* and
AiSeatUsageReasonAibridge keep their existing casing.

The change is applied as a generated-code refactor:
  * sqlc.yaml gains "id" and "ai" under initialisms.
  * `make gen` regenerates all sqlc, typegen, swagger, audit-doc, and
    TypeScript artifacts (~18 generated files).
  * Hand-written call sites in coderd/, enterprise/, cli/, and the
    audit and dbgen helpers are updated to reference the new identifier
    names.

The on-the-wire string values (enum values, RBAC resource type strings,
JSON tags) are unchanged. Only the Go identifier names move.

Refs: AIGOV-369

🤖 Generated with [Coder Agents](https://coder.com)
@github-actions

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/admin/security/audit-logs.md

@linear-code

linear-code Bot commented Jun 12, 2026

Copy link
Copy Markdown

AIGOV-369

The previous commit added `ai` to sqlc's `gen.go.initialisms`, but the
typegen and apikeyscopesgen helpers used by `make gen` had their own
PascalCase routines that didn't recognize initialisms. Locally my bulk
rename happened to mask this by editing the generated files directly,
but a clean `make gen` (which CI runs) reverted those identifiers,
producing `ResourceAiSeat`, `ScopeAiSeat`, `APIKeyScopeAiSeatCreate`,
etc., while hand-written callers like `coderd/rbac/roles.go` used
`ResourceAISeat`, etc. The result was an undefined-symbol failure in
`gen`, `lint`, `offlinedocs`, and the `check-scopes`/`apikeyscopesgen`
builds.

Add a tiny initialisms map (`ai` -> `AI`, `id` -> `ID`) to both
`scripts/typegen/main.go` (`pascalCaseName`) and
`scripts/apikeyscopesgen/main.go` (`pascal`), then regenerate. Keep
`id` in both maps so they stay aligned with the sqlc default, even
though no current RBAC type or action contains `id` as a standalone
underscore-separated token.

Refs: AIGOV-369
Reverts 0b37e3f. Replaced by adding
explicit `Name` fields on the `ai_seat` and `ai_model_price` entries
in `coderd/rbac/policy/policy.go`, which is the existing pattern used
by `ai_provider` and `ai_gateway_key`. That keeps the AI initialism
fix contained to the policy definitions instead of teaching the
PascalCase routines in `scripts/typegen` and `scripts/apikeyscopesgen`
about initialisms.

Refs: AIGOV-369
Sets `Name: "AISeat"` and `Name: "AIModelPrice"` on the matching
entries in coderd/rbac/policy/policy.go so typegen produces
`ResourceAISeat` and `ResourceAIModelPrice`, matching the existing
pattern used by ai_provider (`Name: "AIProvider"`) and ai_gateway_key
(`Name: "AIGatewayKey"`). Without this, typegen's PascalCase split
treats `ai` as an ordinary word and emits `ResourceAiSeat` /
`ResourceAiModelPrice`, mismatching the hand-written call sites in
`coderd/rbac/roles.go`, `enterprise/coderd/usage/cron_test.go`, and
the dbauthz files updated in the first commit on this branch.

Also regenerates the swagger and scope constant files affected by the
typegen run. The `Scope*` and `APIKeyScope*` identifiers regenerate
with `Ai` casing because their templates derive the name from the SQL
identifier directly, not from the policy `Name` field. That matches
the pre-PR pattern for those generated files and only affects internal
Go identifier names; the on-the-wire scope strings (e.g.
`ai_seat:create`) are unchanged.

Refs: AIGOV-369
`scripts/dbgen/main.go` generates `coderd/database/check_constraint.go`,
`coderd/database/foreign_key_constraint.go`, and
`coderd/database/unique_constraint.go` from the schema. Its
`nameFromSnakeCase` helper already special-cases initialisms like
`id`/`ID`, `api`/`API`, `uuid`/`UUID`, `jwt`/`JWT`, etc., but not `ai`.
Without an entry, the underlying CamelCase split produces
`CheckAiGatewayKeysNameCheck` and friends, which mismatch the call
sites already updated in the first commit on this branch and broke
`make gen` in CI.

Adds `case "ai": ret += "AI"` to the existing switch. Regenerates
`coderd/database/unique_constraint.go`, which picks up a single
additional rename:
`UniqueUserAIProviderKeysUserIDAiProviderIDKey` ->
`UniqueUserAIProviderKeysUserIDAIProviderIDKey` (the inner
`ai_provider_id` token now uppercases consistently with the outer
`ai_provider_keys`).

Refs: AIGOV-369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant