Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enforce migration naming and bindata update #47

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ else
done
fi

# check for new SQL migration files
latest_migration=$(ls -1 telemetry/sql/*.up.sql 2>/dev/null | sort -V | tail -n 1)
if [ -n "$latest_migration" ]; then
latest_number=$(basename "$latest_migration" | cut -d'_' -f1)
new_migrations=$(git diff --cached --name-only --diff-filter=A | grep '^telemetry/sql/.*\.up\.sql$')

if [ -n "$new_migrations" ]; then
for migration in $new_migrations; do
number=$(basename "$migration" | cut -d'_' -f1)
# enforce sequential prefix
if [ "$number" -le "$latest_number" ]; then
echo "Error: New migration file $migration does not follow the incremental naming structure."
exit 1
fi
done

# Check if bindata.go has changed
if ! git diff --cached --name-only | grep -q '^telemetry/bindata\.go$'; then
echo "Error: New SQL migration file added, but telemetry/bindata.go has not been updated."
echo "Please run 'make generate' to update bindata.go"
exit 1
fi
fi
fi

if go mod tidy -v 2>&1 | grep -q 'updates to go.mod needed'; then
exit 1
fi
Expand Down
Loading