fix(CI/SQL import): don't use octal (#20449)

This commit is contained in:
Mike Delago
2024-11-05 10:40:41 -05:00
committed by GitHub
parent ce70cf1c13
commit 6161d9969b

View File

@@ -8,14 +8,22 @@ source "$CURRENT_PATH/../bash_shared/includes.sh"
UPDATES_PATH="$AC_PATH_ROOT/data/sql/updates"
# get_next_index "data/sql/updates/db_world/2024_10_14_22.sql"
# => 23
# get_next_index ""
# => 00
function get_next_index() {
if [[ -n "$1" ]]; then
PREV_COUNT="$(basename "$1" | cut -f4 -d_ | cut -f1 -d\.)"
# PREV_COUNT should be a non-zero padded number
PREV_COUNT="$(
# grabs the filename of the first argument, removes ".sql" suffix.
basename "$1" .sql |
# get the last number
cut -f4 -d_ |
# retrieve the last number, without zero padding
grep -oE "[1-9][0-9]*$"
)"
printf '%02d' "$((PREV_COUNT + 1))"
else
echo "00"
@@ -40,8 +48,7 @@ function import() {
# Get latest SQL file applied to this database, today. This could be empty.
LATEST_UPDATE_TODAY="$(find "$UPDATES_DIR" -iname "$TODAY*.sql" | sort -h | tail -n 1)"
for entry in "$PENDING_PATH"/*.sql
do
for entry in "$PENDING_PATH"/*.sql; do
if [[ -f "$entry" ]]; then
INDEX="$(get_next_index "$LATEST_UPDATE_TODAY")"
OUTPUT_FILE="${UPDATES_DIR}/${TODAY}_${INDEX}.sql"