Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change json datatype to jsonb #257

Merged
merged 1 commit into from
Jun 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `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