Skip to content

Commit

Permalink
Change json datatype to jsonb, if available. Otherwise fall back to j…
Browse files Browse the repository at this point in the history
…son or text.

Signed-off-by: Clemens Gruber <[email protected]>
  • Loading branch information
clemensg committed Jun 12, 2015
1 parent e66a305 commit c988d96
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ All configuration takes place in the form of environment vars. See [queue_classi

## JSON

If you are running PostgreSQL 9.2 or higher, queue_classic will use the [json](http://www.postgresql.org/docs/9.2/static/datatype-json.html) datatype for storing arguments. Versions 9.1 and lower will use the 'text' column. If you have installed queue_classic prior to version 2.1.4 and are running PostgreSQL >= 9.2, run the following to switch to using the json type:
If you are running PostgreSQL 9.4 or higher, queue_classic will use the [jsonb](http://www.postgresql.org/docs/9.4/static/datatype-json.html) datatype for new tables. Versions 9.2 and 9.3 will use the `json` data type and versions 9.1 and lower will use the `text` data type.
If you are updating queue_classic and are running PostgreSQL >= 9.4, run the following to switch to using `jsonb`:
```
alter table queue_classic_jobs alter column args type json using (args::json);
alter table queue_classic_jobs alter column args type jsonb using (args::jsonb);
```

## Logging
Expand Down
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased
- Fixed a bug in the offset calculation of `.enqueue_at`.
- Use the jsonb type for the args column from now on. If not available, fall back to json or text.

Version 3.0.0rc
- Improved signal handling
Expand Down
10 changes: 6 additions & 4 deletions sql/create_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ CREATE TABLE queue_classic_jobs (
scheduled_at timestamptz default now()
);

-- If json type is available, use it for the args column.
perform * from pg_type where typname = 'json';
if found then
alter table queue_classic_jobs alter column args type json using (args::json);
-- 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;
Expand Down

0 comments on commit c988d96

Please sign in to comment.