mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-21 10:03:23 +00:00
634fc66e9f
- Update all SQL queries to add missing columns - Update the create conversation API to allow setting the initiator of a conversation. For example, we might want to use this API to create a conversation on behalf of a customer, with the first message coming from the customer instead of the agent. This param allows this. - Minor refactors and clean up - Tidy go.mod - Rename structs to reflect purpose - Create focus structs for scanning JSON payloads for clarity.
54 lines
1.4 KiB
SQL
54 lines
1.4 KiB
SQL
-- name: insert-media
|
|
INSERT INTO media (store, filename, content_type, size, meta, model_id, model_type, disposition, content_id, uuid)
|
|
VALUES(
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
NULLIF($6, 0),
|
|
NULLIF($7, ''),
|
|
$8,
|
|
$9,
|
|
$10
|
|
)
|
|
RETURNING id;
|
|
|
|
-- name: get-media
|
|
SELECT id, created_at, updated_at, "uuid", store, filename, content_type, content_id, model_id, model_type, disposition, "size", meta
|
|
FROM media
|
|
WHERE
|
|
($1 > 0 AND id = $1)
|
|
OR
|
|
($2 != '' AND uuid = $2::uuid)
|
|
|
|
-- name: get-media-by-uuid
|
|
SELECT id, created_at, updated_at, "uuid", store, filename, content_type, content_id, model_id, model_type, disposition, "size", meta
|
|
FROM media
|
|
WHERE uuid = $1;
|
|
|
|
-- name: delete-media
|
|
DELETE FROM media
|
|
WHERE uuid = $1;
|
|
|
|
-- name: attach-to-model
|
|
UPDATE media
|
|
SET model_type = $2,
|
|
model_id = $3
|
|
WHERE id = $1;
|
|
|
|
-- name: get-model-media
|
|
SELECT id, created_at, updated_at, "uuid", store, filename, content_type, content_id, model_id, model_type, disposition, "size", meta
|
|
FROM media
|
|
WHERE model_type = $1
|
|
AND model_id = $2;
|
|
|
|
-- name: get-unlinked-message-media
|
|
SELECT id, created_at, updated_at, "uuid", store, filename, content_type, content_id, model_id, model_type, disposition, "size", meta
|
|
FROM media
|
|
WHERE model_type = 'messages'
|
|
AND (model_id IS NULL OR model_id = 0)
|
|
AND created_at < NOW() - INTERVAL '1 day';
|
|
|
|
-- name: content-id-exists
|
|
SELECT uuid FROM media WHERE content_id = $1; |