V3 version with backward comp
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
-- name: GetFile :one
|
||||
SELECT * FROM files
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: ListFiles :many
|
||||
SELECT * FROM files
|
||||
WHERE parent_file_id IS NULL
|
||||
ORDER BY is_folder DESC, created_at DESC;
|
||||
|
||||
-- name: ListFolders :many
|
||||
SELECT * FROM files
|
||||
WHERE is_folder = true
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: ListFilesByID :many
|
||||
SELECT * FROM files
|
||||
WHERE id = ANY($1::text[])
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: CreateFile :one
|
||||
INSERT INTO files (name, mime_type, size, storage_key, checksum, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: CreateFolder :one
|
||||
INSERT INTO files (name, is_folder, created_at, updated_at)
|
||||
VALUES ($1, true, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: ListFilesByParentID :many
|
||||
SELECT * FROM files
|
||||
WHERE parent_file_id = $1
|
||||
ORDER BY is_folder DESC, created_at DESC;
|
||||
|
||||
-- name: MoveFiles :exec
|
||||
UPDATE files
|
||||
SET parent_file_id = $1, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ANY($2::text[]);
|
||||
|
||||
-- name: UpdateFile :exec
|
||||
UPDATE files
|
||||
SET name = $1, mime_type = $2, ocr_text = $3, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $4;
|
||||
|
||||
-- name: DeleteFile :exec
|
||||
DELETE FROM files
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: FindDuplicatesByNameSize :many
|
||||
SELECT id, name, mime_type, size, checksum, created_at FROM files
|
||||
WHERE name = $1 AND size = $2 AND is_folder = false
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: FindDuplicateByChecksum :one
|
||||
SELECT * FROM files
|
||||
WHERE checksum = $1 AND is_folder = false
|
||||
LIMIT 1;
|
||||
@@ -0,0 +1,36 @@
|
||||
-- name: CreateRebacRelation :one
|
||||
INSERT INTO rebac_relations (resource_id, subject_user_id, role, granted_by)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetRebacRelation :one
|
||||
SELECT * FROM rebac_relations
|
||||
WHERE resource_id = $1 AND subject_user_id = $2
|
||||
LIMIT 1;
|
||||
|
||||
-- name: ListRebacRelationsByResource :many
|
||||
SELECT * FROM rebac_relations
|
||||
WHERE resource_id = $1
|
||||
ORDER BY created_at ASC;
|
||||
|
||||
-- name: ListRebacRelationsBySubject :many
|
||||
SELECT * FROM rebac_relations
|
||||
WHERE subject_user_id = $1
|
||||
ORDER BY created_at ASC;
|
||||
|
||||
-- name: DeleteRebacRelation :exec
|
||||
DELETE FROM rebac_relations
|
||||
WHERE resource_id = $1 AND subject_user_id = $2;
|
||||
|
||||
-- name: DeleteRebacRelationsByResource :exec
|
||||
DELETE FROM rebac_relations
|
||||
WHERE resource_id = $1;
|
||||
|
||||
-- name: HasRebacRelation :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM rebac_relations
|
||||
WHERE resource_id = $1 AND subject_user_id = $2 AND role = $3
|
||||
);
|
||||
|
||||
-- name: ResolveEffectiveRole :one
|
||||
SELECT resolve_effective_role($1, $2) AS role;
|
||||
@@ -0,0 +1,32 @@
|
||||
-- name: CreatePlacement :one
|
||||
INSERT INTO resource_placements (resource_id, storage_location_id, status, storage_key, synced_at)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetPlacement :one
|
||||
SELECT * FROM resource_placements
|
||||
WHERE resource_id = $1 AND storage_location_id = $2
|
||||
LIMIT 1;
|
||||
|
||||
-- name: ListPlacementsByResource :many
|
||||
SELECT * FROM resource_placements
|
||||
WHERE resource_id = $1;
|
||||
|
||||
-- name: ListPlacementsByLocation :many
|
||||
SELECT * FROM resource_placements
|
||||
WHERE storage_location_id = $1;
|
||||
|
||||
-- name: UpdatePlacementStatus :exec
|
||||
UPDATE resource_placements
|
||||
SET status = $1, synced_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $2;
|
||||
|
||||
-- name: DeletePlacement :exec
|
||||
DELETE FROM resource_placements
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: GetServerPlacementByResource :one
|
||||
SELECT rp.* FROM resource_placements rp
|
||||
JOIN storage_locations sl ON sl.id = rp.storage_location_id
|
||||
WHERE rp.resource_id = $1 AND sl.role = 'server'
|
||||
LIMIT 1;
|
||||
@@ -0,0 +1,21 @@
|
||||
-- name: CreateResourceVariant :one
|
||||
INSERT INTO resource_variants (resource_id, variant_type, page_number, width, height, mime_type, generated_by, storage_key)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetVariantsByResourceID :many
|
||||
SELECT * FROM resource_variants
|
||||
WHERE resource_id = $1
|
||||
ORDER BY page_number ASC, variant_type ASC;
|
||||
|
||||
-- name: GetVariantByID :one
|
||||
SELECT * FROM resource_variants
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: DeleteVariantsByResourceID :exec
|
||||
DELETE FROM resource_variants WHERE resource_id = $1;
|
||||
|
||||
-- name: GetBestVariant :one
|
||||
SELECT * FROM resource_variants
|
||||
WHERE resource_id = $1 AND variant_type = $2 AND page_number = 1
|
||||
LIMIT 1;
|
||||
@@ -0,0 +1,67 @@
|
||||
-- name: GetResource :one
|
||||
SELECT * FROM resources
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: ListResources :many
|
||||
SELECT * FROM resources
|
||||
WHERE parent_resource_id IS NULL
|
||||
ORDER BY is_folder DESC, created_at DESC;
|
||||
|
||||
-- name: ListFolders :many
|
||||
SELECT * FROM resources
|
||||
WHERE is_folder = true
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: ListResourcesByID :many
|
||||
SELECT * FROM resources
|
||||
WHERE id = ANY($1::uuid[])
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: CreateResource :one
|
||||
INSERT INTO resources (name, mime_type, size, checksum, owner_id, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: CreateFolder :one
|
||||
INSERT INTO resources (name, is_folder, owner_id, created_at, updated_at)
|
||||
VALUES ($1, true, $2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: ListResourcesByParentID :many
|
||||
SELECT * FROM resources
|
||||
WHERE parent_resource_id = $1
|
||||
ORDER BY is_folder DESC, created_at DESC;
|
||||
|
||||
-- name: MoveResources :exec
|
||||
UPDATE resources
|
||||
SET parent_resource_id = $1, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ANY($2::uuid[]);
|
||||
|
||||
-- name: UpdateResource :exec
|
||||
UPDATE resources
|
||||
SET name = $1, mime_type = $2, ocr_text = $3, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $4;
|
||||
|
||||
-- name: DeleteResource :exec
|
||||
DELETE FROM resources
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: FindDuplicatesByNameSize :many
|
||||
SELECT id, name, mime_type, size, checksum, created_at FROM resources
|
||||
WHERE name = $1 AND size = $2 AND is_folder = false
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: FindDuplicateByChecksum :one
|
||||
SELECT * FROM resources
|
||||
WHERE checksum = $1 AND is_folder = false AND owner_id = $2
|
||||
LIMIT 1;
|
||||
|
||||
-- name: ListResourcesByOwner :many
|
||||
SELECT * FROM resources
|
||||
WHERE owner_id = $1 AND parent_resource_id IS NULL
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: ListResourcesByParentAndOwner :many
|
||||
SELECT * FROM resources
|
||||
WHERE parent_resource_id = $1 AND owner_id = $2
|
||||
ORDER BY is_folder DESC, created_at DESC;
|
||||
@@ -0,0 +1,20 @@
|
||||
-- name: CreateRetentionPolicy :one
|
||||
INSERT INTO retention_policies (user_id, storage_location_id, rule_type, rule_value)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetRetentionPolicy :one
|
||||
SELECT * FROM retention_policies
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListRetentionPoliciesByUser :many
|
||||
SELECT * FROM retention_policies
|
||||
WHERE user_id = $1;
|
||||
|
||||
-- name: ListRetentionPoliciesByLocation :many
|
||||
SELECT * FROM retention_policies
|
||||
WHERE storage_location_id = $1;
|
||||
|
||||
-- name: DeleteRetentionPolicy :exec
|
||||
DELETE FROM retention_policies
|
||||
WHERE id = $1;
|
||||
@@ -0,0 +1,27 @@
|
||||
-- name: CreateStorageLocation :one
|
||||
INSERT INTO storage_locations (user_id, device_name, role)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetStorageLocation :one
|
||||
SELECT * FROM storage_locations
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListStorageLocationsByUser :many
|
||||
SELECT * FROM storage_locations
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at ASC;
|
||||
|
||||
-- name: GetServerStorageLocation :one
|
||||
SELECT * FROM storage_locations
|
||||
WHERE user_id = $1 AND role = 'server'
|
||||
LIMIT 1;
|
||||
|
||||
-- name: UpdateStorageLocationLastSeen :exec
|
||||
UPDATE storage_locations
|
||||
SET last_seen_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: DeleteStorageLocation :exec
|
||||
DELETE FROM storage_locations
|
||||
WHERE id = $1;
|
||||
@@ -0,0 +1,27 @@
|
||||
-- name: CreateSyncQueueItem :one
|
||||
INSERT INTO sync_queue (resource_id, storage_location_id, operation, status, attempts)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetSyncQueueItem :one
|
||||
SELECT * FROM sync_queue
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListPendingSyncItems :many
|
||||
SELECT * FROM sync_queue
|
||||
WHERE status = 'pending'
|
||||
ORDER BY created_at ASC;
|
||||
|
||||
-- name: ListPendingSyncItemsByLocation :many
|
||||
SELECT * FROM sync_queue
|
||||
WHERE storage_location_id = $1 AND status = 'pending'
|
||||
ORDER BY created_at ASC;
|
||||
|
||||
-- name: UpdateSyncQueueStatus :exec
|
||||
UPDATE sync_queue
|
||||
SET status = $1, attempts = $2, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $3;
|
||||
|
||||
-- name: DeleteSyncQueueItem :exec
|
||||
DELETE FROM sync_queue
|
||||
WHERE id = $1;
|
||||
@@ -1,6 +1,6 @@
|
||||
-- name: CreateTag :one
|
||||
INSERT INTO tags (tag_name, tag_type)
|
||||
VALUES ($1, $2)
|
||||
INSERT INTO tags (tag_name)
|
||||
VALUES ($1)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetTag :one
|
||||
@@ -19,23 +19,23 @@ ORDER BY tag_name ASC;
|
||||
DELETE FROM tags
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: AddTagToFile :exec
|
||||
INSERT INTO file_tags (tag_id, file_id)
|
||||
-- name: AddTagToResource :exec
|
||||
INSERT INTO resource_tags (tag_id, resource_id)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
-- name: RemoveTagFromFile :exec
|
||||
DELETE FROM file_tags
|
||||
WHERE tag_id = $1 AND file_id = $2;
|
||||
-- name: RemoveTagFromResource :exec
|
||||
DELETE FROM resource_tags
|
||||
WHERE tag_id = $1 AND resource_id = $2;
|
||||
|
||||
-- name: GetTagsByFileID :many
|
||||
-- name: GetTagsByResourceID :many
|
||||
SELECT t.* FROM tags t
|
||||
JOIN file_tags ft ON t.id = ft.tag_id
|
||||
WHERE ft.file_id = $1
|
||||
JOIN resource_tags rt ON t.id = rt.tag_id
|
||||
WHERE rt.resource_id = $1
|
||||
ORDER BY t.tag_name ASC;
|
||||
|
||||
-- name: GetFilesByTagID :many
|
||||
SELECT f.* FROM files f
|
||||
JOIN file_tags ft ON f.id = ft.file_id
|
||||
WHERE ft.tag_id = $1
|
||||
ORDER BY f.created_at DESC;
|
||||
-- name: GetResourcesByTagID :many
|
||||
SELECT r.* FROM resources r
|
||||
JOIN resource_tags rt ON r.id = rt.resource_id
|
||||
WHERE rt.tag_id = $1
|
||||
ORDER BY r.created_at DESC;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
-- name: CreateThumbnail :one
|
||||
INSERT INTO thumbnails (file_id, page_number, resolution_label, width, height, storage_key, mime_type)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetThumbnailsByFileID :many
|
||||
SELECT * FROM thumbnails
|
||||
WHERE file_id = $1
|
||||
ORDER BY page_number ASC, resolution_label ASC;
|
||||
|
||||
-- name: GetThumbnailByID :one
|
||||
SELECT * FROM thumbnails
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: DeleteThumbnailsByFileID :exec
|
||||
DELETE FROM thumbnails WHERE file_id = $1;
|
||||
|
||||
-- name: GetThumbnailByFilePageResolution :one
|
||||
SELECT * FROM thumbnails
|
||||
WHERE file_id = $1 AND page_number = $2 AND resolution_label = $3
|
||||
LIMIT 1;
|
||||
Reference in New Issue
Block a user