|
62 | 62 | assert_table_not_exists public $(generate_daily_partition_name ${TABLE} ${i})
|
63 | 63 | done
|
64 | 64 | }
|
| 65 | + |
| 66 | +@test "Test that gaps in the partition set prevent any partition removal" { |
| 67 | + local TABLE="test_uuid_gap" |
| 68 | + local INTERVAL=monthly |
| 69 | + local RETENTION=1 |
| 70 | + local PREPROVISIONED=2 |
| 71 | + |
| 72 | + create_table_uuid_range ${TABLE} |
| 73 | + |
| 74 | + declare -a PARTS=( |
| 75 | + ${TABLE}_2024_12 01937f84-5800-7000-0000-000000000000 01941f29-7c00-7000-0000-000000000000 |
| 76 | + # next partition is missing |
| 77 | + # ${TABLE}_2025_01 01941f29-7c00-7000-0000-000000000000 0194bece-a000-7000-0000-000000000000 |
| 78 | + ${TABLE}_2025_02 0194bece-a000-7000-0000-000000000000 01954f00-b000-7000-0000-000000000000 |
| 79 | + ${TABLE}_2025_03 01954f00-b000-7000-0000-000000000000 0195eea5-d400-7000-0000-000000000000 |
| 80 | + ${TABLE}_2025_04 0195eea5-d400-7000-0000-000000000000 01968924-9c00-7000-0000-000000000000 |
| 81 | + ) |
| 82 | + |
| 83 | + create_partitions "$TABLE" "${PARTS[@]}" |
| 84 | + |
| 85 | + local CONFIGURATION=$(cat << EOF |
| 86 | +partitions: |
| 87 | + unittest: |
| 88 | + schema: public |
| 89 | + table: ${TABLE} |
| 90 | + interval: ${INTERVAL} |
| 91 | + partitionKey: id |
| 92 | + cleanupPolicy: drop |
| 93 | + retention: ${RETENTION} |
| 94 | + preProvisioned: ${PREPROVISIONED} |
| 95 | +EOF |
| 96 | +) |
| 97 | + local CONFIGURATION_FILE=$(generate_configuration_file "${CONFIGURATION}") |
| 98 | + |
| 99 | + # When run on 2025-03-15 with a retention of 1 month, the partition for 2024-12 |
| 100 | + # is old enough to be dropped. But since 2025-01 is missing, it is an error that |
| 101 | + # should prevent the drop. |
| 102 | + PPM_WORK_DATE="2025-03-15" run postgresql-partition-manager run cleanup -c ${CONFIGURATION_FILE} |
| 103 | + |
| 104 | + assert_failure |
| 105 | + assert_output --partial 'level=ERROR msg="Partition Gap"' |
| 106 | + |
| 107 | + # Check that all the partitions are still there |
| 108 | + local i=0 |
| 109 | + local expected="" |
| 110 | + while (( i < ${#PARTS[*]} )) |
| 111 | + do |
| 112 | + # bats does not expect any trailing newline, so append it to each previous line |
| 113 | + # except the first |
| 114 | + if (( i > 0 )); then expected+=$'\n'; fi |
| 115 | + expected+="public|${PARTS[i]}|${PARTS[i+1]}|${PARTS[i+2]}" |
| 116 | + (( i+=3 )) |
| 117 | + done |
| 118 | + run list_existing_partitions "unittest" "public" "${TABLE}" |
| 119 | + |
| 120 | + assert_output "$expected" |
| 121 | + |
| 122 | + rm "$CONFIGURATION_FILE" |
| 123 | +} |
0 commit comments