The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Deprecate the use of unescapeLiteral in ColumnEditor
Joshen Lim006fe2463d3b
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsxindex 5c21cec1cb1..768061dd739 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx@@ -128,6 +128,7 @@ const ColumnEditor: FC<Props> = ({? { ...columnFields.foreignKey, source_column_name: columnFields.name }: undefinedconst configuration = { columnId: column?.id }+ console.log('onSaveChanges', payload)saveChanges(payload, foreignKey, isNewRecord, configuration, resolve)} else {resolve()diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.tsindex 030957ec7a5..64bc70e4eab 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts@@ -62,7 +62,7 @@ export const generateColumnFieldFromPostgresColumn = (name: column.name,comment: column?.comment ?? '',format: isArray ? column.format.slice(1) : column.format,- defaultValue: unescapeLiteral(column?.default_value as string),+ defaultValue: (column?.default_value ?? '') as string,isArray: isArray,isNullable: column.is_nullable,isIdentity: column.is_identity,@@ -127,7 +127,7 @@ export const generateUpdateColumnPayload = (if (!isEqual(originalColumn.format, type)) {payload.type = type}- if (!isEqual(unescapeLiteral(originalColumn.default_value as string), defaultValue)) {+ if (!isEqual(originalColumn.default_value as string, defaultValue)) {payload.defaultValue = defaultValuepayload.defaultValueFormat =isNull(defaultValue) || isSQLExpression(defaultValue)@@ -205,64 +205,3 @@ const formatArrayToPostgresArray = (arrayString: string) => {if (!arrayString) return nullreturn arrayString.replaceAll('[', '{').replaceAll(']', '}')}--export const unescapeLiteral = (value: string) => {- if (!value) return value-- // Handle combinations - this is really not the best solution imo- // It's a log(n) attempt to strip off the ::type strings- if (value.includes('||')) {- const formattedValue = []- let found = false- for (let i = 0; i < value.length; i++) {- if (value[i] === ':') found = true- if (((value[i] === ' ' || value[i] === ')') && found) || i === value.length - 1) found = false- if (!found) formattedValue.push(value[i])- }- return formattedValue.join('')- }-- const splits = value.split("'::")- if (splits.length <= 1) return value-- // Handle timezones- if (value.toLowerCase().includes('time zone')) {- return `${splits[0].toLowerCase()}')`- }-- // Handle nextval- if (value.toLowerCase().includes('nextval')) {- return `${splits[0]}')`- }-- // Handle json- if (value.toLowerCase().includes('json')) {- return splits[0].slice(1)- }-- let temp = splits[0].slice(1).replace("'{", '{')- if (- value.endsWith('integer[]') ||- value.endsWith('real[]') ||- value.endsWith('bigint[]') ||- value.endsWith('smallint[]')- ) {- temp = temp.replace(/{/g, '[')- temp = temp.replace(/}/g, ']')- return temp- } else {- const matches = temp.match(/\{([^{}]+)\}/g)- if (matches) {- const array = [...matches]- array.forEach((x) => {- let _x = x.replace(/{/g, '{"')- _x = _x.replace(/}/g, '"}')- _x = _x.replace(/,/g, '","')- temp = temp.replace(x, _x)- })- temp = temp.replace(/{/g, '[')- temp = temp.replace(/}/g, ']')- }- return temp- }-}diff --git a/studio/tests/components/Editor/ColumnEditor.utils.test.js b/studio/tests/components/Editor/ColumnEditor.utils.test.jsdeleted file mode 100644index c147fa07a13..00000000000--- a/studio/tests/components/Editor/ColumnEditor.utils.test.js+++ /dev/null@@ -1,72 +0,0 @@-import { unescapeLiteral } from 'components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils'--describe('ColumnEditor.utils: unescapeLiteral', () => {- test('should return varchar properly', () => {- const mockInput = `nextval('"Test_id_seq"'::regclass)`- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual(`nextval('"Test_id_seq"')`)- })- test('should return varchar properly', () => {- const mockInput = "'potato'::character varying"- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual('potato')- })- test('should return text properly', () => {- const mockInput = "'tomato'::text"- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual('tomato')- })- test('should return null properly', () => {- const mockInput = null- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual(null)- })- test('should return empty string properly', () => {- const mockInput = `''::text`- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual('')- })- test('should return numerical arrays properly', () => {- const mockInput = "'{1,2,3,4}'::integer[]"- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual('[1,2,3,4]')- })- test('should return string arrays properly', () => {- const mockInput = "'{apple,orange}'::text[]"- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual('["apple","orange"]')- })- test('should return single word functions as they are', () => {- const mockInput = 'uuid_generate_v4()'- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual(mockInput)- })- test('should return functions beyond one word properly', () => {- const mockInput = "(now() AT TIME ZONE 'utc'::text)"- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual("(now() at time zone 'utc')")- })- test('should return expressions that combine values properly', () => {- const mockInput1 = "('hi_'::text || uuid_generate_v4())"- const value1 = unescapeLiteral(mockInput1)- expect(value1).toStrictEqual("('hi_' || uuid_generate_v4())")-- const mockInput2 = "(('hi'::text || 'bye'::text) || 'hello'::text)"- const value2 = unescapeLiteral(mockInput2)- expect(value2).toStrictEqual("(('hi' || 'bye') || 'hello')")-- const mockInput3 = "(uuid_generate_v4() || 'hello'::text)"- const value3 = unescapeLiteral(mockInput3)- expect(value3).toStrictEqual("(uuid_generate_v4() || 'hello')")- })- test('should return json object properly', () => {- const mockInput = `'{\"version\": 10, \"dimensions\": {\"width\": 50, \"height\": 20}}'::jsonb`- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual('{"version": 10, "dimensions": {"width": 50, "height": 20}}')- })- test('should return json array properly', () => {- const mockInput = `'[{\"version\": 10}, {\"version\": 11}]'::jsonb`- const value = unescapeLiteral(mockInput)- expect(value).toStrictEqual('[{"version": 10}, {"version": 11}]')- })-})