Skip to content

Commit

Permalink
Add if check for existing partition (#4152)
Browse files Browse the repository at this point in the history
If table has already been created, the partitioning script will continue, in the case where a migration includes adding a new partition.
  • Loading branch information
conbrad authored Dec 3, 2024
1 parent d31d733 commit 8235d3c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion openshift/pgslice/docker/partition_and_archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8235d3c

Please sign in to comment.