Database
cockroach demo --insecure --no-example-database
Table
CREATE TABLE orders (
"id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
"customer_id" UUID NOT NULL,
"total" DECIMAL NOT NULL,
"ts" TIMESTAMPTZ NOT NULL DEFAULT now()
);
Orders service
(cd 001_fragile_data_integrations/purging_data/before/services/orders && go run main.go)
Data purger service
(cd 001_fragile_data_integrations/purging_data/before/services/purger && go run main.go)
Check number of expired orders
see -n 1 cockroach sql --insecure -e "SELECT COUNT(*) FROM orders
WHERE ts < now() + INTERVAL '5 year'";
Without stopping anything
Add TTL
ALTER TABLE orders SET (
ttl_expiration_expression = '((ts AT TIME ZONE ''UTC'') + INTERVAL ''5 year'') AT TIME ZONE ''UTC''',
ttl_job_cron = '* * * * *'
);
Stop the data purger
make teardown