-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38b5c93
commit e0c827a
Showing
1 changed file
with
12 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
CREATE TABLE queue ( | ||
id BIGSERIAL PRIMARY KEY, | ||
id BIGSERIAL, | ||
status status NOT NULL DEFAULT 'ready', | ||
item JSONB NOT NULL, | ||
-- Can't have foreign key relations to hypertables, so recreate the constraints as best as possible | ||
parent BIGINT DEFAULT NULL CHECK (parent IS NULL OR parent > 0), | ||
-- Error message in case of permanent failure. If set, status MUST be 'failed'. | ||
message TEXT CHECK (((message IS NULL) AND (status != 'failed'::status)) OR ((message IS NOT NULL) AND (status = 'failed'::status))), | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT now() | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
PRIMARY KEY (id, created_at) | ||
); | ||
|
||
CREATE INDEX index_queue_status ON queue (status); | ||
CREATE INDEX index_queue_id ON queue (id); | ||
|
||
CREATE INDEX idx_queue_id_created ON queue (created_at); | ||
CREATE INDEX index_queue_status_id ON queue (status, id); | ||
|
||
SELECT create_hypertable('queue', 'id'); | ||
SELECT create_hypertable('queue', 'created_at'); | ||
|
||
SELECT add_retention_policy('queue', INTERVAL '60 days'); | ||
|
||
ALTER TABLE queue SET (timescaledb.compress, timescaledb.compress_orderby = 'created_at DESC', timescaledb.compress_segmentby = 'id'); | ||
|
||
SELECT add_compression_policy('queue', compress_after => INTERVAL '14 days'); |