refactor: rename Ai* database identifiers to AI* (AIGOV-369)#26327
Draft
dannykopping wants to merge 5 commits into
Draft
refactor: rename Ai* database identifiers to AI* (AIGOV-369)#26327dannykopping wants to merge 5 commits into
dannykopping wants to merge 5 commits into
Conversation
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)
Docs preview📖 View docs preview for |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
aito the sqlcgen.go.initialismslist so generated identifiers follow Go's initialism convention. The sqlc default was["id"], which producedAiProviderType,AiSeat,AiModelPrice,ApiKeyScopeAiSeatCreate, etc. Withaiadded, the token uppercases toAIwherever 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 standaloneaitoken).make genpropagates the rename through sqlc, typegen (RBAC/codersdk), swagger, audit doc, and TypeScript artifacts. Hand-written call sites incoderd/,enterprise/,cli/, and the audit/dbgen helpers are updated to reference the new identifier names.Single-token names like
aibridge(one SQL token, notai_bridge) are out of scope and keep their existing casing, soApiKeyScopeAibridgeInterception*andAiSeatUsageReasonAibridgeare 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
🤖 Generated with Coder Agents