Adds the storage and authorization layer for chat project skills. The `skills` table already allows a `project_id` owner (migration 000621); this adds the queries for it and authorizes them through the parent chat project, the same way project instructions work. - New queries in `skills.sql`: insert, get by name, list metadata, update (COALESCE on description, content and enabled), delete, and `GetProjectSkillByIDForUpdate` for the shared update lock. - dbauthz checks `chat_project:read` on the project for reads and `chat_project:update` for writes. `authorizeChatProjectInstructions` became `authorizeChatProjectConfig`, shared by instructions and skills. `Skill.RBACObject()` still denies project rows so nothing reaches them without going through the project. - Audit: new `chat_project_skill` resource type (enum-only migration 000624), `AuditableChatProjectSkill`, and the usual diff/request/table/FriendlyString/AuditFilter wiring. The API that emits these entries comes in the next PR. Stack (merge top to bottom): - #30826 👈 - #30827 - #30838 - #30840 - #30854 - #30855 - #30856 - #30861 - #30880 - #30881 - #30882 - #30884
119 lines
3.7 KiB
SQL
119 lines
3.7 KiB
SQL
-- name: InsertUserSkill :one
|
|
INSERT INTO skills (id, user_id, name, description, content)
|
|
VALUES (@id::uuid, @user_id::uuid, @name::text, @description::text, @content::text)
|
|
RETURNING *;
|
|
|
|
-- name: GetUserSkillByUserIDAndName :one
|
|
SELECT *
|
|
FROM skills
|
|
WHERE user_id = @user_id::uuid AND name = @name;
|
|
|
|
-- name: ListUserSkillMetadataByUserID :many
|
|
SELECT
|
|
id, user_id, name, description, enabled, created_at, updated_at
|
|
FROM skills
|
|
WHERE user_id = @user_id::uuid
|
|
ORDER BY name ASC;
|
|
|
|
-- name: UpdateUserSkillByUserIDAndName :one
|
|
UPDATE skills
|
|
SET
|
|
description = COALESCE(sqlc.narg('description')::text, description),
|
|
content = COALESCE(sqlc.narg('content')::text, content),
|
|
enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled),
|
|
updated_at = now()
|
|
WHERE user_id = @user_id::uuid AND name = @name
|
|
RETURNING *;
|
|
|
|
-- name: DeleteUserSkillByUserIDAndName :one
|
|
DELETE FROM skills
|
|
WHERE user_id = @user_id::uuid AND name = @name
|
|
RETURNING *;
|
|
|
|
-- name: InsertOrganizationSkill :one
|
|
INSERT INTO skills (id, organization_id, name, description, content, group_acl, user_acl)
|
|
VALUES (@id::uuid, @organization_id::uuid, @name::text, @description::text, @content::text, @group_acl, @user_acl)
|
|
RETURNING *;
|
|
|
|
-- name: GetOrganizationSkillByOrganizationIDAndName :one
|
|
SELECT *
|
|
FROM skills
|
|
WHERE organization_id = @organization_id::uuid AND name = @name;
|
|
|
|
-- name: ListOrganizationSkillMetadataByOrganizationID :many
|
|
SELECT
|
|
id, organization_id, name, description, enabled, created_at, updated_at
|
|
FROM skills
|
|
WHERE organization_id = @organization_id::uuid
|
|
-- Authorize Filter clause will be injected below in GetAuthorizedOrganizationSkillMetadata
|
|
-- @authorize_filter
|
|
ORDER BY name ASC;
|
|
|
|
-- name: UpdateOrganizationSkillByOrganizationIDAndName :one
|
|
UPDATE skills
|
|
SET
|
|
description = COALESCE(sqlc.narg('description')::text, description),
|
|
content = COALESCE(sqlc.narg('content')::text, content),
|
|
enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled),
|
|
updated_at = now()
|
|
WHERE organization_id = @organization_id::uuid AND name = @name
|
|
RETURNING *;
|
|
|
|
-- name: DeleteOrganizationSkillByOrganizationIDAndName :one
|
|
DELETE FROM skills
|
|
WHERE organization_id = @organization_id::uuid AND name = @name
|
|
RETURNING *;
|
|
|
|
-- name: GetOrganizationSkillByIDForUpdate :one
|
|
SELECT *
|
|
FROM skills
|
|
WHERE id = @id::uuid AND organization_id IS NOT NULL
|
|
FOR UPDATE;
|
|
|
|
-- name: UpdateOrganizationSkillACLByID :one
|
|
UPDATE skills
|
|
SET
|
|
group_acl = @group_acl,
|
|
user_acl = @user_acl,
|
|
updated_at = now()
|
|
WHERE id = @id::uuid AND organization_id IS NOT NULL
|
|
RETURNING *;
|
|
|
|
-- name: InsertProjectSkill :one
|
|
INSERT INTO skills (id, project_id, name, description, content)
|
|
VALUES (@id::uuid, @project_id::uuid, @name::text, @description::text, @content::text)
|
|
RETURNING *;
|
|
|
|
-- name: GetProjectSkillByProjectIDAndName :one
|
|
SELECT *
|
|
FROM skills
|
|
WHERE project_id = @project_id::uuid AND name = @name;
|
|
|
|
-- name: ListProjectSkillMetadataByProjectID :many
|
|
SELECT
|
|
id, project_id, name, description, enabled, created_at, updated_at
|
|
FROM skills
|
|
WHERE project_id = @project_id::uuid
|
|
ORDER BY name ASC;
|
|
|
|
-- name: UpdateProjectSkillByProjectIDAndName :one
|
|
UPDATE skills
|
|
SET
|
|
description = COALESCE(sqlc.narg('description')::text, description),
|
|
content = COALESCE(sqlc.narg('content')::text, content),
|
|
enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled),
|
|
updated_at = now()
|
|
WHERE project_id = @project_id::uuid AND name = @name
|
|
RETURNING *;
|
|
|
|
-- name: DeleteProjectSkillByProjectIDAndName :one
|
|
DELETE FROM skills
|
|
WHERE project_id = @project_id::uuid AND name = @name
|
|
RETURNING *;
|
|
|
|
-- name: GetProjectSkillByIDForUpdate :one
|
|
SELECT *
|
|
FROM skills
|
|
WHERE id = @id::uuid AND project_id IS NOT NULL
|
|
FOR UPDATE;
|