Skip to content

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

Trim column name in table editor when updating column (#27522)

Joshen Lim553f2aa7fcf7
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts
index f9ce1f04b0a..43b2511f260 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts
@@ -123,18 +123,22 @@ export const generateUpdateColumnPayload = (
const isOriginallyPrimaryKey = primaryKeyColumns.includes(originalColumn.name)
// Only append the properties which are getting updated
+ const name = field.name.trim()
const type = field.isArray ? `${field.format}[]` : field.format
- const comment = (field.comment?.length ?? '') === 0 ? null : field.comment
+ const comment = ((field.comment?.length ?? '') === 0 ? null : field.comment)?.trim()
+ const check = field.check?.trim()
const payload: Partial<UpdateColumnPayload> = {}
- if (!isEqual(originalColumn.name, field.name)) {
- payload.name = field.name
+ // [Joshen] Trimming on the original name as well so we don't rename columns that already
+ // contain whitespaces (and accidentally bringing user apps down)
+ if (!isEqual(originalColumn.name.trim(), name)) {
+ payload.name = name
}
- if (!isEqual(originalColumn.comment, comment)) {
+ if (!isEqual(originalColumn.comment?.trim(), comment)) {
payload.comment = comment as string | undefined
}
- if (!isEqual(originalColumn.check?.trim(), field.check?.trim())) {
- payload.check = field.check?.trim()
+ if (!isEqual(originalColumn.check?.trim(), check)) {
+ payload.check = check
}
if (!isEqual(originalColumn.format, type)) {