Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions .github/workflows/sql-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ jobs:
override-file-path: ./sql/sql-review-override.yml
database-type: MYSQL
file-pattern: ^sql/.*\.sql$
- uses: yu-iskw/action-sqlfluff@v3
id: lint-sql
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
sqlfluff_version: "3.0.6"
sqlfluff_command: "lint" # Or "lint"
paths: '${{ github.workspace }}/sql/myfirstdb'
dialect: 'mysql'
- name: 'Show outputs (Optional)'
shell: bash
run: |
echo '${{ steps.lint-sql.outputs.sqlfluff-results }}' | jq -r '.'
echo '${{ steps.lint-sql.outputs.sqlfluff-results-rdjson }}' | jq -r '.'

- name: Build Docker image
run: |
DOCKER_BUILDKIT=0 docker build -t init-db .
Expand Down
18 changes: 18 additions & 0 deletions sql/lint_sql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import subprocess

def lint_sql_file(file_path, dialect='mysql'):
try:
print(f"Linting {file_path}...")
subprocess.run(['sqlfluff', 'lint', file_path, '--dialect', dialect], check=True)
print(f"{file_path} linted successfully!")
except subprocess.CalledProcessError as e:
print(f"Error linting {file_path}: {e}")

if __name__ == "__main__":
sql_directory = '.'
for root, dirs, files in os.walk(sql_directory):
for file in files:
if file.endswith('.sql'):
file_path = os.path.join(root, file)
lint_sql_file(file_path)
5 changes: 5 additions & 0 deletions sql/myfirstdb/20240517003_inset_user_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +migrate Up
INSERT INTO user_test (username) VALUES ('Ray');

-- +migrate Down
DELETE FROM user_test WHERE username = 'Ray';