Repository: supabase/supabase
File: apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts (TypeScript)

Code before:
  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?.trim()
  const check = field.check?.trim()

  const payload: Partial<UpdateColumnPayload> = {}
  // [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?.trim(), comment)) {
    payload.comment = comment
  }
  if (!isEqual(originalColumn.check?.trim(), check)) {
    payload.check = check
  }

  const originalFormat =
    originalColumn.data_type === 'ARRAY'
      ? `${originalColumn.format.replace(/^_/, '')}[]`
      : originalColumn.format
  if (!isEqual(originalFormat, type)) {
    payload.type = type
  }
  if (!isEqual(originalColumn.default_value, field.defaultValue)) {
    const defaultValue = field.defaultValue
    payload.defaultValue = defaultValue as unknown as Record<string, never> | undefined
    payload.defaultValueFormat =
      isNull(defaultValue) || isSQLExpression(defaultValue) ? 'expression' : 'literal'
  }
  if (!isEqual(originalColumn.is_identity, field.isIdentity)) {
    payload.isIdentity = field.isIdentity
  }
  if (!isEqual(originalColumn.is_nullable, field.isNullable)) {
    payload.isNullable = field.isNullable
  }
  if (!isEqual(originalColumn.is_unique, field.isUnique)) {
    payload.isUnique = field.isUnique
  }
  if (!isEqual(isOriginallyPrimaryKey, field.isPrimaryKey)) {
    payload.isPrimaryKey = field.isPrimaryKey
  }

  return payload
}

export const validateFields = (field: ColumnField) => {

Review comment (refactor):
tiny tiny nit but we can probably just use `===` since these are all just strings - was old code leaning too much into lodash back then 😬 

i'll push up a refactor for this and the other parts in this function 🙏 

Code after:
  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?.trim()
  const check = field.check?.trim()

  const payload: Partial<UpdateColumnPayload> = {}
  // [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 (originalColumn.name.trim() !== name) {
    payload.name = name
  }
  if (originalColumn.comment?.trim() !== comment) {
    payload.comment = comment
  }
  if (originalColumn.check?.trim() !== check) {
    payload.check = check
  }

  const originalFormat =
    originalColumn.data_type === 'ARRAY'
      ? `${originalColumn.format.replace(/^_/, '')}[]`
      : originalColumn.format
  if (originalFormat !== type) {
    payload.type = type
  }

  if (originalColumn.default_value !== field.defaultValue) {
    const defaultValue = field.defaultValue
    payload.defaultValue = defaultValue as unknown as Record<string, never> | undefined
    payload.defaultValueFormat =
      isNull(defaultValue) || isSQLExpression(defaultValue) ? 'expression' : 'literal'
  }
  if (originalColumn.is_identity !== field.isIdentity) {
    payload.isIdentity = field.isIdentity
  }
  if (originalColumn.is_nullable !== field.isNullable) {
    payload.isNullable = field.isNullable
  }
  if (originalColumn.is_unique !== field.isUnique) {
    payload.isUnique = field.isUnique
  }
  if (isOriginallyPrimaryKey !== field.isPrimaryKey) {
    payload.isPrimaryKey = field.isPrimaryKey
  }

  return payload
}