forked from QueueClassic/queue_classic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_table.sql
More file actions
26 lines (21 loc) · 993 Bytes
/
create_table.sql
File metadata and controls
26 lines (21 loc) · 993 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
do $$ begin
CREATE TABLE queue_classic_jobs (
id bigserial PRIMARY KEY,
q_name text not null check (length(q_name) > 0),
method text not null check (length(method) > 0),
args text not null,
locked_at timestamptz,
locked_by integer,
created_at timestamptz default now(),
scheduled_at timestamptz default now()
);
-- If jsonb type is available, use it for the args column
if exists (select 1 from pg_type where typname = 'jsonb') then
alter table queue_classic_jobs alter column args type jsonb using args::jsonb;
-- Otherwise, use json type for the args column if available
elsif exists (select 1 from pg_type where typname = 'json') then
alter table queue_classic_jobs alter column args type json using args::json;
end if;
end $$ language plpgsql;
CREATE INDEX idx_qc_on_name_only_unlocked ON queue_classic_jobs (q_name, id) WHERE locked_at IS NULL;
CREATE INDEX idx_qc_on_scheduled_at_only_unlocked ON queue_classic_jobs (scheduled_at, id) WHERE locked_at IS NULL;