Skip to content

feat(db): add supabase db advisors command for checking security and performance issues#4957

Draft
Rodriguespn wants to merge 1 commit intodevelopfrom
feat/db-advisors
Draft

feat(db): add supabase db advisors command for checking security and performance issues#4957
Rodriguespn wants to merge 1 commit intodevelopfrom
feat/db-advisors

Conversation

@Rodriguespn
Copy link

Summary

Add supabase db advisors command that checks the database for security and performance issues — the CLI equivalent of the get_advisors MCP tool.

Why do we need this if we already have get_advisors in the MCP server?

Same reasoning as supabase db query (#4955): the MCP server works well for agents that go through the OAuth flow for remote projects, but for local development the human still has to reload the agent session to load MCP tools into context. This adds friction to a path that should be fully agentic (no human in the loop).

With this command, an agent can check the security posture of the local database using just the CLI — no MCP configuration needed.

Example use case: security-aware migrations. The agent applies a migration that creates new tables, then runs supabase db advisors --type security to verify RLS is enabled and policies exist. If issues are found, the agent can fix them before committing the migration. Today this requires the get_advisors MCP tool to be configured. With this command, the entire flow only needs the CLI.

Implementation

  • Local (supabase db advisors, default): Executes the same splinter SQL lints that the Studio dashboard runs. Uses pgx to connect directly to the local Postgres — consistent with every other local db subcommand (push, pull, diff, lint, test, reset, dump). Runs in a read-only transaction (always rolled back). No extensions required.
  • Remote (supabase db advisors --linked): Calls the Management API endpoints (GET /v1/projects/{ref}/advisors/security and GET /v1/projects/{ref}/advisors/performance), authenticated with the access token from supabase login.

Differences from db lint

db lint db advisors
Purpose Checks PL/pgSQL function bodies for type errors Checks database security posture and performance issues
Scope Function-level code quality Schema-level security/performance (RLS, indexes, auth config)
Extension Requires plpgsql_check No extensions needed
Checks Syntax/type errors in functions 23 checks: missing RLS, exposed auth.users, unused indexes, missing primary keys, etc.

Usage

# Local (default) — checks the local database
supabase db advisors

# Security checks only
supabase db advisors --type security

# Performance checks only
supabase db advisors --type performance

# Remote — checks the linked project via Management API
supabase db advisors --linked

# Include INFO-level issues (default is WARN+)
supabase db advisors --level info

# CI: exit non-zero on errors
supabase db advisors --fail-on error

Test plan

go test ./internal/db/advisors/... — 15 unit tests covering:

  • Local: query parsing, empty results, query errors
  • Filtering: by type (security/performance/all), by level (info/warn/error), combined
  • Output: JSON encoding, no-issues message, fail-on thresholds
  • API: response conversion, security/performance fetch, error handling

…d performance issues

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Rodriguespn Rodriguespn self-assigned this Mar 15, 2026
@coveralls
Copy link

Pull Request Test Coverage Report for Build 23119563210

Details

  • 109 of 191 (57.07%) changed or added relevant lines in 2 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.09%) to 61.643%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/db.go 0 23 0.0%
internal/db/advisors/advisors.go 109 168 64.88%
Files with Coverage Reduction New Missed Lines %
internal/utils/git.go 5 57.14%
Totals Coverage Status
Change from base Build 23067059123: -0.09%
Covered Lines: 7828
Relevant Lines: 12699

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants