Skip to content

Commit

Permalink
Update pre-commit hook to use custom script for Alembic checks and en…
Browse files Browse the repository at this point in the history
…hance environment variable loading
  • Loading branch information
quang-ng committed Dec 4, 2024
1 parent b538896 commit 22f56b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ repos:
hooks:
- id: alembic-check
name: Check for model changes requiring migrations
entry: alembic check
language: system
entry: ./alembic_check.sh
language: script
pass_filenames: false
types: [python]
files: ^dsst_etl/.*\.py$
Expand Down
20 changes: 11 additions & 9 deletions alembic_check.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash

# Exit immediately if any command fails
set -e
# Load environment variables if .env exists
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
elif [ -f .mockenv ]; then
export $(cat .mockenv | grep -v '^#' | xargs)
fi

# Run the Alembic check command
# Run alembic check
alembic check

if [ $? -ne 0 ]; then
echo "Error: Uncommitted Alembic upgrade operations detected."
echo "Please generate and commit your migration scripts."
exit 1
fi
# Store the exit code
exit_code=$?

echo "Alembic check passed. No new upgrade operations detected."
# Return the alembic check exit code
exit $exit_code

0 comments on commit 22f56b8

Please sign in to comment.