mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
## 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 <img width="623" height="535" alt="image" src="https://github.com/user-attachments/assets/4c388f4a-753b-4fd6-89c5-89dfaa52c859" /> ## 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; ```
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { IS_PLATFORM } from 'common'
|
|
import type { SqlSnippets, UserContent } from 'types'
|
|
|
|
const SQL_SNIPPET_SCHEMA_VERSION = '1.0'
|
|
|
|
export const NEW_SQL_SNIPPET_SKELETON: UserContent<SqlSnippets.Content> = {
|
|
name: 'New Query',
|
|
description: '',
|
|
type: 'sql',
|
|
visibility: 'user', // default to user scope
|
|
favorite: false,
|
|
content: {
|
|
schema_version: SQL_SNIPPET_SCHEMA_VERSION,
|
|
content_id: '',
|
|
sql: 'this is a test',
|
|
},
|
|
}
|
|
|
|
export const sqlAiDisclaimerComment = `
|
|
-- Supabase AI is experimental and may produce incorrect answers
|
|
-- Always verify the output before executing
|
|
`.trim()
|
|
|
|
// Should only be used for comparisons. If you need a new title, use generateSnippetTitle()
|
|
export const untitledSnippetTitle = 'Untitled query'
|
|
|
|
/**
|
|
* Generates a snippet title. If the platform is self-hosted, it will return a random number to avoid conflicts.
|
|
*/
|
|
export const generateSnippetTitle = () => {
|
|
if (IS_PLATFORM) {
|
|
return untitledSnippetTitle
|
|
} else {
|
|
return `${untitledSnippetTitle} ${Math.floor(Math.random() * 900) + 100}`
|
|
}
|
|
}
|
|
|
|
export const destructiveSqlRegex = [
|
|
/^(.*;)?\s*(drop|delete|truncate|alter\s+table\s+.*\s+drop\s+column)\s/is,
|
|
]
|
|
|
|
export const updateWithoutWhereRegex =
|
|
/(?:^|;)\s*update\s+(?:"[\w.]+"\."[\w.]+"|[\w.]+)\s+set\s+[\w\W]+?(?!\s*where\s)/is
|
|
|
|
export const alterDatabasePreventConnectionStatements = [
|
|
'alter database postgres connection limit 0',
|
|
'alter database postgres allow_connections false',
|
|
]
|
|
|
|
export const ASSISTANT_TEMPLATES = [
|
|
{
|
|
name: 'Twitter clone',
|
|
description: 'Simplified schema that mimics the Twitter application',
|
|
prompt: 'Create a twitter clone',
|
|
},
|
|
{
|
|
name: 'Chat application',
|
|
description: 'Send messages through channels or direct messages',
|
|
prompt:
|
|
'Create a chat application that supports sending messages either through channels or directly between users',
|
|
},
|
|
{
|
|
name: 'User management schema',
|
|
description: 'With role based access control',
|
|
prompt: 'Create a simple user management schema that supports role based access control',
|
|
},
|
|
{
|
|
name: 'Countries and Cities',
|
|
description: 'With each city belonging to a country',
|
|
prompt:
|
|
'Create a table of countries and a table of cities, with each city belonging to a country',
|
|
},
|
|
]
|
|
|
|
export const ROWS_PER_PAGE_OPTIONS = [
|
|
{ value: -1, label: 'No limit' },
|
|
{ value: 100, label: '100 rows' },
|
|
{ value: 500, label: '500 rows' },
|
|
{ value: 1000, label: '1,000 rows' },
|
|
]
|