Merged in feature/chatbot1 (pull request #223)
Chatbot functionality * baseline working * missing test file * more tests
This commit is contained in:
@@ -195,6 +195,82 @@ func (q *Queries) GetCurrentDocumentCustomMetadata(ctx context.Context, document
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const getCurrentDocumentCustomMetadataForClient = `-- name: GetCurrentDocumentCustomMetadataForClient :one
|
||||
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 = $1
|
||||
AND d.clientId = $2
|
||||
ORDER BY dcm.version DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type GetCurrentDocumentCustomMetadataForClientParams struct {
|
||||
DocumentID uuid.UUID `db:"document_id"`
|
||||
ClientID string `db:"client_id"`
|
||||
}
|
||||
|
||||
type GetCurrentDocumentCustomMetadataForClientRow struct {
|
||||
ID uuid.UUID `db:"id"`
|
||||
DocumentID uuid.UUID `db:"document_id"`
|
||||
Metadata []byte `db:"metadata"`
|
||||
Version int32 `db:"version"`
|
||||
CreatedAt pgtype.Timestamptz `db:"created_at"`
|
||||
CreatedBy string `db:"created_by"`
|
||||
SchemaID *uuid.UUID `db:"schema_id"`
|
||||
SchemaName *string `db:"schema_name"`
|
||||
SchemaVersion *int32 `db:"schema_version"`
|
||||
}
|
||||
|
||||
// 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 = $1
|
||||
// AND d.clientId = $2
|
||||
// ORDER BY dcm.version DESC
|
||||
// LIMIT 1
|
||||
func (q *Queries) GetCurrentDocumentCustomMetadataForClient(ctx context.Context, arg *GetCurrentDocumentCustomMetadataForClientParams) (*GetCurrentDocumentCustomMetadataForClientRow, error) {
|
||||
row := q.db.QueryRow(ctx, getCurrentDocumentCustomMetadataForClient, arg.DocumentID, arg.ClientID)
|
||||
var i GetCurrentDocumentCustomMetadataForClientRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DocumentID,
|
||||
&i.Metadata,
|
||||
&i.Version,
|
||||
&i.CreatedAt,
|
||||
&i.CreatedBy,
|
||||
&i.SchemaID,
|
||||
&i.SchemaName,
|
||||
&i.SchemaVersion,
|
||||
)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const getDocumentClientID = `-- name: GetDocumentClientID :one
|
||||
SELECT clientId FROM documents WHERE id = $1
|
||||
`
|
||||
@@ -353,6 +429,34 @@ func (q *Queries) GetDocumentCustomSchemaId(ctx context.Context, id uuid.UUID) (
|
||||
return custom_schema_id, err
|
||||
}
|
||||
|
||||
const getDocumentCustomSchemaIdForClient = `-- name: GetDocumentCustomSchemaIdForClient :one
|
||||
SELECT custom_schema_id
|
||||
FROM documents
|
||||
WHERE id = $1
|
||||
AND clientId = $2
|
||||
`
|
||||
|
||||
type GetDocumentCustomSchemaIdForClientParams struct {
|
||||
ID uuid.UUID `db:"id"`
|
||||
ClientID string `db:"client_id"`
|
||||
}
|
||||
|
||||
// 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 = $1
|
||||
// AND clientId = $2
|
||||
func (q *Queries) GetDocumentCustomSchemaIdForClient(ctx context.Context, arg *GetDocumentCustomSchemaIdForClientParams) (*uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentCustomSchemaIdForClient, arg.ID, arg.ClientID)
|
||||
var custom_schema_id *uuid.UUID
|
||||
err := row.Scan(&custom_schema_id)
|
||||
return custom_schema_id, err
|
||||
}
|
||||
|
||||
const getDocumentSchemaBindingForReset = `-- name: GetDocumentSchemaBindingForReset :one
|
||||
SELECT
|
||||
d.custom_schema_id,
|
||||
|
||||
Reference in New Issue
Block a user