Skip to content

Commit 7d162d9

Browse files
authored
Merge pull request #8 from SFTtech/milo/db-migration-filter-extensions
fix(sftkit): filter out database functions belonging to postgres user / loaded extensions
2 parents 5932a5e + 580fe77 commit 7d162d9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sftkit/src/sftkit/database/introspection/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ class PgFunctionDef(BaseModel):
3737

3838

3939
async def list_functions(conn: Connection, schema: str) -> list[PgFunctionDef]:
40+
"""
41+
List all functions which are owned by the current database user and do not belong to any extension.
42+
"""
4043
return await conn.fetch_many(
4144
PgFunctionDef,
42-
"select pg_proc.*, pg_get_function_identity_arguments(oid) as signature from pg_proc "
43-
"where pronamespace = $1::regnamespace and pg_proc.proname !~ '^pg_';",
45+
"select p.*, pg_get_function_identity_arguments(p.oid) as signature from pg_proc as p "
46+
"join pg_authid as a on p.proowner = a.oid "
47+
"where p.pronamespace = $1::regnamespace and a.rolname = CURRENT_USER "
48+
" and not exists(select from pg_depend as d where d.objid = p.oid and d.deptype = 'e')",
4449
schema,
4550
)
4651

0 commit comments

Comments
 (0)