-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from supabase/or/pre-commit
Add pre-commit hooks for consistency
- Loading branch information
Showing
24 changed files
with
700 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: pre-commit hooks | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: set up python 3.9 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: install pre-commit | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pre-commit | ||
- name: run static analysis | ||
run: | | ||
pre-commit run --all-files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.3.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
exclude: '^test/expected' | ||
- id: check-added-large-files | ||
- id: check-yaml | ||
- id: mixed-line-ending | ||
args: ['--fix=lf'] | ||
|
||
- repo: https://github.com/Lucas-C/pre-commit-hooks | ||
rev: v1.5.5 | ||
hooks: | ||
- id: remove-tabs | ||
args: [--whitespaces-count, '4'] # defaults to: 4 | ||
|
||
- repo: https://github.com/Lucas-C/pre-commit-hooks | ||
rev: v1.5.5 | ||
hooks: | ||
- id: remove-tabs | ||
args: [--whitespaces-count, '4'] # defaults to: 4 | ||
|
||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 24.2.0 | ||
hooks: | ||
- id: black | ||
language_version: python3.9 | ||
|
||
- repo: local | ||
hooks: | ||
- id: compile-script | ||
name: Compile SQL Files | ||
entry: python bin/compile.py | ||
language: system | ||
always_run: true | ||
pass_filenames: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
|
||
def join_sql_files(directory_path) -> str: | ||
# Convert the directory path to a Path object | ||
directory = Path(directory_path) | ||
|
||
# Initialize an empty string to store the concatenated SQL | ||
queries = [] | ||
|
||
# Check if directory exists | ||
if not directory.exists(): | ||
raise Exception(f"The directory {directory} does not exist.") | ||
|
||
# Loop through each file in the specified directory | ||
for file_path in sorted(directory.glob("*.sql")): | ||
# Open and read the SQL file | ||
with file_path.open("r") as file: | ||
# Read the file's content and add it to the concatenated SQL string | ||
contents = file.read() | ||
lines = contents.strip().split("\n") | ||
|
||
# Query without semicolons and "create view" statement | ||
adjusted_contents = "\n".join( | ||
[line.replace(";", "") for line in lines if "create view" not in line] | ||
) | ||
# wrap each query in "(" ")" so queries with CTEs can be unioned | ||
# without syntax errors | ||
adjusted_contents = f"({adjusted_contents})" | ||
|
||
queries.append(adjusted_contents) | ||
return "\nunion all\n".join(queries) | ||
|
||
|
||
# Example usage | ||
directory_path = "./lints" | ||
concatenated_sql = join_sql_files(directory_path) | ||
|
||
with open("splinter.sql", "w") as f: | ||
f.write(concatenated_sql) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.