2 Commits

Author SHA1 Message Date
cefcc296fb Merge pull request 'fix: resolve unbound variable error in deploy script migration check' (#17) from feature-deploy-script into main
Reviewed-on: #17
2026-04-09 09:16:34 -04:00
2aad137bd7 fix: resolve unbound variable error in deploy script migration check
The APPLIED_MIGRATIONS associative array triggered "unbound variable"
under set -u when empty (first run / seed-existing). Fix by initializing
with =() and using a safe helper function with ${:-} default syntax.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 09:15:54 -04:00

View File

@@ -248,12 +248,19 @@ CREATE TABLE IF NOT EXISTS shared.schema_migrations (
SQL
ok "Migration tracking table ready"
# Helper: check if a migration has been applied (safe with set -u)
is_applied() {
local key="$1"
# Use a subshell test to avoid unbound variable with set -u on empty associative arrays
[[ -n "${APPLIED_MIGRATIONS[$key]:-}" ]]
}
# Step 5b: Get list of already-applied migrations
declare -A APPLIED_MIGRATIONS
declare -A APPLIED_MIGRATIONS=()
while IFS= read -r fname; do
fname=$(echo "$fname" | xargs) # trim whitespace
[ -n "$fname" ] && APPLIED_MIGRATIONS["$fname"]=1
done < <(run_sql -t -c "SELECT filename FROM shared.schema_migrations ORDER BY filename;")
done < <(run_sql -t -c "SELECT filename FROM shared.schema_migrations ORDER BY filename;" 2>/dev/null || true)
APPLIED_COUNT=${#APPLIED_MIGRATIONS[@]}
log "Previously applied migrations: $APPLIED_COUNT"
@@ -304,7 +311,7 @@ PENDING_COUNT=0
APPLIED_THIS_RUN=0
for filename in "${MIGRATION_FILES[@]}"; do
if [ -n "${APPLIED_MIGRATIONS[$filename]+x}" ]; then
if is_applied "$filename"; then
continue
fi
((PENDING_COUNT++))
@@ -317,7 +324,7 @@ else
echo ""
for filename in "${MIGRATION_FILES[@]}"; do
if [ -n "${APPLIED_MIGRATIONS[$filename]+x}" ]; then
if is_applied "$filename"; then
continue
fi