Skip to content

Add warning in SQL editor when running alter db commands which prevents connections to the DB - #43584

Merged
joshenlim merged 4 commits into
masterfrom
joshen/fe-2733-warnconfirm-before-risky-alter-database-statements-in-sql
Mar 11, 2026
Merged

joshenlim merged 4 commits into
masterfrom
joshen/fe-2733-warnconfirm-before-risky-alter-database-statements-in-sql

Conversation

@joshenlim

Copy link
Copy Markdown
Member

Context

Adds a warning if running an ALTER DATABASE command that prevents connections to the database. This would lock the dashboard out of the database, and re-configuring the setting will require a direct connection to the DB

image

To test

  • Could try running the following command in the SQL editor to check the warning, this will show all the warnings
ALTER TABLE colors2 drop column sss;
update colors set name = 'test';
alter database postgres connection limit 0;

@joshenlim
joshenlim requested a review from a team as a code owner March 10, 2026 08:50
@vercel

vercel Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

9 Skipped Deployments
Project Deployment Actions Updated (UTC)
cms Ignored Ignored Mar 11, 2026 8:02am
studio Ignored Ignored Mar 11, 2026 8:02am
design-system Skipped Skipped Mar 11, 2026 8:02am
docs Skipped Skipped Mar 11, 2026 8:02am
learn Skipped Skipped Mar 11, 2026 8:02am
studio-self-hosted Skipped Skipped Mar 11, 2026 8:02am
studio-staging Skipped Skipped Mar 11, 2026 8:02am
ui-library Skipped Skipped Mar 11, 2026 8:02am
zone-www-dot-com Skipped Skipped Mar 11, 2026 8:02am

Request Review

@supabase

supabase Bot commented Mar 10, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 35771df8-ecf6-49c4-8ba8-b5cc8bdb3a6f

📥 Commits

Reviewing files that changed from the base of the PR and between b110077 and da373c8.

📒 Files selected for processing (1)
  • e2e/studio/features/sql-editor.spec.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Detects SQL that can prevent DB connections and flags UPDATEs missing WHERE.
  • Refactor

    • Consolidated multiple warning flags into a single issue flow and simplified modal handling.
  • UI

    • Plural-aware alert titles and clearer warning messages and list styling for multiple issues.
  • Tests

    • Added unit and end-to-end tests covering risky-statement detection and warning/modal behavior.

Walkthrough

The changes centralize SQL-safety detection by introducing a new exported type PotentialIssues and replacing separate boolean props/state with a single potentialIssues object. New constants (updateWithoutWhereRegex, alterDatabasePreventConnectionStatements) and a utility checkAlterDatabaseConnection were added and used by SQLEditor to populate potentialIssues. The RunQueryWarningModal component now accepts and displays multiple issue types. SQLEditor state and modal control flow were updated accordingly. E2E and unit tests were added to cover the new detection logic.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant SQLEditor
    participant Validator as "Validator\n(constants + utils)"
    participant RunQueryWarningModal as "RunQueryWarningModal"
    participant Server as "Server/Database"

    User->>SQLEditor: Click "Run" with SQL
    SQLEditor->>Validator: analyze SQL (destructive / updateWithoutWhere / alterDBConnection)
    Validator-->>SQLEditor: PotentialIssues (object or undefined)

    alt issues detected
        SQLEditor->>RunQueryWarningModal: show(potentialIssues)
        RunQueryWarningModal-->>User: display warnings
        User->>RunQueryWarningModal: Confirm
        RunQueryWarningModal-->>SQLEditor: onConfirm (clear potentialIssues)
        SQLEditor->>Server: execute SQL
        Server-->>SQLEditor: execution result
        SQLEditor-->>User: show result
    else no issues
        SQLEditor->>Server: execute SQL
        Server-->>SQLEditor: execution result
        SQLEditor-->>User: show result
    end
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@djhi

djhi commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Tested on staging

@github-actions

github-actions Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  159 passed
flaky  1 flaky
skipped  4 skipped

Details

stats  164 tests across 20 suites
duration  7 minutes, 56 seconds
commit  da373c8

Flaky tests

Features › realtime-inspector.spec.ts › Realtime Inspector › Broadcast Messages › broadcast modal validates JSON payload

Skipped tests

Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@e2e/studio/features/sql-editor.spec.ts`:
- Around line 170-192: The test currently only verifies the warning modal is
visible but not that it blocks execution; update the test to intercept/monitor
the POST to the query endpoint (the pg-meta ... query?key= request) before
clicking the SQL run button and assert that no such POST is sent until the user
confirms the modal; use the existing UI hooks like
page.getByTestId('sql-run-button'), the modal heading 'Potential issue detected
with', and the modal confirm button (instead of Cancel) to trigger the request,
then assert the POST is observed after confirmation; apply the same
interception/assertion pattern to the other similar tests that check this modal.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 2423c626-d2b7-427f-b39f-c1d0f88a986b

📥 Commits

Reviewing files that changed from the base of the PR and between 4a94b58 and b110077.

📒 Files selected for processing (1)
  • e2e/studio/features/sql-editor.spec.ts

Comment thread e2e/studio/features/sql-editor.spec.ts Resolved
Comment thread e2e/studio/features/sql-editor.spec.ts Resolved
@joshenlim
joshenlim merged commit eeacb97 into master Mar 11, 2026
24 of 28 checks passed
@joshenlim
joshenlim deleted the joshen/fe-2733-warnconfirm-before-risky-alter-database-statements-in-sql branch March 11, 2026 08:34
@github-actions

github-actions Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1773218199)

Score Average Improvements Regressions
Completeness 97.2% (+0pp) 1 🟢 1 🔴
Conciseness 0% (-1pp) - 1 🔴
Correctness 100% (+0pp) - -
Docs Faithfulness 61.1% (+3pp) 1 🟢 -
Goal Completion 95.8% (+4pp) 3 🟢 1 🔴
Tool Usage 97% (-3pp) - 1 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
URL Validity 100% (+0pp) - -
Time_to_first_token 0.17tok (-0.02tok) 9 🟢 3 🔴
Llm_calls 8.39 (+0.06) 4 🟢 3 🔴
Tool_calls 3.08 (+0.08) 5 🟢 3 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 59911.11tok (+9702.5tok) 6 🟢 6 🔴
Prompt_cached_tokens 24526.22tok (-1536tok) 8 🟢 3 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Completion_tokens 2725.36tok (+123.81tok) 4 🟢 8 🔴
Completion_reasoning_tokens 1948.44tok (+72.89tok) 3 🟢 8 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 62636.47tok (+9826.31tok) 5 🟢 7 🔴
Estimated_cost 0.01$ (+0$) 6 🟢 5 🔴
Duration 39.67s (+6.04s) 3 🟢 9 🔴
Llm_duration 77.83s (+11.89s) 3 🟢 9 🔴

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