fix: update to rollback and changes with insert,update or delete on pretty explai (#41651)

update to rollback and changes with insert,update or delete
This commit is contained in:
Ali Waseem authored and GitHub committed 2025-12-30 09:29:38 -07:00
1 parent 0ac60955c1
commit b6874ff76d
2 files changed
+19 -2

No files matched your search

@@ -20,6 +20,7 @@ import { constructHeaders, isValidConnString } from 'data/fetchers'
import { lintKeys } from 'data/lint/keys'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { useExecuteSqlMutation } from 'data/sql/execute-sql-mutation'
import { wrapWithRollback } from 'data/sql/utils/transaction'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { isError } from 'data/utils/error-check'
import { useOrgAiOptInLevel } from 'hooks/misc/useOrgOptedIntoAi'
@@ -409,10 +410,16 @@ export const SQLEditor = () => {
// Wrap the query with EXPLAIN ANALYZE only if it's not already an EXPLAIN query
const explainSql = isExplainSql(sql) ? sql : `EXPLAIN ANALYZE ${sql}`
// Wrap EXPLAIN queries in a transaction with rollback to prevent data modifications
// This ensures EXPLAIN ANALYZE INSERT/UPDATE/DELETE queries don't actually modify data
const explainSqlWithTransaction = wrapWithRollback(
wrapWithRoleImpersonation(explainSql, impersonatedRoleState)
)
executeExplain({
projectRef: project.ref,
connectionString: connectionString,
sql: wrapWithRoleImpersonation(explainSql, impersonatedRoleState),
sql: explainSqlWithTransaction,
isRoleImpersonationEnabled: isRoleImpersonationEnabled(impersonatedRoleState.role),
handleError: (error) => {
throw error
+11 -1
View File
@@ -1,9 +1,19 @@
export function wrapWithTransaction(sql: string) {
return /* SQL */ `
begin;
${sql}
commit;
`
}
export function wrapWithRollback(sql: string) {
return /* SQL */ `
begin;
${sql}
rollback;
`
}