From 4c7bdf88e2dc455d583e2eaca38f40ea6b32eac9 Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Fri, 28 May 2021 17:05:09 -0500 Subject: [PATCH] update default retention policy in sql --- docs/usage.md | 40 +++++++++++++++++++++------------------- src/migrationStore.js | 6 ++++-- src/plans.js | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 520b1b07..a98f4576 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -109,25 +109,27 @@ If you need to interact with pg-boss outside of Node.js, such as other clients o The following command is the definition of the primary job table. For manual job creation, the only required column is `name`. All other columns are nullable or have sensible defaults. ```sql - CREATE TABLE ${schema}.job ( - id uuid primary key not null default gen_random_uuid(), - name text not null, - priority integer not null default(0), - data jsonb, - state ${schema}.job_state not null default('${states.created}'), - retryLimit integer not null default(0), - retryCount integer not null default(0), - retryDelay integer not null default(0), - retryBackoff boolean not null default false, - startAfter timestamp with time zone not null default now(), - startedOn timestamp with time zone, - singletonKey text, - singletonOn timestamp without time zone, - expireIn interval not null default interval '15 minutes', - createdOn timestamp with time zone not null default now(), - completedOn timestamp with time zone, - keepUntil timestamp with time zone NOT NULL default now() + interval '30 days' - ) + CREATE TABLE ${schema}.job ( + id uuid primary key not null default gen_random_uuid(), + name text not null, + priority integer not null default(0), + data jsonb, + state ${schema}.job_state not null default('${states.created}'), + retryLimit integer not null default(0), + retryCount integer not null default(0), + retryDelay integer not null default(0), + retryBackoff boolean not null default false, + startAfter timestamp with time zone not null default now(), + startedOn timestamp with time zone, + singletonKey text, + singletonOn timestamp without time zone, + expireIn interval not null default interval '15 minutes', + createdOn timestamp with time zone not null default now(), + completedOn timestamp with time zone, + keepUntil timestamp with time zone NOT NULL default now() + interval '14 days', + on_complete boolean not null default true, + output jsonb + ) ``` # Events diff --git a/src/migrationStore.js b/src/migrationStore.js index f8e0fbce..7bea2902 100644 --- a/src/migrationStore.js +++ b/src/migrationStore.js @@ -78,7 +78,8 @@ function getAll (schema, config) { `CREATE INDEX IF NOT EXISTS job_fetch ON ${schema}.job (name text_pattern_ops, startAfter) WHERE state < 'active'`, `ALTER TABLE ${schema}.job ADD output jsonb`, `ALTER TABLE ${schema}.archive ADD output jsonb`, - `ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT false` + `ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT false`, + `ALTER TABLE ${schema}.job ALTER COLUMN keepuntil SET DEFAULT now() + interval '14 days'` ], uninstall: [ `DROP INDEX ${schema}.job_fetch`, @@ -87,7 +88,8 @@ function getAll (schema, config) { `CREATE UNIQUE INDEX job_singletonKey ON ${schema}.job (name, singletonKey) WHERE state < 'completed' AND singletonOn IS NULL`, `ALTER TABLE ${schema}.job DROP COLUMN output`, `ALTER TABLE ${schema}.archive DROP COLUMN output`, - `ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT true` + `ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT true`, + `ALTER TABLE ${schema}.job ALTER COLUMN keepuntil SET DEFAULT now() + interval '30 days'` ] }, { diff --git a/src/plans.js b/src/plans.js index 38785b8d..05e014c9 100644 --- a/src/plans.js +++ b/src/plans.js @@ -164,7 +164,7 @@ function createJobTable (schema) { expireIn interval not null default interval '15 minutes', createdOn timestamp with time zone not null default now(), completedOn timestamp with time zone, - keepUntil timestamp with time zone NOT NULL default now() + interval '30 days', + keepUntil timestamp with time zone NOT NULL default now() + interval '14 days', on_complete boolean not null default true, output jsonb )