add sqlfluff dep and script and config
This commit is contained in:
parent
a4965ed9b2
commit
478e953700
3 changed files with 41 additions and 0 deletions
3
ci/.sqlfluff
Normal file
3
ci/.sqlfluff
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[sqlfluff]
|
||||||
|
large_file_skip_char_limit = 0
|
||||||
|
large_file_skip_byte_limit = 0
|
||||||
1
ci/ci-requirements.txt
Normal file
1
ci/ci-requirements.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
sqlfluff==3.3.1
|
||||||
37
ci/sqlfluff-check.sh
Normal file
37
ci/sqlfluff-check.sh
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script gets all the .sql files in a path and checks if they are valid
|
||||||
|
# as defined by the PostgreSQL dialect. The script exits with 1 if any single
|
||||||
|
# file has an issue. The script exits with 0 if all files are valid.
|
||||||
|
|
||||||
|
# The script takes one arg, which is the directory where the .sql files are.
|
||||||
|
|
||||||
|
# Ensure a directory is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <sql_directory>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SQL_DIR=$1
|
||||||
|
|
||||||
|
EXIT_CODE=0
|
||||||
|
|
||||||
|
echo "Starting sqlfluff checks on ${SQL_DIR}"
|
||||||
|
|
||||||
|
while read -r sql_file; do
|
||||||
|
|
||||||
|
echo "Parsing $sql_file"
|
||||||
|
# Run sqlfluff parse on the file and capture the output
|
||||||
|
OUTPUT=$(sqlfluff parse --dialect postgres "$sql_file" 2>&1)
|
||||||
|
|
||||||
|
|
||||||
|
# Check if the output contains a parsing error
|
||||||
|
if echo "$OUTPUT" | grep -q "==== parsing violations ===="; then
|
||||||
|
echo "Error in file: $sql_file"
|
||||||
|
echo "$OUTPUT" | awk '/==== parsing violations ====/{flag=1; next} /Complete/{flag=0} flag'
|
||||||
|
EXIT_CODE=1
|
||||||
|
fi
|
||||||
|
done < <(find "$SQL_DIR" -type f -name "*.sql")
|
||||||
|
|
||||||
|
echo "Exit code: ${EXIT_CODE}"
|
||||||
|
exit $EXIT_CODE
|
||||||
Loading…
Add table
Add a link
Reference in a new issue