The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: add basic table template infrastructure (1 of 3) (#38933)
Sean Olivere1703d4429e7
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsxindex 780093e1517..10690bd227b 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx@@ -1,6 +1,7 @@import type { PostgresTable } from '@supabase/postgres-meta'+import dayjs from 'dayjs'import { isEmpty, isUndefined, noop } from 'lodash'-import { useEffect, useState } from 'react'+import { useEffect, useMemo, useState } from 'react'import { toast } from 'sonner'import { DocsButton } from 'components/ui/DocsButton'@@ -24,6 +25,7 @@ import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { useUrlState } from 'hooks/ui/useUrlState'import { useProtectedSchemas } from 'hooks/useProtectedSchemas'import { DOCS_URL } from 'lib/constants'+import { usePHFlag } from 'hooks/ui/useFlag'import { useTableEditorStateSnapshot } from 'state/table-editor'import { Badge, Checkbox, Input, SidePanel } from 'ui'import { Admonition } from 'ui-patterns'@@ -45,6 +47,12 @@ import {generateTableFieldFromPostgresTable,validateFields,} from './TableEditor.utils'+import { TableTemplateSelector } from './TableQuickstart/TableTemplateSelector'+import { QuickstartVariant } from './TableQuickstart/types'+import { LOCAL_STORAGE_KEYS } from 'common'+import { useLocalStorage } from 'hooks/misc/useLocalStorage'++const NEW_PROJECT_THRESHOLD_DAYS = 7export interface TableEditorProps {table?: PostgresTable@@ -90,6 +98,31 @@ export const TableEditor = ({const { realtimeAll: realtimeEnabled } = useIsFeatureEnabled(['realtime:all'])const { mutate: sendEvent } = useSendEventMutation()+ /**+ * Returns:+ * - `QuickstartVariant`: user variation (if bucketed)+ * - `false`: user not yet bucketed or targeted+ * - `undefined`: posthog still loading+ */+ const tableQuickstartVariant = usePHFlag<QuickstartVariant | false | undefined>('tableQuickstart')++ const [quickstartDismissed, setQuickstartDismissed] = useLocalStorage(+ LOCAL_STORAGE_KEYS.TABLE_QUICKSTART_DISMISSED,+ false+ )++ const isRecentProject = useMemo(() => {+ if (!project?.inserted_at) return false+ return dayjs().diff(dayjs(project.inserted_at), 'day') < NEW_PROJECT_THRESHOLD_DAYS+ }, [project?.inserted_at])++ const shouldShowTemplateQuickstart =+ isNewRecord &&+ !isDuplicating &&+ tableQuickstartVariant === QuickstartVariant.TEMPLATES &&+ !quickstartDismissed &&+ isRecentProject+const { docsRowLevelSecurityGuidePath } = useCustomContent(['docs:row_level_security_guide_path'])const [params, setParams] = useUrlState()@@ -280,6 +313,20 @@ export const TableEditor = ({}><SidePanel.Content className="space-y-10 py-6">+ {shouldShowTemplateQuickstart && (+ <TableTemplateSelector+ variant={tableQuickstartVariant}+ onSelectTemplate={(template) => {+ const updates: Partial<TableField> = {}+ if (template.name) updates.name = template.name+ if (template.comment) updates.comment = template.comment+ if (template.columns) updates.columns = template.columns+ onUpdateField(updates)+ }}+ onDismiss={() => setQuickstartDismissed(true)}+ disabled={false}+ />+ )}<Inputdata-testid="table-name-input"label="Name"diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/TableTemplateSelector.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/TableTemplateSelector.tsxnew file mode 100644index 00000000000..2efb9c871af--- /dev/null+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/TableTemplateSelector.tsx@@ -0,0 +1,121 @@+import { useState, useCallback, useEffect, useMemo } from 'react'+import { toast } from 'sonner'+import { Button, cn } from 'ui'+import { tableTemplates } from './templates'+import { QuickstartVariant } from './types'+import { convertTableSuggestionToTableField } from './utils'+import type { TableSuggestion } from './types'+import type { TableField } from '../TableEditor.types'++interface TableTemplateSelectorProps {+ variant: Exclude<QuickstartVariant, QuickstartVariant.CONTROL> // [Sean] this will be used in PR #38934+ onSelectTemplate: (tableField: Partial<TableField>) => void+ onDismiss?: () => void+ disabled?: boolean+}++const SUCCESS_MESSAGE_DURATION_MS = 3000++export const TableTemplateSelector = ({+ variant: _variant,+ onSelectTemplate,+ onDismiss,+ disabled,+}: TableTemplateSelectorProps) => {+ const [activeCategory, setActiveCategory] = useState<string | null>(null) // null => All+ const [selectedTemplate, setSelectedTemplate] = useState<TableSuggestion | null>(null)++ const handleSelectTemplate = useCallback(+ (template: TableSuggestion) => {+ const tableField = convertTableSuggestionToTableField(template)+ onSelectTemplate(tableField)+ setSelectedTemplate(template)+ toast.success(+ `${template.tableName} template applied. You can add or modify the fields below.`,+ {+ duration: SUCCESS_MESSAGE_DURATION_MS,+ }+ )+ },+ [onSelectTemplate]+ )++ const categories = useMemo(() => Object.keys(tableTemplates), [])++ useEffect(() => {+ if (activeCategory === null && categories.length > 0) {+ setActiveCategory(categories[0])+ }+ }, [categories, activeCategory])++ const displayed = useMemo(+ () => (activeCategory ? tableTemplates[activeCategory] || [] : []),+ [activeCategory]+ )++ return (+ <div className="rounded-lg border border-default bg-surface-75 p-4">+ <div className="flex items-center justify-between mb-3">+ <div>+ <h3 className="text-sm font-medium">Start faster with a table template</h3>+ <p className="text-xs text-foreground-lighter mt-1">+ Save time by starting from a ready-made table schema.+ </p>+ </div>+ {onDismiss && (+ <Button type="text" size="tiny" onClick={onDismiss}>+ Dismiss+ </Button>+ )}+ </div>++ <div className="flex flex-wrap gap-2 mb-3">+ {categories.map((category) => (+ <button+ key={category}+ onClick={() => setActiveCategory(category)}+ disabled={disabled}+ className={cn(+ 'px-2 py-1 rounded-md text-xs capitalize border',+ activeCategory === category+ ? 'border-foreground bg-surface-200'+ : 'border-default hover:border-foreground-muted hover:bg-surface-100',+ 'disabled:opacity-50 disabled:cursor-not-allowed'+ )}+ >+ {category}+ </button>+ ))}+ </div>++ <div className="grid gap-2">+ {displayed.map((t) => (+ <button+ key={`${activeCategory}:${t.tableName}`}+ onClick={() => handleSelectTemplate(t)}+ disabled={disabled}+ className={cn(+ 'text-left p-3 rounded-md border transition-all w-full',+ selectedTemplate?.tableName === t.tableName+ ? 'border-foreground bg-surface-200'+ : 'border-default hover:border-foreground-muted hover:bg-surface-100',+ 'disabled:opacity-50 disabled:cursor-not-allowed'+ )}+ >+ <div className="flex items-start justify-between">+ <div className="flex-1">+ <div className="text-sm font-medium font-mono">{t.tableName}</div>+ {t.rationale && (+ <div className="text-sm text-foreground-light mt-1">{t.rationale}</div>+ )}+ </div>+ <div className="flex items-center gap-1 text-sm text-foreground-muted ml-3">+ <span>{t.fields.length} columns</span>+ </div>+ </div>+ </button>+ ))}+ </div>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/constants.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/constants.tsnew file mode 100644index 00000000000..506a4e7d0cb--- /dev/null+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/constants.ts@@ -0,0 +1,12 @@+export const LIMITS = {+ MAX_PROMPT_LENGTH: 500,+ MAX_TABLES_TO_GENERATE: 3,+ MIN_TABLES_TO_GENERATE: 2,+} as const++export const AI_QUICK_IDEAS = [+ 'Recipe sharing app',+ 'Event ticketing system',+ 'Fitness tracker',+ 'Learning management platform',+] as constdiff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/templates.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/templates.tsnew file mode 100644index 00000000000..0566358236c--- /dev/null+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/templates.ts@@ -0,0 +1,416 @@+import { TableSource, TableSuggestion } from './types'++export const tableTemplates: Record<string, TableSuggestion[]> = {+ 'Social Network': [+ {+ tableName: 'profiles',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'user_id',+ type: 'uuid',+ nullable: false,+ unique: true,+ isForeign: true,+ references: 'auth.users(id)',+ },+ { name: 'username', type: 'text', nullable: true, unique: true },+ { name: 'display_name', type: 'text', nullable: true },+ { name: 'avatar_url', type: 'text', nullable: true },+ { name: 'bio', type: 'text', nullable: true },+ { name: 'location', type: 'text', nullable: true },+ { name: 'website', type: 'text', nullable: true },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'updated_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Stores user profile details such as name, avatar, and bio',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'posts',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'author_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'profiles(id)',+ },+ { name: 'content', type: 'text', nullable: false },+ { name: 'image_url', type: 'text', nullable: true },+ { name: 'likes_count', type: 'int4', nullable: false, default: '0' },+ { name: 'comments_count', type: 'int4', nullable: false, default: '0' },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'updated_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Stores user posts, images, and engagement counts',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'follows',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'follower_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'profiles(id)',+ },+ {+ name: 'following_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'profiles(id)',+ },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Tracks relationships between followers and followed users',+ source: TableSource.TEMPLATE,+ },+ ],+ 'E-commerce': [+ {+ tableName: 'products',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ { name: 'name', type: 'text', nullable: false },+ { name: 'slug', type: 'text', nullable: false, unique: true },+ { name: 'description', type: 'text', nullable: true },+ { name: 'price', type: 'numeric', nullable: false },+ { name: 'compare_at_price', type: 'numeric', nullable: true },+ { name: 'cost', type: 'numeric', nullable: true },+ { name: 'sku', type: 'text', nullable: true, unique: true },+ { name: 'barcode', type: 'text', nullable: true },+ { name: 'stock_quantity', type: 'int4', nullable: false, default: '0' },+ { name: 'weight', type: 'numeric', nullable: true },+ { name: 'published', type: 'bool', nullable: false, default: 'false' },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'updated_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Stores product details, pricing, and stock levels',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'orders',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ { name: 'order_number', type: 'text', nullable: false, unique: true },+ {+ name: 'customer_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'profiles(id)',+ },+ { name: 'status', type: 'text', nullable: false, default: "'pending'" },+ { name: 'subtotal', type: 'numeric', nullable: false },+ { name: 'tax', type: 'numeric', nullable: false, default: '0' },+ { name: 'shipping', type: 'numeric', nullable: false, default: '0' },+ { name: 'total', type: 'numeric', nullable: false },+ { name: 'notes', type: 'text', nullable: true },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'updated_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Manages customer orders, payment totals, and statuses',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'cart_items',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'user_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'profiles(id)',+ },+ {+ name: 'product_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'products(id)',+ },+ { name: 'quantity', type: 'int4', nullable: false, default: '1' },+ { name: 'added_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Tracks products added to customer shopping carts',+ source: TableSource.TEMPLATE,+ },+ ],+ Blog: [+ {+ tableName: 'articles',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ { name: 'title', type: 'text', nullable: false },+ { name: 'slug', type: 'text', nullable: false, unique: true },+ { name: 'content', type: 'text', nullable: true },+ { name: 'excerpt', type: 'text', nullable: true },+ { name: 'cover_image', type: 'text', nullable: true },+ {+ name: 'author_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'profiles(id)',+ },+ { name: 'status', type: 'text', nullable: false, default: "'draft'" },+ { name: 'published_at', type: 'timestamptz', nullable: true },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'updated_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Stores blog posts with author, status, and publish dates',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'categories',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ { name: 'name', type: 'text', nullable: false },+ { name: 'slug', type: 'text', nullable: false, unique: true },+ { name: 'description', type: 'text', nullable: true },+ { name: 'color', type: 'text', nullable: true },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Organizes articles into categories or tags for filtering',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'comments',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'article_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'articles(id)',+ },+ { name: 'author_name', type: 'text', nullable: false },+ { name: 'author_email', type: 'text', nullable: false },+ { name: 'content', type: 'text', nullable: false },+ { name: 'approved', type: 'bool', nullable: false, default: 'false' },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Stores reader comments and approval status for moderation',+ source: TableSource.TEMPLATE,+ },+ ],+ 'To-Do List': [+ {+ tableName: 'tasks',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ { name: 'title', type: 'text', nullable: false },+ { name: 'description', type: 'text', nullable: true },+ { name: 'completed', type: 'bool', nullable: false, default: 'false' },+ { name: 'priority', type: 'text', nullable: true, default: "'medium'" },+ { name: 'due_date', type: 'date', nullable: true },+ {+ name: 'user_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'auth.users(id)',+ },+ { name: 'list_id', type: 'uuid', nullable: true, isForeign: true, references: 'lists(id)' },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'updated_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Stores user tasks with priorities, due dates, and status',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'lists',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ { name: 'name', type: 'text', nullable: false },+ { name: 'description', type: 'text', nullable: true },+ { name: 'color', type: 'text', nullable: true },+ { name: 'icon', type: 'text', nullable: true },+ {+ name: 'user_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'auth.users(id)',+ },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'updated_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Groups tasks into named lists for better organization',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'subtasks',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'task_id',+ type: 'uuid',+ nullable: false,+ isForeign: true,+ references: 'tasks(id)',+ },+ { name: 'title', type: 'text', nullable: false },+ { name: 'completed', type: 'bool', nullable: false, default: 'false' },+ { name: 'position', type: 'int4', nullable: false, default: '0' },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Tracks smaller subtasks linked to a main task',+ source: TableSource.TEMPLATE,+ },+ ],+ Analytics: [+ {+ tableName: 'events',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'user_id',+ type: 'uuid',+ nullable: true,+ isForeign: true,+ references: 'profiles(id)',+ },+ { name: 'session_id', type: 'text', nullable: true },+ { name: 'event_type', type: 'text', nullable: false },+ { name: 'properties', type: 'jsonb', nullable: true },+ { name: 'user_agent', type: 'text', nullable: true },+ { name: 'ip_address', type: 'text', nullable: true },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Captures user events and properties for analytics tracking',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'page_views',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ {+ name: 'user_id',+ type: 'uuid',+ nullable: true,+ isForeign: true,+ references: 'profiles(id)',+ },+ { name: 'session_id', type: 'text', nullable: true },+ { name: 'path', type: 'text', nullable: false },+ { name: 'referrer', type: 'text', nullable: true },+ { name: 'duration', type: 'int4', nullable: true },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Tracks user page views, referrers, and session info',+ source: TableSource.TEMPLATE,+ },+ {+ tableName: 'metrics',+ fields: [+ {+ name: 'id',+ type: 'uuid',+ nullable: false,+ isPrimary: true,+ default: 'gen_random_uuid()',+ },+ { name: 'metric_name', type: 'text', nullable: false },+ { name: 'value', type: 'numeric', nullable: false },+ { name: 'tags', type: 'jsonb', nullable: true },+ { name: 'timestamp', type: 'timestamptz', nullable: false, default: 'now()' },+ { name: 'aggregation_period', type: 'text', nullable: true },+ { name: 'created_at', type: 'timestamptz', nullable: false, default: 'now()' },+ ],+ rationale: 'Stores aggregated metrics and KPIs with timestamps',+ source: TableSource.TEMPLATE,+ },+ ],+}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/types.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/types.tsnew file mode 100644index 00000000000..aeceaa3acdb--- /dev/null+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/types.ts@@ -0,0 +1,82 @@+export type PostgresType =+ | 'text'+ | 'varchar'+ | 'uuid'+ | 'int2'+ | 'int4'+ | 'int8'+ | 'float4'+ | 'float8'+ | 'numeric'+ | 'bool'+ | 'json'+ | 'jsonb'+ | 'date'+ | 'time'+ | 'timestamp'+ | 'timestamptz'+ | 'timetz'+ | 'bytea'++export type TableField = {+ name: string+ type: PostgresType+ nullable?: boolean+ unique?: boolean+ default?: string // Must be string for table editor compatibility+ description?: string+ isPrimary?: boolean+ isForeign?: boolean+ references?: string+}++export type TableRelationship = {+ from: string+ to: string+ type: 'one-to-one' | 'one-to-many' | 'many-to-many' | 'many-to-one'+}++export enum TableSource {+ AI = 'ai',+ TEMPLATE = 'template',+}++export enum QuickstartVariant {+ CONTROL = 'control',+ AI = 'ai',+ TEMPLATES = 'templates',+}++export enum ViewMode {+ INITIAL = 'initial',+ AI_INPUT = 'ai-input',+ AI_RESULTS = 'ai-results',+ CATEGORY_SELECTED = 'category-selected',+}++export type TableSuggestion = {+ tableName: string+ fields: TableField[]+ rationale?: string+ source: TableSource+ relationships?: TableRelationship[]+}++export type AIGeneratedSchema = {+ tables: Array<{+ name: string+ description: string+ columns: Array<{+ name: string+ type: string+ isPrimary?: boolean+ isForeign?: boolean+ references?: string+ isNullable?: boolean+ defaultValue?: string+ isUnique?: boolean+ }>+ relationships?: TableRelationship[]+ }>+ summary: string+}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/utils.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/utils.tsnew file mode 100644index 00000000000..727d5b7ac5c--- /dev/null+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/utils.ts@@ -0,0 +1,47 @@+import type { TableSuggestion, TableField } from './types'+import type { ColumnField } from '../../SidePanelEditor.types'+import type { TableField as EditorTableField } from '../TableEditor.types'++export const DEFAULT_SCHEMA = 'public' as const++export function isPrimaryKeyField(field: TableField): boolean {+ return field.isPrimary === true || field.name === 'id'+}++export function isIdentityField(field: TableField): boolean {+ return field.name === 'id' && field.type.toLowerCase().includes('int') && !field.default+}++export function convertTableSuggestionToTableField(+ table: TableSuggestion+): Partial<EditorTableField> {+ const columns: ColumnField[] = table.fields.map((field, index) => {+ const isPrimaryKey = isPrimaryKeyField(field)+ const isIdentity = isIdentityField(field)+ const defaultValue = field.default ? String(field.default) : null++ return {+ id: `column-${index}`,+ name: field.name,+ format: field.type,+ defaultValue,+ isNullable: field.nullable !== false,+ isUnique: field.unique ?? false,+ isIdentity,+ isPrimaryKey,+ comment: field.description || '',+ isNewColumn: true,+ table: table.tableName,+ schema: DEFAULT_SCHEMA,+ check: null,+ isArray: false,+ isEncrypted: false,+ }+ })++ return {+ name: table.tableName,+ comment: table.rationale || '',+ columns,+ }+}diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.tsindex 0ac015cb730..c6a13084208 100644--- a/packages/common/constants/local-storage.ts+++ b/packages/common/constants/local-storage.ts@@ -90,6 +90,9 @@ export const LOCAL_STORAGE_KEYS = {* WWW*/BLOG_VIEW: 'supabase-blog-view',++ // Used to track if user has dismissed table editor quickstart prompt+ TABLE_QUICKSTART_DISMISSED: 'table-quickstart-dismissed',} as constexport type LocalStorageKey = (typeof LOCAL_STORAGE_KEYS)[keyof typeof LOCAL_STORAGE_KEYS]@@ -111,6 +114,7 @@ const LOCAL_STORAGE_KEYS_ALLOWLIST = [LOCAL_STORAGE_KEYS.AI_ASSISTANT_MCP_OPT_IN,LOCAL_STORAGE_KEYS.UI_PREVIEW_BRANCHING_2_0,LOCAL_STORAGE_KEYS.LINTER_SHOW_FOOTER,+ LOCAL_STORAGE_KEYS.TABLE_QUICKSTART_DISMISSED,]export function clearLocalStorage() {