Skip to content

Commit

Permalink
H-3304: Initial setup for SqlFluff (#5781)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored Dec 3, 2024
1 parent 5e3bbda commit ecce2fd
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ LICENSE.txt @hashintel/legal
LICENSE.md @hashintel/legal

# Database migrations
/apps/hash-graph/libs/graph/postgres_migrations/ @hashintel/db-admins
/libs/@local/graph/postgres-store/postgres_migrations/ @hashintel/db-admins
/libs/@local/graph/migrations/graph-migrations/ @hashintel/db-admins
26 changes: 25 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ jobs:
name: Global
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Warm up repository
uses: ./.github/actions/warm-up-repo
Expand Down Expand Up @@ -343,6 +344,29 @@ jobs:
exit 1
fi
- name: Install Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: 3.12

- name: Install SQLFluff
run: pip install sqlfluff

- name: SQLFluff
run: sqlfluff lint --warn-unused-ignores

- name: Crate SQLFluff annotationss
if: failure() && github.event.pull_request.head.repo.full_name == github.repository
run: sqlfluff lint --warn-unused-ignores --format github-annotation --write-output annotations.json --annotation-level failure --nofail

- name: Annotate
uses: yuzutech/annotations-action@0e061a6e3ac848299310b6429b60d67cafd4e7f8 # v0.5.0
if: failure() && github.event.pull_request.head.repo.full_name == github.repository
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
title: "SQLFluff Lint"
input: "annotations.json"

passed:
name: Linting passed
needs: [setup, package, global]
Expand Down
48 changes: 48 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[sqlfluff]
dialect = postgres
encoding = utf-8

max_line_length = 100
large_file_skip_byte_limit = 100000


[sqlfluff:indentation]
indented_ctes = True
indented_on_contents = False
allow_implicit_indents = True

[sqlfluff:rules]
single_table_references = qualified

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = upper


[sqlfluff:rules:convention.count_rows]
prefer_count_1 = True

[sqlfluff:rules:ambiguous.column_references]
# GROUP BY/ORDER BY column references
group_by_and_order_by_style = explicit


[sqlfluff:rules:convention.not_equal]
# Consistent usage of preferred "not equal to" comparison
preferred_not_equal_style = c_style


[sqlfluff:rules:convention.casting_style]
# SQL type casting
preferred_type_casting_style = shorthand
2 changes: 1 addition & 1 deletion infra/docker/citus/prod/initdb/0000_init.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CREATE EXTENSION
citus;
citus;
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ CREATE TABLE data_type_conversions (

CREATE VIEW data_type_conversion_aggregation AS
SELECT
source_data_type_ontology_id,
array_agg(target_data_type_base_url) AS target_data_type_base_urls,
array_agg("into") AS intos,
array_agg("from") AS froms
data_type_conversions.source_data_type_ontology_id,
array_agg(data_type_conversions.target_data_type_base_url) AS target_data_type_base_urls,
array_agg(data_type_conversions."into") AS intos,
array_agg(data_type_conversions."from") AS froms
FROM data_type_conversions
GROUP BY source_data_type_ontology_id;
GROUP BY data_type_conversions.source_data_type_ontology_id;
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CREATE TABLE entity_has_left_entity (
FOREIGN KEY (left_web_id, left_entity_uuid) REFERENCES entity_ids
);
CREATE INDEX entity_has_left_entity_source_idx
ON entity_has_left_entity(web_id, entity_uuid);
ON entity_has_left_entity (web_id, entity_uuid);

CREATE TABLE entity_has_right_entity (
web_id UUID NOT NULL,
Expand All @@ -90,7 +90,7 @@ CREATE TABLE entity_has_right_entity (
FOREIGN KEY (right_web_id, right_entity_uuid) REFERENCES entity_ids
);
CREATE INDEX entity_has_right_entity_source_idx
ON entity_has_right_entity(web_id, entity_uuid);
ON entity_has_right_entity (web_id, entity_uuid);

CREATE TABLE entity_embeddings (
web_id UUID NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*

0 comments on commit ecce2fd

Please sign in to comment.