@@ -193,16 +193,36 @@ export default function QueryConsole() {
193193 } ) ;
194194 }
195195 } else {
196- const errorData = await response . json ( ) ;
197- setResult ( {
198- success : false ,
199- error : errorData . detail || 'Query execution failed' ,
200- } ) ;
201- toast ( {
202- title : 'Error' ,
203- description : errorData . detail || 'Query execution failed' ,
204- variant : 'destructive' ,
205- } ) ;
196+ // Get response text first, then try to parse as JSON
197+ const responseText = await response . text ( ) ;
198+
199+ try {
200+ const errorData = JSON . parse ( responseText ) ;
201+ setResult ( {
202+ success : false ,
203+ error : errorData . detail || 'Query execution failed' ,
204+ } ) ;
205+ toast ( {
206+ title : 'Error' ,
207+ description : errorData . detail || 'Query execution failed' ,
208+ variant : 'destructive' ,
209+ } ) ;
210+ } catch ( jsonError ) {
211+ // Handle non-JSON error responses (e.g., HTML "Internal Server Error")
212+ const errorMessage = responseText . includes ( 'Internal Server Error' )
213+ ? 'Internal server error occurred. Please check the query syntax and try again.'
214+ : responseText || 'Query execution failed' ;
215+
216+ setResult ( {
217+ success : false ,
218+ error : errorMessage ,
219+ } ) ;
220+ toast ( {
221+ title : 'Error' ,
222+ description : errorMessage ,
223+ variant : 'destructive' ,
224+ } ) ;
225+ }
206226 }
207227 } catch ( error ) {
208228 console . error ( 'Error executing query:' , error ) ;
@@ -537,8 +557,9 @@ WHERE expires_at < NOW() OR is_active = false;`
537557WHERE high_watermark_bytes > 1000000000; -- 1GB threshold`
538558 } ,
539559 {
540- name : '🗑️ Remove old Python version data' ,
541- query : `DELETE FROM runs
560+ name : '🗑️ Remove old Python version data (Step 1: benchmark_results)' ,
561+ query : `-- First delete benchmark_results for old Python versions
562+ DELETE FROM benchmark_results
542563WHERE run_id IN (
543564 SELECT r.run_id
544565 FROM runs r
@@ -547,33 +568,66 @@ WHERE run_id IN (
547568);`
548569 } ,
549570 {
550- name : '🗑️ Delete all data for specific binary' ,
551- query : `-- Delete all runs and results for a specific binary
571+ name : '🗑️ Remove old Python version data (Step 2: runs)' ,
572+ query : `-- Then delete runs for old Python versions
573+ DELETE FROM runs
574+ WHERE run_id IN (
575+ SELECT r.run_id
576+ FROM runs r
577+ JOIN commits c ON r.commit_sha = c.sha
578+ WHERE c.python_major < 3 OR (c.python_major = 3 AND c.python_minor < 10)
579+ );`
580+ } ,
581+ {
582+ name : '🗑️ Delete specific Python version data' ,
583+ query : `-- Template: Replace X with Python minor version (e.g., 15)
584+ -- Run this query twice: first for benchmark_results, then for runs
552585DELETE FROM benchmark_results
553586WHERE run_id IN (
554- SELECT run_id FROM runs WHERE binary_id = 'REPLACE_WITH_BINARY_ID'
587+ SELECT run_id FROM runs WHERE python_minor = X
555588);
589+ -- DELETE FROM runs WHERE python_minor = X;`
590+ } ,
591+ {
592+ name : '🗑️ Delete binary data (Step 1: benchmark_results)' ,
593+ query : `-- First delete benchmark_results for specific binary
594+ DELETE FROM benchmark_results
595+ WHERE run_id IN (
596+ SELECT run_id FROM runs WHERE binary_id = 'REPLACE_WITH_BINARY_ID'
597+ );`
598+ } ,
599+ {
600+ name : '🗑️ Delete binary data (Step 2: runs)' ,
601+ query : `-- Then delete runs for specific binary
556602DELETE FROM runs WHERE binary_id = 'REPLACE_WITH_BINARY_ID';`
557603 } ,
558604 {
559- name : '🗑️ Delete all data for specific environment ' ,
560- query : `-- Delete all runs and results for a specific environment
605+ name : '🗑️ Delete environment data (Step 1: benchmark_results) ' ,
606+ query : `-- First delete benchmark_results for specific environment
561607DELETE FROM benchmark_results
562608WHERE run_id IN (
563609 SELECT run_id FROM runs WHERE environment_id = 'REPLACE_WITH_ENVIRONMENT_ID'
564- );
610+ );`
611+ } ,
612+ {
613+ name : '🗑️ Delete environment data (Step 2: runs)' ,
614+ query : `-- Then delete runs for specific environment
565615DELETE FROM runs WHERE environment_id = 'REPLACE_WITH_ENVIRONMENT_ID';`
566616 } ,
567617 {
568- name : '🗑️ Delete all data older than X months ' ,
569- query : `-- Delete all benchmark data older than 6 months
618+ name : '🗑️ Delete old data (Step 1: benchmark_results) ' ,
619+ query : `-- First delete benchmark_results older than 6 months
570620DELETE FROM benchmark_results
571621WHERE run_id IN (
572622 SELECT r.run_id
573623 FROM runs r
574624 JOIN commits c ON r.commit_sha = c.sha
575625 WHERE c.timestamp < NOW() - INTERVAL '6 months'
576- );
626+ );`
627+ } ,
628+ {
629+ name : '🗑️ Delete old data (Step 2: runs)' ,
630+ query : `-- Then delete runs older than 6 months
577631DELETE FROM runs
578632WHERE run_id IN (
579633 SELECT r.run_id
0 commit comments