Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update destructive regex and add tests (#35423)

Jordi Enricf01b4faab038
diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts b/apps/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts
index 776575c517c..bb8d77a0cad 100644
--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts
+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts
@@ -22,7 +22,9 @@ export const sqlAiDisclaimerComment = `
export const untitledSnippetTitle = 'Untitled query'
-export const destructiveSqlRegex = [/^(.*;)?\s*(drop|delete|truncate)\s/is]
+export const destructiveSqlRegex = [
+ /^(.*;)?\s*(drop|delete|truncate|alter\s+table\s+.*\s+drop\s+column)\s/is,
+]
export const ASSISTANT_TEMPLATES = [
{
diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts b/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts
index bea8f7a8f91..b8736ded8e1 100644
--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts
+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts
@@ -246,4 +246,17 @@ describe('SQLEditor.utils:updateWithoutWhere', () => {
expect(match).toBe(true)
})
+
+ it('should catch potential destructive queries', () => {
+ const DESTRUCTIVE_QUERIES = [
+ `ALTER TABLE test DROP COLUMN test;`,
+ `DELETE FROM test;`,
+ `DROP TABLE test;`,
+ `TRUNCATE TABLE test;`,
+ ]
+
+ DESTRUCTIVE_QUERIES.forEach((query) => {
+ expect(checkDestructiveQuery(query), `Query ${query} should be destructive`).toBe(true)
+ })
+ })
})