StaticdeployDeploys the prune() Postgres function into the target schema.
Also runs schema migrations (e.g., adding pruned_at column).
Idempotent — uses CREATE OR REPLACE and IF NOT EXISTS.
The function is automatically deployed when DBA.prune is called, but this method is exposed for explicit control (e.g., CI/CD migration scripts that provision database objects before the application starts).
Postgres provider configuration
Application identifier (schema name)
StaticprunePrunes expired data and/or strips execution artifacts from completed jobs. Each operation is independently controlled, so callers can target a single table per cron schedule.
Operations (each enabled individually):
entities when set.adata,
hmark, status, other) from completed, un-pruned jobs.
Preserves jdata, udata, and jmark. Marks stripped
jobs with pruned_at for idempotency.entity IS NULLPrune configuration
Counts of deleted/stripped rows
import { Client as Postgres } from 'pg';
import { DBA } from '@hotmeshio/hotmesh';
// Strip attributes from 'book' entities only
await DBA.prune({
appId: 'myapp',
connection: {
class: Postgres,
options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
},
jobs: false,
streams: false,
attributes: true,
entities: ['book'],
});
Database maintenance operations for HotMesh's Postgres backend.
HotMesh uses soft-delete patterns: expired jobs and stream messages retain their rows with
expired_atset but are never physically removed during normal operation. Over time, three tables accumulate dead rows:{appId}.jobsexpired_atset{appId}.jobs_attributesadata,hmark,status,other) that are only needed during workflow execution{appId}.engine_streamsexpired_atset{appId}.worker_streamsexpired_atsetThe
DBAservice addresses this with two methods:Attribute stripping preserves export history
Stripping removes
adata,hmark,status, andotherattributes from completed jobs while preserving:jdata— workflow return dataudata— user-searchable datajmark— timeline markers needed for workflow execution exportSet
keepHmark: trueto also preservehmark(activity state markers).Entity-scoped pruning
Use
entitiesto restrict pruning/stripping to specific entity types (e.g.,['book', 'author']). UsepruneTransientto delete expired jobs with no entity (entity IS NULL).Idempotent stripping with
pruned_atAfter stripping, jobs are marked with
pruned_at = NOW(). Subsequent prune calls skip already-pruned jobs, making the operation idempotent and efficient for repeated scheduling.Independent cron schedules (TypeScript)
Example
Direct SQL (schedulable via pg_cron)
The underlying Postgres function can be called directly, without the TypeScript SDK. The first 4 parameters are backwards-compatible: