Skip to content
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
8 changes: 6 additions & 2 deletions lints/0001_unindexed_foreign_keys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ create view lint."0001_unindexed_foreign_keys" as

with foreign_keys as (
select
cl.relnamespace::regnamespace::text as schema_name,
ns.nspname as schema_name,
cl.relname as table_name,
cl.oid as table_oid,
ct.conname as fkey_name,
Expand All @@ -11,13 +11,16 @@ with foreign_keys as (
pg_catalog.pg_constraint ct
join pg_catalog.pg_class cl -- fkey owning table
on ct.conrelid = cl.oid
join pg_catalog.pg_namespace ns
on cl.relnamespace = ns.oid
left join pg_catalog.pg_depend d
on d.objid = cl.oid
and d.deptype = 'e'
and d.classid = 'pg_catalog.pg_class'::regclass
where
ct.contype = 'f' -- foreign key constraints
and d.objid is null -- exclude tables that are dependencies of extensions
and cl.relnamespace::regnamespace::text not in (
and ns.nspname not in (
'pg_catalog', 'information_schema', 'auth', 'storage', 'vault', 'extensions'
)
),
Expand Down Expand Up @@ -61,6 +64,7 @@ from
left join pg_catalog.pg_depend dep
on idx.table_oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
idx.index_ is null
and fk.schema_name not in (
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 @@ -32,6 +32,7 @@ from
left join pg_catalog.pg_depend dep
on pgc.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
pgc.relkind = 'r' -- regular tables
and pgns.nspname not in (
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 @@ -33,6 +33,7 @@ from
left join pg_catalog.pg_depend dep
on psui.relid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
psui.idx_scan = 0
and not pi.indisunique
Expand Down
3 changes: 2 additions & 1 deletion lints/0006_multiple_permissive_policies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ from
or p.polroles = array[0::oid]
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e',
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass,
lateral (
select x.cmd
from unnest((
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 @@ -33,6 +33,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'r' -- regular tables
and n.nspname not in (
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 @@ -32,6 +32,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'r' -- regular tables
and n.nspname not in (
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 @@ -40,6 +40,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind in ('r', 'm') -- tables and materialized views
and n.nspname not in (
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 @@ -30,6 +30,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'v'
and (
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 @@ -31,6 +31,7 @@ from
left join pg_catalog.pg_depend dep
on p.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_proc'::regclass
where
n.nspname not in (
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config', '_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql', 'graphql_public', 'information_schema', 'net', 'pgmq', 'pgroonga', 'pgsodium', 'pgsodium_masks', 'pgtle', 'pgbouncer', 'pg_catalog', 'realtime', 'repack', 'storage', 'supabase_functions', 'supabase_migrations', 'tiger', 'topology', 'vault'
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 @@ -30,6 +30,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'm'
and (
Expand Down
1 change: 1 addition & 0 deletions lints/0017_foreign_table_in_api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'f'
and (
Expand Down
20 changes: 17 additions & 3 deletions splinter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set local search_path = '';
(
with foreign_keys as (
select
cl.relnamespace::regnamespace::text as schema_name,
ns.nspname as schema_name,
cl.relname as table_name,
cl.oid as table_oid,
ct.conname as fkey_name,
Expand All @@ -12,13 +12,16 @@ with foreign_keys as (
pg_catalog.pg_constraint ct
join pg_catalog.pg_class cl -- fkey owning table
on ct.conrelid = cl.oid
join pg_catalog.pg_namespace ns
on cl.relnamespace = ns.oid
left join pg_catalog.pg_depend d
on d.objid = cl.oid
and d.deptype = 'e'
and d.classid = 'pg_catalog.pg_class'::regclass
where
ct.contype = 'f' -- foreign key constraints
and d.objid is null -- exclude tables that are dependencies of extensions
and cl.relnamespace::regnamespace::text not in (
and ns.nspname not in (
'pg_catalog', 'information_schema', 'auth', 'storage', 'vault', 'extensions'
)
),
Expand Down Expand Up @@ -62,6 +65,7 @@ from
left join pg_catalog.pg_depend dep
on idx.table_oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
idx.index_ is null
and fk.schema_name not in (
Expand Down Expand Up @@ -296,6 +300,7 @@ from
left join pg_catalog.pg_depend dep
on pgc.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
pgc.relkind = 'r' -- regular tables
and pgns.nspname not in (
Expand Down Expand Up @@ -343,6 +348,7 @@ from
left join pg_catalog.pg_depend dep
on psui.relid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
psui.idx_scan = 0
and not pi.indisunique
Expand Down Expand Up @@ -392,7 +398,8 @@ from
or p.polroles = array[0::oid]
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e',
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass,
lateral (
select x.cmd
from unnest((
Expand Down Expand Up @@ -459,6 +466,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'r' -- regular tables
and n.nspname not in (
Expand Down Expand Up @@ -504,6 +512,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'r' -- regular tables
and n.nspname not in (
Expand Down Expand Up @@ -558,6 +567,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind in ('r', 'm') -- tables and materialized views
and n.nspname not in (
Expand Down Expand Up @@ -603,6 +613,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'v'
and (
Expand Down Expand Up @@ -657,6 +668,7 @@ from
left join pg_catalog.pg_depend dep
on p.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_proc'::regclass
where
n.nspname not in (
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config', '_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql', 'graphql_public', 'information_schema', 'net', 'pgmq', 'pgroonga', 'pgsodium', 'pgsodium_masks', 'pgtle', 'pgbouncer', 'pg_catalog', 'realtime', 'repack', 'storage', 'supabase_functions', 'supabase_migrations', 'tiger', 'topology', 'vault'
Expand Down Expand Up @@ -830,6 +842,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'm'
and (
Expand Down Expand Up @@ -873,6 +886,7 @@ from
left join pg_catalog.pg_depend dep
on c.oid = dep.objid
and dep.deptype = 'e'
and dep.classid = 'pg_catalog.pg_class'::regclass
where
c.relkind = 'f'
and (
Expand Down
Loading