fix: preview actual DROP INDEX sql in drop confirmation

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Diego Imbert
2026-06-02 13:58:30 +02:00
parent dd00f184c0
commit 31f6ca47e2
3 changed files with 54 additions and 10 deletions
@@ -2005,6 +2005,29 @@ impl FromSql<'_> for StringCollector {
mod tests {
use super::*;
#[test]
fn test_statement_requires_no_transaction() {
// CONCURRENTLY index DDL must bypass the implicit transaction.
assert!(statement_requires_no_transaction(
"CREATE INDEX CONCURRENTLY idx ON t (a)"
));
assert!(statement_requires_no_transaction(
"create unique index concurrently idx on t (a)"
));
assert!(statement_requires_no_transaction(
"DROP INDEX CONCURRENTLY IF EXISTS idx"
));
assert!(statement_requires_no_transaction(
" REINDEX INDEX CONCURRENTLY idx"
));
// Plain DDL and unrelated statements stay on the normal path.
assert!(!statement_requires_no_transaction(
"CREATE INDEX idx ON t (a)"
));
assert!(!statement_requires_no_transaction("DROP INDEX idx"));
assert!(!statement_requires_no_transaction("SELECT 1"));
}
#[test]
fn test_parse_naive_date() {
// chrono's NaiveDate::to_string() format
@@ -109,17 +109,29 @@
}
}
function openDropConfirm(idx: DbIndex) {
confirm = {
open: true,
title: `Drop index "${idx.name}"?`,
confirmationText: 'Drop index',
code: idx.definition,
onConfirm: async () => {
await dbIndexOps.dropIndex({ name: idx.name, schema, concurrent: true })
sendUserToast('Index dropped')
indexes.refetch()
async function openDropConfirm(idx: DbIndex) {
busy = true
try {
const sql = await dbIndexOps.previewDropIndexSql({
name: idx.name,
schema,
concurrent: true
})
confirm = {
open: true,
title: `Drop index "${idx.name}"?`,
confirmationText: 'Drop index',
code: sql,
onConfirm: async () => {
await dbIndexOps.dropIndex({ name: idx.name, schema, concurrent: true })
sendUserToast('Index dropped')
indexes.refetch()
}
}
} catch (e) {
toastErr(e)
} finally {
busy = false
}
}
+9
View File
@@ -301,6 +301,11 @@ export type IDbIndexOps = {
values: CreateIndexInput
}) => Promise<string>
dropIndex: (params: { name: string; schema?: string; concurrent?: boolean }) => Promise<void>
previewDropIndexSql: (params: {
name: string
schema?: string
concurrent?: boolean
}) => Promise<string>
}
export function dbIndexOpsWithPreviewScripts({
@@ -366,6 +371,10 @@ export function dbIndexOpsWithPreviewScripts({
workspace,
requestBody: { args: { ...dbArg }, language, content }
})
},
previewDropIndexSql: async ({ name, schema, concurrent }) => {
const content = makeMarker('DROP_INDEX', { name, schema, concurrent: concurrent ?? false })
return expandMarker(workspace, language, content)
}
}
}