mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 09:50:33 -04:00
19a6fc90ac
## Problem When using LLMs, it's useful to describe your tables in markdown format. ## Solution - Add an _Copy as SQL_ and _Copy as Markdown_ in the schema visualiser table menu <img width="320" height="235" alt="image" src="https://github.com/user-attachments/assets/b465d6aa-a011-4308-86de-78725328630b" /> - Refactor the _Copy as SQL_ and _Download current view_ buttons in a single button/dropdown combo and add _Copy as markdown_: <img width="333" height="143" alt="image" src="https://github.com/user-attachments/assets/a823988b-abff-4840-b5a5-53a5830065b4" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * "Copy as Markdown" for schemas and individual tables. * "Copy as SQL" for individual tables. * Per-column descriptions included in schema/table exports. * **Style** * Export actions consolidated into a compact, grouped dropdown with adjacent copy action for streamlined header controls. * **Tests** * Unit tests for markdown export helpers. * E2E tests updated to use the new export UI and adjusted dialog timing. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
177 lines
4.2 KiB
TypeScript
177 lines
4.2 KiB
TypeScript
import { describe, expect, test } from 'vitest'
|
|
|
|
import { getSchemaAsMarkdown, getTableDefinitionAsMarkdown } from './Schemas.utils'
|
|
|
|
describe('Schemas.utils', () => {
|
|
test('getSchemaAsMarkdown returns properly formatted markdown', () => {
|
|
const schema = 'public'
|
|
const tables = [
|
|
{
|
|
ref: 'default',
|
|
id: 20999,
|
|
name: 'test',
|
|
description: 'An excellent description',
|
|
schema: 'public',
|
|
isForeign: false,
|
|
columns: [
|
|
{
|
|
id: '20999.1',
|
|
isPrimary: true,
|
|
name: 'id',
|
|
format: 'int8',
|
|
isNullable: false,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: true,
|
|
description: '',
|
|
},
|
|
{
|
|
id: '20999.2',
|
|
isPrimary: false,
|
|
name: 'created_at',
|
|
format: 'timestamptz',
|
|
isNullable: false,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: false,
|
|
description: '',
|
|
},
|
|
{
|
|
id: '20999.3',
|
|
isPrimary: false,
|
|
name: 'user_id',
|
|
format: 'uuid',
|
|
isNullable: true,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: false,
|
|
description: '',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
ref: 'default',
|
|
id: 21049,
|
|
name: 'test2',
|
|
description: '',
|
|
schema: 'public',
|
|
isForeign: false,
|
|
columns: [
|
|
{
|
|
id: '21049.1',
|
|
isPrimary: true,
|
|
name: 'id',
|
|
format: 'int8',
|
|
isNullable: false,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: true,
|
|
description: '',
|
|
},
|
|
{
|
|
id: '21049.2',
|
|
isPrimary: false,
|
|
name: 'created_at',
|
|
format: 'timestamptz',
|
|
isNullable: false,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: false,
|
|
description: '',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: 21009,
|
|
ref: 'default',
|
|
schema: 'auth',
|
|
name: 'auth.users.id',
|
|
description: '',
|
|
isForeign: true,
|
|
columns: [],
|
|
},
|
|
]
|
|
const result = getSchemaAsMarkdown(schema, tables)
|
|
expect(result).toBe(`## Table \`test\`
|
|
|
|
An excellent description
|
|
|
|
### Columns
|
|
|
|
| Name | Type | Constraints |
|
|
|------|------|-------------|
|
|
| \`id\` | \`int8\` | Primary Identity |
|
|
| \`created_at\` | \`timestamptz\` | |
|
|
| \`user_id\` | \`uuid\` | Nullable |
|
|
|
|
## Table \`test2\`
|
|
|
|
### Columns
|
|
|
|
| Name | Type | Constraints |
|
|
|------|------|-------------|
|
|
| \`id\` | \`int8\` | Primary Identity |
|
|
| \`created_at\` | \`timestamptz\` | |
|
|
|
|
`)
|
|
})
|
|
test('getTableDefinitionAsMarkdown returns properly formatted markdown', () => {
|
|
const table = {
|
|
ref: 'default',
|
|
id: 20999,
|
|
name: 'test',
|
|
description: 'An excellent description',
|
|
schema: 'public',
|
|
isForeign: false,
|
|
columns: [
|
|
{
|
|
id: '20999.1',
|
|
isPrimary: true,
|
|
name: 'id',
|
|
format: 'int8',
|
|
isNullable: false,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: true,
|
|
description: '',
|
|
},
|
|
{
|
|
id: '20999.2',
|
|
isPrimary: false,
|
|
name: 'created_at',
|
|
format: 'timestamptz',
|
|
isNullable: false,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: false,
|
|
description: '',
|
|
},
|
|
{
|
|
id: '20999.3',
|
|
isPrimary: false,
|
|
name: 'user_id',
|
|
format: 'uuid',
|
|
isNullable: true,
|
|
isUnique: false,
|
|
isUpdateable: true,
|
|
isIdentity: false,
|
|
description: '',
|
|
},
|
|
],
|
|
}
|
|
const result = getTableDefinitionAsMarkdown(table)
|
|
expect(result).toBe(`## Table \`test\`
|
|
|
|
An excellent description
|
|
|
|
### Columns
|
|
|
|
| Name | Type | Constraints |
|
|
|------|------|-------------|
|
|
| \`id\` | \`int8\` | Primary Identity |
|
|
| \`created_at\` | \`timestamptz\` | |
|
|
| \`user_id\` | \`uuid\` | Nullable |
|
|
`)
|
|
})
|
|
})
|