From 8705b84282b4adcfb5b52a03b47b5cc73fa44bb5 Mon Sep 17 00:00:00 2001 From: Conor Brady Date: Tue, 3 Dec 2024 10:23:31 -0800 Subject: [PATCH] Add if check for existing partition --- openshift/pgslice/docker/partition_and_archive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openshift/pgslice/docker/partition_and_archive.sh b/openshift/pgslice/docker/partition_and_archive.sh index 5f329d8ac..73fc4ed2e 100755 --- a/openshift/pgslice/docker/partition_and_archive.sh +++ b/openshift/pgslice/docker/partition_and_archive.sh @@ -58,7 +58,7 @@ FIRST_DAY_NEXT_MONTH=$(date -d "$(date +%Y-%m-01) next month" +%Y-%m-%d) LAST_DAY_NEXT_MONTH=$(date -d "$(date +%Y-%m-01) next month +1 month -1 day" +%Y-%m-%d) echo "Creating new partition for dates: $FIRST_DAY_NEXT_MONTH to $LAST_DAY_NEXT_MONTH" -NEW_PARTITION_COMMAND="CREATE TABLE ${TABLE}_${NEXT_MONTH_DATE} PARTITION OF $TABLE FOR VALUES FROM ('$FIRST_DAY_NEXT_MONTH') TO ('$LAST_DAY_NEXT_MONTH');" +NEW_PARTITION_COMMAND="CREATE TABLE IF NOT EXISTS ${TABLE}_${NEXT_MONTH_DATE} PARTITION OF $TABLE FOR VALUES FROM ('$FIRST_DAY_NEXT_MONTH') TO ('$LAST_DAY_NEXT_MONTH');" psql -c "$NEW_PARTITION_COMMAND" "$PGSLICE_URL" # Mark tables from 3 months ago to 6 months ago as retired if they exist, then detach and dump them to object store