Files
supabase/apps/studio/components/interfaces/Database/Tables/Tables.utils.ts
Joshen Lim 54320ddb73 Chore/support showing all entities in database tables page (#27749)
* Support showing views in database tables page

* Support showing materialized views in database tables page

* Support showing foreign tables in database tables page

* Prevent deleting non table entities in database/tables, consistent with table editor

* Fix invalidation logic when deleting tables in database/tables
2024-07-03 14:40:45 +08:00

70 lines
1.7 KiB
TypeScript

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'
// [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[]
}) => {
const formattedTables = tables.map((x) => {
return {
...x,
type: ENTITY_TYPE.TABLE,
rows: x.live_rows_estimate,
columns: x.columns ?? [],
}
})
const formattedViews = views.map((x) => {
return {
type: ENTITY_TYPE.VIEW,
id: x.id,
name: x.name,
comment: x.comment,
rows: undefined,
size: undefined,
columns: x.columns ?? [],
}
})
const formattedMaterializedViews = 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 ?? [],
}
})
const formattedForeignTables = 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 ?? [],
}
})
return [
...formattedTables,
...formattedViews,
...formattedMaterializedViews,
...formattedForeignTables,
].sort((a, b) => a.name.localeCompare(b.name))
}