From e10cf3ebfd537471d656eb49c244efc245fbdb71 Mon Sep 17 00:00:00 2001 From: Alaister Young Date: Tue, 11 Apr 2023 19:29:30 +1000 Subject: [PATCH] adds updating of check constraints --- package-lock.json | 16 ++++++++-------- .../ColumnEditor/ColumnEditor.tsx | 1 + .../ColumnEditor/ColumnEditor.utils.ts | 8 ++++++-- .../SidePanelEditor/SidePanelEditor.types.ts | 5 +++-- studio/package.json | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 67067295f21..0a726b40db4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9529,9 +9529,9 @@ } }, "node_modules/@supabase/postgres-meta": { - "version": "0.62.0", - "resolved": "https://registry.npmjs.org/@supabase/postgres-meta/-/postgres-meta-0.62.0.tgz", - "integrity": "sha512-35p2KJXq1tvzIuEa1VTEbRl5Or5qQEYFLZmG30LwdyDYGzdVtuQ03rYpQLMKAG8ueuhul+PN0WCPfvH1yq3DhA==", + "version": "0.64.4", + "resolved": "https://registry.npmjs.org/@supabase/postgres-meta/-/postgres-meta-0.64.4.tgz", + "integrity": "sha512-QLRsNEPCi1VExZJqDy41YPzsAfXDyP/qB4fXu6G+EjcToONUGbi1zHFkBR9bqyAEE0dP+cf11+ZMD4cAXJ+7JQ==", "dev": true, "dependencies": { "@sinclair/typebox": "^0.25.1", @@ -39094,7 +39094,7 @@ "@storybook/addon-links": "^6.4.19", "@storybook/react": "^6.4.19", "@storybook/testing-library": "^0.0.9", - "@supabase/postgres-meta": "^0.62.0", + "@supabase/postgres-meta": "^0.64.4", "@tailwindcss/typography": "^0.5.2", "@testing-library/dom": "^8.19.0", "@testing-library/react": "^12.1.5", @@ -45927,9 +45927,9 @@ } }, "@supabase/postgres-meta": { - "version": "0.62.0", - "resolved": "https://registry.npmjs.org/@supabase/postgres-meta/-/postgres-meta-0.62.0.tgz", - "integrity": "sha512-35p2KJXq1tvzIuEa1VTEbRl5Or5qQEYFLZmG30LwdyDYGzdVtuQ03rYpQLMKAG8ueuhul+PN0WCPfvH1yq3DhA==", + "version": "0.64.4", + "resolved": "https://registry.npmjs.org/@supabase/postgres-meta/-/postgres-meta-0.64.4.tgz", + "integrity": "sha512-QLRsNEPCi1VExZJqDy41YPzsAfXDyP/qB4fXu6G+EjcToONUGbi1zHFkBR9bqyAEE0dP+cf11+ZMD4cAXJ+7JQ==", "dev": true, "requires": { "@sinclair/typebox": "^0.25.1", @@ -65994,7 +65994,7 @@ "@storybook/testing-library": "^0.0.9", "@stripe/react-stripe-js": "^1.7.0", "@stripe/stripe-js": "^1.25.0", - "@supabase/postgres-meta": "^0.62.0", + "@supabase/postgres-meta": "^0.64.4", "@supabase/react-data-grid": "^7.1.0-beta.7", "@supabase/shared-types": "^0.1.40", "@supabase/supabase-js": "^2.13.0", diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx index dafb2da326b..7bb69ff989c 100644 --- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx +++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx @@ -345,6 +345,7 @@ const ColumnEditor = ({ type="text" value={columnFields?.check ?? ''} onChange={(event: any) => onUpdateField({ check: event.target.value })} + className="[&_input]:font-mono" /> diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts index f1b31300425..98c92be6f42 100644 --- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts +++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts @@ -73,7 +73,7 @@ export const generateColumnFieldFromPostgresColumn = ( comment: column?.comment ?? '', format: isArray ? column.format.slice(1) : column.format, defaultValue: column?.default_value as string | null, - check: null, + check: column.check, isArray: isArray, isNullable: column.is_nullable, isIdentity: column.is_identity, @@ -97,7 +97,7 @@ export const generateCreateColumnPayload = ( name: field.name, comment: field.comment, type: field.isArray ? `${field.format}[]` : field.format, - check: field.check ?? undefined, + check: field.check?.trim() || undefined, isUnique: field.isUnique, isPrimaryKey: field.isPrimaryKey, ...(!field.isPrimaryKey && !isIdentity && { isNullable: field.isNullable }), @@ -137,6 +137,10 @@ export const generateUpdateColumnPayload = ( if (!isEqual(originalColumn.comment, comment)) { payload.comment = comment } + if (!isEqual(originalColumn.check?.trim(), field.check?.trim())) { + payload.check = field.check?.trim() || null + } + if (!isEqual(originalColumn.format, type)) { payload.type = type } diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.ts index 7d52f817a15..392a449c00f 100644 --- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.ts +++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.ts @@ -4,7 +4,7 @@ export interface CreateColumnPayload { tableId: number name: string type: string - check?: string + check?: string | null comment?: string defaultValue?: any defaultValueFormat?: 'expression' | 'literal' @@ -19,6 +19,7 @@ export interface UpdateColumnPayload { name?: string comment?: string | null type?: string + check?: string | null dropDefault?: boolean defaultValue?: any defaultValueFormat?: 'expression' | 'literal' @@ -63,11 +64,11 @@ export interface ExtendedPostgresRelationship extends PostgresRelationship { export interface ColumnField { id: string name: string + check: string | null comment?: string format: string defaultValue: string | null foreignKey: ExtendedPostgresRelationship | undefined - check: string | null isNullable: boolean isUnique: boolean isArray: boolean diff --git a/studio/package.json b/studio/package.json index c2299cd3fef..8f44780b533 100644 --- a/studio/package.json +++ b/studio/package.json @@ -108,7 +108,7 @@ "@storybook/addon-links": "^6.4.19", "@storybook/react": "^6.4.19", "@storybook/testing-library": "^0.0.9", - "@supabase/postgres-meta": "^0.62.0", + "@supabase/postgres-meta": "^0.64.4", "@tailwindcss/typography": "^0.5.2", "@testing-library/dom": "^8.19.0", "@testing-library/react": "^12.1.5",