Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H-3304: Initial setup for SqlFluff #5781

Merged
merged 8 commits into from
Dec 3, 2024
Merged
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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I am a huge fan of the removal of indentation here (or citus one), but no strong opinions really.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this is configurable. I'll take a Quick Look

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found for JOIN but not for creating indices/extensions. Also not a strong opinion, so I'll just merge it πŸ™‚

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 @@
*
Loading