Skip to content

Instantly share code, notes, and snippets.

@ImreSamu
Last active September 4, 2025 15:25
Show Gist options
  • Select an option

  • Save ImreSamu/a66ffe9b56ce1798c18f8b1e3d5d4467 to your computer and use it in GitHub Desktop.

Select an option

Save ImreSamu/a66ffe9b56ce1798c18f8b1e3d5d4467 to your computer and use it in GitHub Desktop.
Orioledb SQL header check & optional fix. // https://github.com/orioledb/orioledb/pull/552
#!/usr/bin/env bash
set -euo pipefail
# Usage:
# ./check-sql-headers.sh [--fix] [rootdir]
# Examples:
# ./check-sql-headers.sh
# ./check-sql-headers.sh --fix .
# ./check-sql-headers.sh --fix path/to/repo
fix=0
if [ "${1:-}" = "--fix" ]; then
fix=1
shift
fi
root="${1:-.}"
bad=0
# Only .sql files
find "$root" -type f -name '*.sql' -print0 |
while IFS= read -r -d '' f; do
# First line only
line1="$(sed -n '1p' "$f" || true)"
# We only check files whose first line contains "contrib/orioledb"
if ! printf '%s' "$line1" | grep -Fq 'contrib/orioledb'; then
continue
fi
# Extract the path token that starts with contrib/orioledb and continues until whitespace
header_path="$(printf '%s' "$line1" | grep -o 'contrib/orioledb[^[:space:]]*' | head -n1 || true)"
expected_path="contrib/orioledb/${f#./}"
if [ -z "$header_path" ]; then
# Defensive: shouldn't happen if the grep above matched, but keep it robust
printf '%s: [SQL] cannot parse header path from first line\n' "$f"
bad=1
continue
fi
if [ "$header_path" != "$expected_path" ]; then
if [ $fix -eq 1 ]; then
# Replace ONLY the contrib/orioledb... token on line 1, preserving indentation and trailing comment
if sed -i -E "1{s|contrib/orioledb[^[:space:]]*|$expected_path|}" "$f"; then
echo "FIXED [SQL]: $f"
else
echo "FAILED [SQL]: $f"
bad=1
fi
else
printf '%s: [SQL] got [%s], expected [%s]\n' "$f" "$header_path" "$expected_path"
bad=1
fi
fi
done
exit "$bad"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment