Skip to content

Commit ecce2fd

Browse files
authored
H-3304: Initial setup for SqlFluff (#5781)
1 parent 5e3bbda commit ecce2fd

File tree

7 files changed

+84
-10
lines changed

7 files changed

+84
-10
lines changed

.github/CODEOWNERS

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ LICENSE.txt @hashintel/legal
44
LICENSE.md @hashintel/legal
55

66
# Database migrations
7-
/apps/hash-graph/libs/graph/postgres_migrations/ @hashintel/db-admins
7+
/libs/@local/graph/postgres-store/postgres_migrations/ @hashintel/db-admins
8+
/libs/@local/graph/migrations/graph-migrations/ @hashintel/db-admins

.github/workflows/lint.yml

+25-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ jobs:
204204
name: Global
205205
runs-on: ubuntu-24.04
206206
steps:
207-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
207+
- name: Checkout repository
208+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
208209

209210
- name: Warm up repository
210211
uses: ./.github/actions/warm-up-repo
@@ -343,6 +344,29 @@ jobs:
343344
exit 1
344345
fi
345346
347+
- name: Install Python
348+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
349+
with:
350+
python-version: 3.12
351+
352+
- name: Install SQLFluff
353+
run: pip install sqlfluff
354+
355+
- name: SQLFluff
356+
run: sqlfluff lint --warn-unused-ignores
357+
358+
- name: Crate SQLFluff annotationss
359+
if: failure() && github.event.pull_request.head.repo.full_name == github.repository
360+
run: sqlfluff lint --warn-unused-ignores --format github-annotation --write-output annotations.json --annotation-level failure --nofail
361+
362+
- name: Annotate
363+
uses: yuzutech/annotations-action@0e061a6e3ac848299310b6429b60d67cafd4e7f8 # v0.5.0
364+
if: failure() && github.event.pull_request.head.repo.full_name == github.repository
365+
with:
366+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
367+
title: "SQLFluff Lint"
368+
input: "annotations.json"
369+
346370
passed:
347371
name: Linting passed
348372
needs: [setup, package, global]

.sqlfluff

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[sqlfluff]
2+
dialect = postgres
3+
encoding = utf-8
4+
5+
max_line_length = 100
6+
large_file_skip_byte_limit = 100000
7+
8+
9+
[sqlfluff:indentation]
10+
indented_ctes = True
11+
indented_on_contents = False
12+
allow_implicit_indents = True
13+
14+
[sqlfluff:rules]
15+
single_table_references = qualified
16+
17+
[sqlfluff:rules:capitalisation.keywords]
18+
capitalisation_policy = upper
19+
20+
[sqlfluff:rules:capitalisation.identifiers]
21+
extended_capitalisation_policy = lower
22+
23+
[sqlfluff:rules:capitalisation.functions]
24+
extended_capitalisation_policy = lower
25+
26+
[sqlfluff:rules:capitalisation.literals]
27+
capitalisation_policy = upper
28+
29+
[sqlfluff:rules:capitalisation.types]
30+
extended_capitalisation_policy = upper
31+
32+
33+
[sqlfluff:rules:convention.count_rows]
34+
prefer_count_1 = True
35+
36+
[sqlfluff:rules:ambiguous.column_references]
37+
# GROUP BY/ORDER BY column references
38+
group_by_and_order_by_style = explicit
39+
40+
41+
[sqlfluff:rules:convention.not_equal]
42+
# Consistent usage of preferred "not equal to" comparison
43+
preferred_not_equal_style = c_style
44+
45+
46+
[sqlfluff:rules:convention.casting_style]
47+
# SQL type casting
48+
preferred_type_casting_style = shorthand
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CREATE EXTENSION
2-
citus;
2+
citus;

libs/@local/graph/migrations/graph-migrations/v006__data_types/up.sql

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ CREATE TABLE data_type_conversions (
3636

3737
CREATE VIEW data_type_conversion_aggregation AS
3838
SELECT
39-
source_data_type_ontology_id,
40-
array_agg(target_data_type_base_url) AS target_data_type_base_urls,
41-
array_agg("into") AS intos,
42-
array_agg("from") AS froms
39+
data_type_conversions.source_data_type_ontology_id,
40+
array_agg(data_type_conversions.target_data_type_base_url) AS target_data_type_base_urls,
41+
array_agg(data_type_conversions."into") AS intos,
42+
array_agg(data_type_conversions."from") AS froms
4343
FROM data_type_conversions
44-
GROUP BY source_data_type_ontology_id;
44+
GROUP BY data_type_conversions.source_data_type_ontology_id;

libs/@local/graph/migrations/graph-migrations/v009__entities/up.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CREATE TABLE entity_has_left_entity (
7777
FOREIGN KEY (left_web_id, left_entity_uuid) REFERENCES entity_ids
7878
);
7979
CREATE INDEX entity_has_left_entity_source_idx
80-
ON entity_has_left_entity(web_id, entity_uuid);
80+
ON entity_has_left_entity (web_id, entity_uuid);
8181

8282
CREATE TABLE entity_has_right_entity (
8383
web_id UUID NOT NULL,
@@ -90,7 +90,7 @@ CREATE TABLE entity_has_right_entity (
9090
FOREIGN KEY (right_web_id, right_entity_uuid) REFERENCES entity_ids
9191
);
9292
CREATE INDEX entity_has_right_entity_source_idx
93-
ON entity_has_right_entity(web_id, entity_uuid);
93+
ON entity_has_right_entity (web_id, entity_uuid);
9494

9595
CREATE TABLE entity_embeddings (
9696
web_id UUID NOT NULL,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

0 commit comments

Comments
 (0)