Merged in feature/chatbot1 (pull request #223)
Chatbot functionality * baseline working * missing test file * more tests
This commit is contained in:
@@ -120,6 +120,39 @@ SELECT custom_schema_id
|
||||
FROM documents
|
||||
WHERE id = @id;
|
||||
|
||||
-- name: GetDocumentCustomSchemaIdForClient :one
|
||||
-- Chatbot-scoped variant of GetDocumentCustomSchemaId: adds a clientId
|
||||
-- filter so cross-client lookups miss with pgx.ErrNoRows. Same scalar
|
||||
-- result type (nullable uuid) as the non-scoped query — only the WHERE
|
||||
-- clause differs. Plan §5.
|
||||
SELECT custom_schema_id
|
||||
FROM documents
|
||||
WHERE id = @id
|
||||
AND clientId = @client_id;
|
||||
|
||||
-- name: GetCurrentDocumentCustomMetadataForClient :one
|
||||
-- Chatbot-scoped variant of GetCurrentDocumentCustomMetadata. Same column
|
||||
-- set (the metadata row decorated with schema id/name/version), but the
|
||||
-- joined documents row must belong to @client_id; cross-client calls miss
|
||||
-- with pgx.ErrNoRows. Plan §5.
|
||||
SELECT
|
||||
dcm.id,
|
||||
dcm.document_id,
|
||||
dcm.metadata,
|
||||
dcm.version,
|
||||
dcm.created_at,
|
||||
dcm.created_by,
|
||||
cms.id AS schema_id,
|
||||
cms.name AS schema_name,
|
||||
cms.version AS schema_version
|
||||
FROM document_custom_metadata dcm
|
||||
JOIN documents d ON d.id = dcm.document_id
|
||||
LEFT JOIN client_metadata_schemas cms ON cms.id = d.custom_schema_id
|
||||
WHERE dcm.document_id = @document_id
|
||||
AND d.clientId = @client_id
|
||||
ORDER BY dcm.version DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- name: GetDocumentClientID :one
|
||||
-- Read a document's clientId for the AssignSchema cross-client check.
|
||||
-- documents.clientId is the unquoted (lowercased) varchar column.
|
||||
|
||||
Reference in New Issue
Block a user