fix: resolve unbound variable error in deploy script migration check #17
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user