-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sql
More file actions
37 lines (35 loc) · 912 Bytes
/
setup.sql
File metadata and controls
37 lines (35 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- 1. Table for Metadata & Queue
create table images (
id uuid default gen_random_uuid() primary key,
download_url text unique not null,
page_url text,
preview_url text,
motive text,
place text,
date text,
image_width int,
image_height int,
status text default 'pending', -- pending, processing, indexed, failed
created_at timestamp with time zone default now()
);
-- 2. Indexes for speed
create index idx_images_status on images(status);
create index idx_images_download on images(download_url);
-- 3. Atomic change
-- Allows a worker to atomically claim N images
create or replace function get_pending_images(limit_count int)
returns setof images
language sql
as $$
update images
set status = 'processing'
where id in (
select id
from images
where status = 'pending'
order by created_at desc
limit limit_count
for update skip locked
)
returning *;
$$;