Files
git.stella-ops.org/devops/scripts/scanner-artifact-boms-retention.sh
2026-02-11 01:32:14 +02:00

35 lines
723 B
Bash

#!/usr/bin/env bash
set -euo pipefail
if [[ -z "${PG_DSN:-}" ]]; then
echo "PG_DSN is required (PostgreSQL connection string)." >&2
exit 1
fi
RETAIN_MONTHS="${1:-12}"
DRY_RUN="${2:-true}"
if ! [[ "${RETAIN_MONTHS}" =~ ^[0-9]+$ ]]; then
echo "retainMonths must be a positive integer." >&2
exit 1
fi
if [[ "${RETAIN_MONTHS}" -lt 1 ]]; then
echo "retainMonths must be >= 1." >&2
exit 1
fi
case "${DRY_RUN}" in
true|false) ;;
*)
echo "dryRun must be 'true' or 'false'." >&2
exit 1
;;
esac
psql "${PG_DSN}" \
--no-psqlrc \
--set ON_ERROR_STOP=on \
--quiet \
--command "SELECT partition_name, dropped FROM scanner.drop_artifact_boms_partitions_older_than(${RETAIN_MONTHS}, ${DRY_RUN});"