Skip to content

pgtle.sh: spurious "WARNING: UPGRADE_FILES not set, initializing" for extensions with no upgrade scripts #151

Open

Description

@jnasbyupgrade

🤖 (Claude)

make pgtle prints WARNING: UPGRADE_FILES not set, initializing once per pg_tle version range for any extension that has no sql/<ext>--<v1>--<v2>.sql upgrade scripts. The warning is spurious: the array is already initialized, and the output is unaffected.

Example output for an extension with a single sql/<ext>--1.0.0.sql and no upgrade scripts:

Discovering SQL files for extension: <ext>
  Found 1 version file(s):
    - sql/<ext>--1.0.0.sql
WARNING: UPGRADE_FILES not set, initializing
Generating: pg_tle/1.0.0-1.4.0/<ext>.sql (pg_tle 1.0.0-1.4.0)
...

Cause: in generate_pgtle_sql(), the "defensive" initialization checks use ${UPGRADE_FILES+set} (and likewise ${VERSION_FILES+set}):

if [ -z "${UPGRADE_FILES+set}" ]; then
    echo "WARNING: UPGRADE_FILES not set, initializing" >&2
    UPGRADE_FILES=()
fi

For an array, ${arr+set} tests whether element 0 exists, not whether the array was declared. A declared-but-empty array (UPGRADE_FILES=(), as set at the top of the script and again in discover_sql_files) has no element 0, so the test reports it as unset:

$ bash -c 'a=(); [ -z "${a+set}" ] && echo "warns on empty array"; a=(x); [ -z "${a+set}" ] || echo "no warn when nonempty"'
warns on empty array
no warn when nonempty

The branch only re-assigns an empty array to an empty array, so it's harmless apart from the noise. It runs once per generate_pgtle_sql call, which is why it appears three times when generating all pg_tle versions. VERSION_FILES can't hit it in practice, since discover_sql_files dies when there are no version files.

Possible fixes: drop the check, since both arrays are initialized at the top level and reset in discover_sql_files. Or test declaration instead, e.g. declare -p UPGRADE_FILES &>/dev/null. The same applies to the debug 30 lines that print ${UPGRADE_FILES+set} / ${VERSION_FILES+set}, which report "unset" for an empty array.

Still present on current master.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions