From a69a69e4b0d719fd38e07091ee22db711b9d38ef Mon Sep 17 00:00:00 2001 From: joe miller Date: Sun, 5 Jan 2025 16:50:19 +0000 Subject: [PATCH] script: add sweep script and make task --- GNUmakefile | 10 +++++++++- script/sweep | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 script/sweep diff --git a/GNUmakefile b/GNUmakefile index 5d714bb..96dae71 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,5 +1,9 @@ default: testacc +.PHONY: build +build: + CGO_ENABLED=0 go build -v -trimpath . + .PHONY: lint lint: golangci-lint run -v ./... @@ -13,4 +17,8 @@ testacc: generate: bash ./script/update_openapi_spec bash ./script/generate - go generate ./... \ No newline at end of file + go generate ./... + +.PHONY: sweep +sweep: + bash ./script/sweep \ No newline at end of file diff --git a/script/sweep b/script/sweep new file mode 100755 index 0000000..c6b4b76 --- /dev/null +++ b/script/sweep @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# delete db's older than 24 hours in the test org whose name starts with "testacc" + +set -eou pipefail + +ORG="${ORG:-planetscale-terraform-testing}" + +pscale database list --org "$ORG" --format json | + jq -r '.[] | select( + (.name | startswith("testacc")) and + (.created_at | sub("\\.\\d+"; "") | fromdateiso8601 < (now - 86400))).name' | + while read -r dbname; do + pscale database delete "$dbname" --org "$ORG" --force + done