From 8235d3cfd47bf5cac2d6428117d1d5a5b5084f02 Mon Sep 17 00:00:00 2001 From: Conor Brady Date: Tue, 3 Dec 2024 11:00:13 -0800 Subject: [PATCH] Add if check for existing partition (#4152) If table has already been created, the partitioning script will continue, in the case where a migration includes adding a new 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