Adds per-user chat project pins, the first backend layer of the Projects page and pinned projects design. Nothing in the UI reads pins yet; the sidebar and Projects page PRs stacked on top do. - **Schema:** migration `000647_chat_project_pins` adds the `chat_project_pins` table (`user_id`, `project_id`, `pin_order`, `source` of `migration`/`default`/`user`, `created_at`). Unpinning deletes the row. The migration pins every project to its owner in today's sidebar order (`lower(name), id`); shared projects are not pinned. - **Shared rule for which projects a user's list matches:** the migration also adds `chat_project_ids_for_user(viewer_id, include_grants)`: owned projects, plus projects whose ACL names the user or one of their groups (including Everyone) in an organization they belong to. The project list and `GetChats` call it instead of each keeping a copy of that predicate, and so do #32026's queries. Postgres inlines it, so the ACL indexes still apply (same results and timings as before on a 10,000-user, 305-project test database). - **Endpoints:** `PUT` and `DELETE /api/experimental/organizations/{organization}/chats/projects/{project}/pin` pin and unpin. `PUT` takes no body and pins at the end; a project that is already pinned keeps its place. `DELETE` removes the pin. The caller needs read access to a project they can use (anything else is a 404) and `update_personal` on themselves, because a pin is their personal data; an API key scoped without `user:update_personal` gets a 403. Pins are personal preferences, so they are not audited. - **Reordering:** `PUT /api/experimental/chats/projects/pins/order` takes `{"project_ids": [...]}`, the pinned projects in their new order. The server saves the listed pins in that order and keeps every other pin after them, in its current order. The table also holds pins the caller can no longer see (lost access, sharing disabled), and this way no write has to work out which pins those are. IDs the caller has not pinned are ignored, so a project unpinned in another tab does not fail a reorder. The route sits outside `/organizations/{organization}` because one pin list spans organizations. It needs only `update_personal` on the caller. Pins and reorders take a per-user advisory lock. The stored `pin_order` only sorts the pins: it can have gaps after an unpin or a deleted project, until the next reorder. - **New projects** get a `default` pin for their creator inside the create transaction, so an API key scoped to create projects needs the pin's two permissions as well, and gets a 403 without them. - **Chat list:** `exclude_own_project_chats=true` leaves out the caller's own unpinned chats in projects the caller can use; clients list those per project with `project_id`. Project pins don't change the result, so pinning or unpinning never changes the chat list. Shared chats and the caller's pinned chats are still returned, and so are chats in projects the caller can no longer use, because no project list reaches them. The filter sits in the same `WHERE` as the cursor, so pages stay full. User-facing docs land with the UI PR, since these routes stay under `/api/experimental` with `x-apidocgen skip` like the other project routes. <details> <summary>Verification</summary> `make gen` (clean diff), `go build ./...`, `make lint/go`, and the pin, chat list, migration (`TestMigration000647PinsOwnedProjects`, `TestMigrateUpWithFixtures`), dbauthz and codersdk tests pass. `make pre-commit` passes except `lint/actions/actionlint`, which needs a newer local mise and fails the same way on `main`. The dogfood UAT below ran when a pin took a `pin_order` position. It was not repeated after reordering became its own call; the Go tests cover that call, including overlapping reorders and pins. Dogfood UAT ran against a dev deployment with a premium license (groups and a second org created through the licensed APIs): upgrade from `main` with case-sensitive names, pin/reorder/unpin/re-pin, 400 and 404 paths, an 84-request concurrent pin burst with no 5xx, the chat list filter in each sharing mode (as `pinned_projects_only`, before the rename to `exclude_own_project_chats`), and cascade on project delete. Upgrade output: ```text username | name | pin_order | source ----------+---------+-----------+----------- usera | Alpha | 1 | migration usera | beta | 2 | migration usera | gamma | 3 | migration userb | bown | 1 | migration userb | Bshared | 2 | migration ``` Creating a project afterwards appends a `default` pin at position 4, and usera has no pin on userb's shared `Bshared`. </details> > [!NOTE] > Most of this PR was written by AI agents (Xum, with UAT run through Coder Agents). The verification above is from those runs.
116 lines
16 KiB
Go
Generated
116 lines
16 KiB
Go
Generated
// Code generated by scripts/dbgen/main.go. DO NOT EDIT.
|
|
package database
|
|
|
|
// CheckConstraint represents a named check constraint on a table.
|
|
type CheckConstraint string
|
|
|
|
// CheckConstraint enums.
|
|
const (
|
|
CheckAIGatewayKeysHashedSecretCheck CheckConstraint = "ai_gateway_keys_hashed_secret_check" // ai_gateway_keys
|
|
CheckAIGatewayKeysNameCheck CheckConstraint = "ai_gateway_keys_name_check" // ai_gateway_keys
|
|
CheckAIGatewayKeysSecretPrefixCheck CheckConstraint = "ai_gateway_keys_secret_prefix_check" // ai_gateway_keys
|
|
CheckAIModelConfigsCacheReadPriceCheck CheckConstraint = "ai_model_configs_cache_read_price_check" // ai_model_configs
|
|
CheckAIModelConfigsCacheWritePriceCheck CheckConstraint = "ai_model_configs_cache_write_price_check" // ai_model_configs
|
|
CheckAIModelConfigsInputPriceCheck CheckConstraint = "ai_model_configs_input_price_check" // ai_model_configs
|
|
CheckAIModelConfigsModelCheck CheckConstraint = "ai_model_configs_model_check" // ai_model_configs
|
|
CheckAIModelConfigsOutputPriceCheck CheckConstraint = "ai_model_configs_output_price_check" // ai_model_configs
|
|
CheckAIModelPricesCacheReadPriceCheck CheckConstraint = "ai_model_prices_cache_read_price_check" // ai_model_prices
|
|
CheckAIModelPricesCacheWritePriceCheck CheckConstraint = "ai_model_prices_cache_write_price_check" // ai_model_prices
|
|
CheckAIModelPricesInputPriceCheck CheckConstraint = "ai_model_prices_input_price_check" // ai_model_prices
|
|
CheckAIModelPricesOutputPriceCheck CheckConstraint = "ai_model_prices_output_price_check" // ai_model_prices
|
|
CheckAIProvidersNameCheck CheckConstraint = "ai_providers_name_check" // ai_providers
|
|
CheckAIUserDailySpendSpendMicrosCheck CheckConstraint = "ai_user_daily_spend_spend_micros_check" // ai_user_daily_spend
|
|
CheckAibridgeInterceptionsOrganizationSourceCheck CheckConstraint = "aibridge_interceptions_organization_source_check" // aibridge_interceptions
|
|
CheckAibridgeTokenUsagesCacheReadPriceMicrosCheck CheckConstraint = "aibridge_token_usages_cache_read_price_micros_check" // aibridge_token_usages
|
|
CheckAibridgeTokenUsagesCacheWritePriceMicrosCheck CheckConstraint = "aibridge_token_usages_cache_write_price_micros_check" // aibridge_token_usages
|
|
CheckAibridgeTokenUsagesCostMicrosCheck CheckConstraint = "aibridge_token_usages_cost_micros_check" // aibridge_token_usages
|
|
CheckAibridgeTokenUsagesInputPriceMicrosCheck CheckConstraint = "aibridge_token_usages_input_price_micros_check" // aibridge_token_usages
|
|
CheckAibridgeTokenUsagesOutputPriceMicrosCheck CheckConstraint = "aibridge_token_usages_output_price_micros_check" // aibridge_token_usages
|
|
CheckAPIKeysAllowListNotEmpty CheckConstraint = "api_keys_allow_list_not_empty" // api_keys
|
|
CheckBoundaryLogsSequenceNumberCheck CheckConstraint = "boundary_logs_sequence_number_check" // boundary_logs
|
|
CheckChatModelConfigsAIProviderRequiredWhenActive CheckConstraint = "chat_model_configs_ai_provider_required_when_active" // chat_model_configs
|
|
CheckChatModelConfigsCompressionThresholdCheck CheckConstraint = "chat_model_configs_compression_threshold_check" // chat_model_configs
|
|
CheckChatModelConfigsContextLimitCheck CheckConstraint = "chat_model_configs_context_limit_check" // chat_model_configs
|
|
CheckChatModelConfigsGroupAclIsObject CheckConstraint = "chat_model_configs_group_acl_is_object" // chat_model_configs
|
|
CheckChatModelConfigsUserAclIsObject CheckConstraint = "chat_model_configs_user_acl_is_object" // chat_model_configs
|
|
CheckChatOrganizationModelOverridesContextCheck CheckConstraint = "chat_organization_model_overrides_context_check" // chat_organization_model_overrides
|
|
CheckChatProjectInstructionsNotBlank CheckConstraint = "chat_project_instructions_not_blank" // chat_project_instructions
|
|
CheckChatProjectMemoriesBodyLength CheckConstraint = "chat_project_memories_body_length" // chat_project_memories
|
|
CheckChatProjectMemoriesDescriptionLength CheckConstraint = "chat_project_memories_description_length" // chat_project_memories
|
|
CheckChatProjectMemoriesNameFormat CheckConstraint = "chat_project_memories_name_format" // chat_project_memories
|
|
CheckChatProjectPinsPinOrderCheck CheckConstraint = "chat_project_pins_pin_order_check" // chat_project_pins
|
|
CheckChatProjectsDefaultPresetOrParameters CheckConstraint = "chat_projects_default_preset_or_parameters" // chat_projects
|
|
CheckChatProjectsDescriptionLength CheckConstraint = "chat_projects_description_length" // chat_projects
|
|
CheckChatProjectsGroupAclIsObject CheckConstraint = "chat_projects_group_acl_is_object" // chat_projects
|
|
CheckChatProjectsIconLength CheckConstraint = "chat_projects_icon_length" // chat_projects
|
|
CheckChatProjectsNameLength CheckConstraint = "chat_projects_name_length" // chat_projects
|
|
CheckChatProjectsNameNotBlank CheckConstraint = "chat_projects_name_not_blank" // chat_projects
|
|
CheckChatProjectsUserAclIsObject CheckConstraint = "chat_projects_user_acl_is_object" // chat_projects
|
|
CheckChatUsageLimitConfigDefaultLimitMicrosCheck CheckConstraint = "chat_usage_limit_config_default_limit_micros_check" // chat_usage_limit_config
|
|
CheckChatUsageLimitConfigPeriodCheck CheckConstraint = "chat_usage_limit_config_period_check" // chat_usage_limit_config
|
|
CheckChatUsageLimitConfigSingletonCheck CheckConstraint = "chat_usage_limit_config_singleton_check" // chat_usage_limit_config
|
|
CheckChatUserModelOverridesContextCheck CheckConstraint = "chat_user_model_overrides_context_check" // chat_user_model_overrides
|
|
CheckChatUserModelOverridesModeCheck CheckConstraint = "chat_user_model_overrides_mode_check" // chat_user_model_overrides
|
|
CheckChatUserModelOverridesModelRequiresConfigCheck CheckConstraint = "chat_user_model_overrides_model_requires_config_check" // chat_user_model_overrides
|
|
CheckChatAclOnlyOnRootChats CheckConstraint = "chat_acl_only_on_root_chats" // chats
|
|
CheckChatGroupAclNotNullJsonb CheckConstraint = "chat_group_acl_not_null_jsonb" // chats
|
|
CheckChatUserAclNotNullJsonb CheckConstraint = "chat_user_acl_not_null_jsonb" // chats
|
|
CheckChatsPinOrderArchivedCheck CheckConstraint = "chats_pin_order_archived_check" // chats
|
|
CheckChatsPinOrderParentCheck CheckConstraint = "chats_pin_order_parent_check" // chats
|
|
CheckOneTimePasscodeSet CheckConstraint = "one_time_passcode_set" // users
|
|
CheckUsersChatSpendLimitMicrosCheck CheckConstraint = "users_chat_spend_limit_micros_check" // users
|
|
CheckUsersEmailNotEmpty CheckConstraint = "users_email_not_empty" // users
|
|
CheckUsersServiceAccountLoginType CheckConstraint = "users_service_account_login_type" // users
|
|
CheckUsersUsernameMinLength CheckConstraint = "users_username_min_length" // users
|
|
CheckConnectionLogsClientSessionIDCheck CheckConstraint = "connection_logs_client_session_id_check" // connection_logs
|
|
CheckOrganizationIDNotZero CheckConstraint = "organization_id_not_zero" // custom_roles
|
|
CheckGroupAIBudgetsSpendLimitMicrosCheck CheckConstraint = "group_ai_budgets_spend_limit_micros_check" // group_ai_budgets
|
|
CheckGroupsChatSpendLimitMicrosCheck CheckConstraint = "groups_chat_spend_limit_micros_check" // groups
|
|
CheckMcpServerConfigsAuthTypeCheck CheckConstraint = "mcp_server_configs_auth_type_check" // mcp_server_configs
|
|
CheckMcpServerConfigsAvailabilityCheck CheckConstraint = "mcp_server_configs_availability_check" // mcp_server_configs
|
|
CheckMcpServerConfigsGroupAclIsObject CheckConstraint = "mcp_server_configs_group_acl_is_object" // mcp_server_configs
|
|
CheckMcpServerConfigsOauth2ClientRegistrationCheck CheckConstraint = "mcp_server_configs_oauth2_client_registration_check" // mcp_server_configs
|
|
CheckMcpServerConfigsTransportCheck CheckConstraint = "mcp_server_configs_transport_check" // mcp_server_configs
|
|
CheckMcpServerConfigsUserAclIsObject CheckConstraint = "mcp_server_configs_user_acl_is_object" // mcp_server_configs
|
|
CheckOauth2ProviderAppCodesScopeNotEmpty CheckConstraint = "oauth2_provider_app_codes_scope_not_empty" // oauth2_provider_app_codes
|
|
CheckOauth2ProviderAppTokensScopeNotEmpty CheckConstraint = "oauth2_provider_app_tokens_scope_not_empty" // oauth2_provider_app_tokens
|
|
CheckOauth2ProviderAppsClientTypeCheck CheckConstraint = "oauth2_provider_apps_client_type_check" // oauth2_provider_apps
|
|
CheckMaxProvisionerLogsLength CheckConstraint = "max_provisioner_logs_length" // provisioner_jobs
|
|
CheckNatsPortValidTcp CheckConstraint = "nats_port_valid_tcp" // replicas
|
|
CheckSkillsAclOnlyOnOrganizationSkills CheckConstraint = "skills_acl_only_on_organization_skills" // skills
|
|
CheckSkillsActionProjectOnly CheckConstraint = "skills_action_project_only" // skills
|
|
CheckSkillsContentSize CheckConstraint = "skills_content_size" // skills
|
|
CheckSkillsDescriptionSize CheckConstraint = "skills_description_size" // skills
|
|
CheckSkillsDisplayNameLength CheckConstraint = "skills_display_name_length" // skills
|
|
CheckSkillsDisplayNameProjectOnly CheckConstraint = "skills_display_name_project_only" // skills
|
|
CheckSkillsGroupAclIsObject CheckConstraint = "skills_group_acl_is_object" // skills
|
|
CheckSkillsNameFormat CheckConstraint = "skills_name_format" // skills
|
|
CheckSkillsNameSize CheckConstraint = "skills_name_size" // skills
|
|
CheckSkillsSingleOwner CheckConstraint = "skills_single_owner" // skills
|
|
CheckSkillsUserAclIsObject CheckConstraint = "skills_user_acl_is_object" // skills
|
|
CheckTelemetryLockEventTypeConstraint CheckConstraint = "telemetry_lock_event_type_constraint" // telemetry_locks
|
|
CheckValidationMonotonicOrder CheckConstraint = "validation_monotonic_order" // template_version_parameters
|
|
CheckTemplateVersionsScriptOrderDataSourceCountCheck CheckConstraint = "template_versions_script_order_data_source_count_check" // template_versions
|
|
CheckTemplateVersionsScriptOrderRuleCountCheck CheckConstraint = "template_versions_script_order_rule_count_check" // template_versions
|
|
CheckUsageEventTypeCheck CheckConstraint = "usage_event_type_check" // usage_events
|
|
CheckUsageEventsAgentRuntimeHourAligned CheckConstraint = "usage_events_agent_runtime_hour_aligned" // usage_events
|
|
CheckUserAIBudgetOverridesSpendLimitMicrosCheck CheckConstraint = "user_ai_budget_overrides_spend_limit_micros_check" // user_ai_budget_overrides
|
|
CheckUserAIProviderKeysAPIKeyCheck CheckConstraint = "user_ai_provider_keys_api_key_check" // user_ai_provider_keys
|
|
CheckUserSecretsEnabledRequiresTarget CheckConstraint = "user_secrets_enabled_requires_target" // user_secrets
|
|
CheckWorkspaceAgentScriptsDependenciesIsArray CheckConstraint = "workspace_agent_scripts_dependencies_is_array" // workspace_agent_scripts
|
|
CheckMaxLogsLength CheckConstraint = "max_logs_length" // workspace_agents
|
|
CheckSubsystemsNotNone CheckConstraint = "subsystems_not_none" // workspace_agents
|
|
CheckWorkspaceBuildOrchestrationsAttemptCountCheck CheckConstraint = "workspace_build_orchestrations_attempt_count_check" // workspace_build_orchestrations
|
|
CheckWorkspaceBuildOrchestrationsChildLogLevelCheck CheckConstraint = "workspace_build_orchestrations_child_log_level_check" // workspace_build_orchestrations
|
|
CheckWorkspaceBuildOrchestrationsChildParametersCheck CheckConstraint = "workspace_build_orchestrations_child_parameters_check" // workspace_build_orchestrations
|
|
CheckWorkspaceBuildOrchestrationsChildPresetVersionCheck CheckConstraint = "workspace_build_orchestrations_child_preset_version_check" // workspace_build_orchestrations
|
|
CheckWorkspaceBuildOrchestrationsCompletedChildCheck CheckConstraint = "workspace_build_orchestrations_completed_child_check" // workspace_build_orchestrations
|
|
CheckWorkspaceBuildOrchestrationsNextRetryAfterCheck CheckConstraint = "workspace_build_orchestrations_next_retry_after_check" // workspace_build_orchestrations
|
|
CheckWorkspaceBuildOrchestrationsStatusCheck CheckConstraint = "workspace_build_orchestrations_status_check" // workspace_build_orchestrations
|
|
CheckWorkspaceBuildsDeadlineBelowMaxDeadline CheckConstraint = "workspace_builds_deadline_below_max_deadline" // workspace_builds
|
|
CheckGroupAclIsObject CheckConstraint = "group_acl_is_object" // workspaces
|
|
CheckUserAclIsObject CheckConstraint = "user_acl_is_object" // workspaces
|
|
CheckWorkspaceSecretsRequiresTarget CheckConstraint = "workspace_secrets_requires_target" // workspace_secrets
|
|
CheckWorkspaceSecretsValueCleared CheckConstraint = "workspace_secrets_value_cleared" // workspace_secrets
|
|
)
|