diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f261b96b2e3..8e9af47bba9 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3bde95faa90..93e7c11c8d5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 @@ -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] diff --git a/.sqlfluff b/.sqlfluff new file mode 100644 index 00000000000..7661d4689b3 --- /dev/null +++ b/.sqlfluff @@ -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 diff --git a/infra/docker/citus/prod/initdb/0000_init.sql b/infra/docker/citus/prod/initdb/0000_init.sql index 3064ba29f50..8746012d46c 100644 --- a/infra/docker/citus/prod/initdb/0000_init.sql +++ b/infra/docker/citus/prod/initdb/0000_init.sql @@ -1,2 +1,2 @@ CREATE EXTENSION - citus; +citus; diff --git a/libs/@local/graph/migrations/graph-migrations/v006__data_types/up.sql b/libs/@local/graph/migrations/graph-migrations/v006__data_types/up.sql index ae4034cb035..5132ca6be99 100644 --- a/libs/@local/graph/migrations/graph-migrations/v006__data_types/up.sql +++ b/libs/@local/graph/migrations/graph-migrations/v006__data_types/up.sql @@ -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; diff --git a/libs/@local/graph/migrations/graph-migrations/v009__entities/up.sql b/libs/@local/graph/migrations/graph-migrations/v009__entities/up.sql index 00a24e2632e..e67948da184 100644 --- a/libs/@local/graph/migrations/graph-migrations/v009__entities/up.sql +++ b/libs/@local/graph/migrations/graph-migrations/v009__entities/up.sql @@ -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, @@ -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, diff --git a/libs/@local/graph/postgres-store/postgres_migrations/.sqlfluffignore b/libs/@local/graph/postgres-store/postgres_migrations/.sqlfluffignore new file mode 100644 index 00000000000..72e8ffc0db8 --- /dev/null +++ b/libs/@local/graph/postgres-store/postgres_migrations/.sqlfluffignore @@ -0,0 +1 @@ +*