Skip to content

Commit

Permalink
Add titles to lints (#72)
Browse files Browse the repository at this point in the history
* add titles to lints

* add title to lint interface doc
  • Loading branch information
olirice committed May 9, 2024
1 parent e2a6622 commit 95f050c
Show file tree
Hide file tree
Showing 34 changed files with 165 additions and 134 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ If you are only interested in linting a project, a single query containing the l
Each lint creates a view that returns a common interface. The interface is:

- name (text) not null -- Name of the lint
- title (text) not null -- Human readable title of the lint
- level (text) not null -- The level of issue. One of ERROR/WARN/INFO
- facing (text) not null -- Is it an internal (to supabase) or an external (user centric) lint. One of INTERNAL/EXTERNAL
- categories (text[]) not null -- Relevant tags for the issue. Any/All of SECURITY/PERFORMANCE (list may grow)
Expand Down
1 change: 1 addition & 0 deletions lints/0001_unindexed_foreign_keys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ index_ as (
)
select
'unindexed_foreign_keys' as name,
'Unindexed foreign keys' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0002_auth_users_exposed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0002_auth_users_exposed" as

select
'auth_users_exposed' as name,
'Exposed Auth Users' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0003_auth_rls_initplan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ with policies as (
)
select
'auth_rls_initplan' as name,
'Auth RLS Initialization Plan' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0004_no_primary_key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0004_no_primary_key" as

select
'no_primary_key' as name,
'No Primary Key' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0005_unused_index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0005_unused_index" as

select
'unused_index' as name,
'Unused Index' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0006_multiple_permissive_policies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0006_multiple_permissive_policies" as

select
'multiple_permissive_policies' as name,
'Multiple Permissive Policies' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0007_policy_exists_rls_disabled.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0007_policy_exists_rls_disabled" as

select
'policy_exists_rls_disabled' as name,
'Policy Exists RLS Disabled' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0008_rls_enabled_no_policy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0008_rls_enabled_no_policy" as

select
'rls_enabled_no_policy' as name,
'RLS Enabled No Policy' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0009_duplicate_index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0009_duplicate_index" as

select
'duplicate_index' as name,
'Duplicate Index' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0010_security_definer_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0010_security_definer_view" as

select
'security_definer_view' as name,
'Security Definer View' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0011_function_search_path_mutable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0011_function_search_path_mutable" as

select
'function_search_path_mutable' as name,
'Function Search Path Mutable' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0013_rls_disabled_in_public.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0013_rls_disabled_in_public" as

select
'rls_disabled_in_public' as name,
'RLS Disabled in Public' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0014_extension_in_public.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0014_extension_in_public" as

select
'extension_in_public' as name,
'Extension in Public' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0015_rls_references_user_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ with policies as (
)
select
'rls_references_user_metadata' as name,
'RLS references user metadata' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
1 change: 1 addition & 0 deletions lints/0016_materialized_view_in_api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create view lint."0016_materialized_view_in_api" as

select
'materialized_view_in_api' as name,
'Materialized View in API' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
30 changes: 15 additions & 15 deletions splinter.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions splinter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ index_ as (
)
select
'unindexed_foreign_keys' as name,
'Unindexed foreign keys' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down Expand Up @@ -75,6 +76,7 @@ union all
(
select
'auth_users_exposed' as name,
'Exposed Auth Users' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -191,6 +193,7 @@ with policies as (
)
select
'auth_rls_initplan' as name,
'Auth RLS Initialization Plan' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down Expand Up @@ -254,6 +257,7 @@ union all
(
select
'no_primary_key' as name,
'No Primary Key' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down Expand Up @@ -299,6 +303,7 @@ union all
(
select
'unused_index' as name,
'Unused Index' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down Expand Up @@ -341,6 +346,7 @@ union all
(
select
'multiple_permissive_policies' as name,
'Multiple Permissive Policies' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down Expand Up @@ -413,6 +419,7 @@ union all
(
select
'policy_exists_rls_disabled' as name,
'Policy Exists RLS Disabled' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -458,6 +465,7 @@ union all
(
select
'rls_enabled_no_policy' as name,
'RLS Enabled No Policy' as title,
'INFO' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -503,6 +511,7 @@ union all
(
select
'duplicate_index' as name,
'Duplicate Index' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['PERFORMANCE'] as categories,
Expand Down Expand Up @@ -557,6 +566,7 @@ union all
(
select
'security_definer_view' as name,
'Security Definer View' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -608,6 +618,7 @@ union all
(
select
'function_search_path_mutable' as name,
'Function Search Path Mutable' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -647,6 +658,7 @@ union all
(
select
'rls_disabled_in_public' as name,
'RLS Disabled in Public' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -687,6 +699,7 @@ union all
(
select
'extension_in_public' as name,
'Extension in Public' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -738,6 +751,7 @@ with policies as (
)
select
'rls_references_user_metadata' as name,
'RLS references user metadata' as title,
'ERROR' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down Expand Up @@ -774,6 +788,7 @@ union all
(
select
'materialized_view_in_api' as name,
'Materialized View in API' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
Expand Down
26 changes: 13 additions & 13 deletions test/expected/0001_unindexed_foreign_keys.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ begin;
aaa_id int references public.aaa(id) -- no index
);
select * from lint."0001_unindexed_foreign_keys";
name | level | facing | categories | description | detail | remediation | metadata | cache_key
------------------------+-------+----------+---------------+-----------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+---------------------------------------------------
unindexed_foreign_keys | INFO | EXTERNAL | {PERFORMANCE} | Identifies foreign key constraints without a covering index, which can impact database performance. | Table \`public.bbb\` has a foreign key \`bbb_aaa_id_fkey\` without a covering index. This can lead to suboptimal query performance. | https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys | {"name": "bbb", "type": "table", "schema": "public", "fkey_name": "bbb_aaa_id_fkey", "fkey_columns": [2]} | unindexed_foreign_keys_public_bbb_bbb_aaa_id_fkey
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------------------------+------------------------+-------+----------+---------------+-----------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+---------------------------------------------------
unindexed_foreign_keys | Unindexed foreign keys | INFO | EXTERNAL | {PERFORMANCE} | Identifies foreign key constraints without a covering index, which can impact database performance. | Table \`public.bbb\` has a foreign key \`bbb_aaa_id_fkey\` without a covering index. This can lead to suboptimal query performance. | https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys | {"name": "bbb", "type": "table", "schema": "public", "fkey_name": "bbb_aaa_id_fkey", "fkey_columns": [2]} | unindexed_foreign_keys_public_bbb_bbb_aaa_id_fkey
(1 row)

-- When a covering index is created, the error goes away
create index on public.bbb(aaa_id);
select * from lint."0001_unindexed_foreign_keys";
name | level | facing | categories | description | detail | remediation | metadata | cache_key
------+-------+--------+------------+-------------+--------+-------------+----------+-----------
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------+-------+-------+--------+------------+-------------+--------+-------------+----------+-----------
(0 rows)

rollback to savepoint a;
Expand All @@ -38,25 +38,25 @@ begin;
foreign key (foo, bar) references public.aaa(foo, bar)
);
select * from lint."0001_unindexed_foreign_keys";
name | level | facing | categories | description | detail | remediation | metadata | cache_key
------------------------+-------+----------+---------------+-----------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------+----------------------------------------------------
unindexed_foreign_keys | INFO | EXTERNAL | {PERFORMANCE} | Identifies foreign key constraints without a covering index, which can impact database performance. | Table \`public.bbb\` has a foreign key \`bbb_foo_bar_fkey\` without a covering index. This can lead to suboptimal query performance. | https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys | {"name": "bbb", "type": "table", "schema": "public", "fkey_name": "bbb_foo_bar_fkey", "fkey_columns": [2, 3]} | unindexed_foreign_keys_public_bbb_bbb_foo_bar_fkey
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------------------------+------------------------+-------+----------+---------------+-----------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------+----------------------------------------------------
unindexed_foreign_keys | Unindexed foreign keys | INFO | EXTERNAL | {PERFORMANCE} | Identifies foreign key constraints without a covering index, which can impact database performance. | Table \`public.bbb\` has a foreign key \`bbb_foo_bar_fkey\` without a covering index. This can lead to suboptimal query performance. | https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys | {"name": "bbb", "type": "table", "schema": "public", "fkey_name": "bbb_foo_bar_fkey", "fkey_columns": [2, 3]} | unindexed_foreign_keys_public_bbb_bbb_foo_bar_fkey
(1 row)

-- Confirm that an index on the correct columns but in the wrong order
-- does NOT resolve the issue
create index on public.bbb(bar, foo);
select * from lint."0001_unindexed_foreign_keys";
name | level | facing | categories | description | detail | remediation | metadata | cache_key
------------------------+-------+----------+---------------+-----------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------+----------------------------------------------------
unindexed_foreign_keys | INFO | EXTERNAL | {PERFORMANCE} | Identifies foreign key constraints without a covering index, which can impact database performance. | Table \`public.bbb\` has a foreign key \`bbb_foo_bar_fkey\` without a covering index. This can lead to suboptimal query performance. | https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys | {"name": "bbb", "type": "table", "schema": "public", "fkey_name": "bbb_foo_bar_fkey", "fkey_columns": [2, 3]} | unindexed_foreign_keys_public_bbb_bbb_foo_bar_fkey
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------------------------+------------------------+-------+----------+---------------+-----------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------+----------------------------------------------------
unindexed_foreign_keys | Unindexed foreign keys | INFO | EXTERNAL | {PERFORMANCE} | Identifies foreign key constraints without a covering index, which can impact database performance. | Table \`public.bbb\` has a foreign key \`bbb_foo_bar_fkey\` without a covering index. This can lead to suboptimal query performance. | https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys | {"name": "bbb", "type": "table", "schema": "public", "fkey_name": "bbb_foo_bar_fkey", "fkey_columns": [2, 3]} | unindexed_foreign_keys_public_bbb_bbb_foo_bar_fkey
(1 row)

-- When we create a multi-column index in the correct order the issue is resolved
create index on public.bbb(foo, bar);
select * from lint."0001_unindexed_foreign_keys";
name | level | facing | categories | description | detail | remediation | metadata | cache_key
------+-------+--------+------------+-------------+--------+-------------+----------+-----------
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------+-------+-------+--------+------------+-------------+--------+-------------+----------+-----------
(0 rows)

rollback;
Loading

0 comments on commit 95f050c

Please sign in to comment.