forked from supabase/supabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTables.utils.ts
84 lines (78 loc) · 2.07 KB
/
Tables.utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { PostgresMaterializedView, PostgresTable, PostgresView } from '@supabase/postgres-meta'
import { PostgresForeignTable } from '@supabase/postgres-meta/dist/lib/types'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
type Entity = {
type: ENTITY_TYPE
id: number
name: string
comment: string | null
rows: number | undefined
size: string | undefined
columns: unknown[]
schema: string
}
// [Joshen] We just need name, description, rows, size, and the number of columns
// Just missing partitioned tables as missing pg-meta support
export const formatAllEntities = ({
tables = [],
views = [],
materializedViews = [],
foreignTables = [],
}: {
tables?: PostgresTable[]
views?: PostgresView[]
materializedViews?: PostgresMaterializedView[]
foreignTables?: PostgresForeignTable[]
}): Entity[] => {
const formattedTables: Entity[] = tables.map((x) => {
return {
...x,
type: ENTITY_TYPE.TABLE,
rows: x.live_rows_estimate,
columns: x.columns ?? [],
schema: x.schema,
}
})
const formattedViews: Entity[] = views.map((x) => {
return {
type: ENTITY_TYPE.VIEW,
id: x.id,
name: x.name,
comment: x.comment,
rows: undefined,
size: undefined,
columns: x.columns ?? [],
schema: x.schema,
}
})
const formattedMaterializedViews: Entity[] = materializedViews.map((x) => {
return {
type: ENTITY_TYPE.MATERIALIZED_VIEW,
id: x.id,
name: x.name,
comment: x.comment,
rows: undefined,
size: undefined,
columns: x.columns ?? [],
schema: x.schema,
}
})
const formattedForeignTables: Entity[] = foreignTables.map((x) => {
return {
type: ENTITY_TYPE.FOREIGN_TABLE,
id: x.id,
name: x.name,
comment: x.comment,
rows: undefined,
size: undefined,
columns: x.columns ?? [],
schema: x.schema,
}
})
return [
...formattedTables,
...formattedViews,
...formattedMaterializedViews,
...formattedForeignTables,
].sort((a, b) => a.name.localeCompare(b.name))
}