Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: Remove unused stores (#19637)

Ivan Vasilova72f60ff6190
diff --git a/apps/database-new/app/layout.tsx b/apps/database-new/app/layout.tsx
index 2b3f8c5b0f0..2935c8b68ea 100644
--- a/apps/database-new/app/layout.tsx
+++ b/apps/database-new/app/layout.tsx
@@ -1,10 +1,10 @@
import '@ui/layout/ai-icon-animation/ai-icon-animation-style.module.css'
import './globals.css'
+import Footer from '@/components/Footer'
import Header from '@/components/Header/Header'
import { ThemeProvider } from '@/components/providers'
import type { Metadata } from 'next'
-import Footer from '@/components/Footer'
import { LoadingLine } from './LoadingLine'
const defaultUrl = process.env.VERCEL_URL
@@ -17,7 +17,7 @@ export const metadata: Metadata = {
description: 'Generate schemas from your ideas',
}
-// supressHydrationWarning:
+// suppressHydrationWarning:
// https://github.com/pacocoursey/next-themes#with-app
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
diff --git a/apps/studio/stores/RootStore.ts b/apps/studio/stores/RootStore.ts
index c9cceda7b5f..35bf3b1ecec 100644
--- a/apps/studio/stores/RootStore.ts
+++ b/apps/studio/stores/RootStore.ts
@@ -1,9 +1,7 @@
import { configure } from 'mobx'
import { Project } from 'types'
import UiStore, { IUiStore } from './UiStore'
-import AppStore, { IAppStore } from './app/AppStore'
import MetaStore, { IMetaStore } from './pgmeta/MetaStore'
-import ProjectFunctionsStore, { IProjectFunctionsStore } from './project/ProjectFunctionsStore'
import VaultStore, { IVaultStore } from './project/VaultStore'
// Temporary disable mobx warnings
@@ -13,10 +11,8 @@ configure({
})
export interface IRootStore {
- app: IAppStore
ui: IUiStore
meta: IMetaStore
- functions: IProjectFunctionsStore
vault: IVaultStore
selectedProjectRef?: string
@@ -24,20 +20,16 @@ export interface IRootStore {
setProject: (project: Project) => void
}
export class RootStore implements IRootStore {
- app: IAppStore
ui: IUiStore
meta: IMetaStore
- functions: IProjectFunctionsStore
vault: IVaultStore
selectedProjectRef: string | undefined
constructor() {
- this.app = new AppStore(this)
this.ui = new UiStore(this)
this.meta = new MetaStore(this, { projectRef: '', connectionString: '' })
- this.functions = new ProjectFunctionsStore(this, { projectRef: '' })
this.vault = new VaultStore(this)
}
@@ -54,7 +46,6 @@ export class RootStore implements IRootStore {
this.ui.setProjectRef(undefined)
this.meta.setProjectDetails(project)
- this.functions.setProjectRef(project.ref)
// ui set must come last
this.ui.setProjectRef(project.ref)
diff --git a/apps/studio/stores/app/AppStore.ts b/apps/studio/stores/app/AppStore.ts
deleted file mode 100644
index 4c0a84b878b..00000000000
--- a/apps/studio/stores/app/AppStore.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { API_URL } from 'lib/constants'
-import { IRootStore } from '../RootStore'
-import DatabaseStore, { IDatabaseStore } from './DatabaseStore'
-
-export interface IAppStore {
- database: IDatabaseStore
-}
-export default class AppStore implements IAppStore {
- rootStore: IRootStore
- database: DatabaseStore
-
- baseUrl: string
-
- constructor(rootStore: IRootStore) {
- this.rootStore = rootStore
- this.baseUrl = API_URL || '/api'
-
- const headers: any = {}
- this.database = new DatabaseStore(rootStore, `${this.baseUrl}/database`, headers)
- }
-}
diff --git a/apps/studio/stores/app/DatabaseStore.ts b/apps/studio/stores/app/DatabaseStore.ts
deleted file mode 100644
index 2d47b3ad468..00000000000
--- a/apps/studio/stores/app/DatabaseStore.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { ResponseError } from 'types'
-import { API_URL } from 'lib/constants'
-import { get } from 'lib/common/fetch'
-import { IRootStore } from '../RootStore'
-import { constructHeaders } from 'lib/api/apiHelpers'
-import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'
-
-export interface IDatabaseStore extends IPostgresMetaInterface<any> {
- getPoolingConfiguration: (projectRef: string) => Promise<any | { error: ResponseError }>
-}
-
-export default class DatabaseStore extends PostgresMetaInterface<any> {
- constructor(
- rootStore: IRootStore,
- dataUrl: string,
- headers?: {
- [prop: string]: any
- },
- options?: { identifier: string }
- ) {
- super(rootStore, dataUrl, headers, options)
- }
-
- async getPoolingConfiguration(projectRef: string) {
- try {
- // Need to use project ref -> shouldn;t need to pass it in via argument
- const url = `${API_URL}/projects/${projectRef}/config/pgbouncer`
- const response = await get(url, { headers: this.headers })
- if (response.error) throw response.error
- return response
- } catch (error: any) {
- return { error }
- }
- }
-}
diff --git a/apps/studio/stores/pgmeta/ColumnStore.ts b/apps/studio/stores/pgmeta/ColumnStore.ts
deleted file mode 100644
index 572f3e01b9c..00000000000
--- a/apps/studio/stores/pgmeta/ColumnStore.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import PostgresMetaInterface from '../common/PostgresMetaInterface'
-import type { PostgresColumn } from '@supabase/postgres-meta'
-import { IRootStore } from '../RootStore'
-
-export default class ColumnStore extends PostgresMetaInterface<PostgresColumn> {
- constructor(
- rootStore: IRootStore,
- dataUrl: string,
- headers?: {
- [prop: string]: any
- },
- options?: { identifier: string }
- ) {
- super(rootStore, dataUrl, headers, options)
- }
-}
diff --git a/apps/studio/stores/pgmeta/ForeignTableStore.ts b/apps/studio/stores/pgmeta/ForeignTableStore.ts
deleted file mode 100644
index 6ba1e3d5a7f..00000000000
--- a/apps/studio/stores/pgmeta/ForeignTableStore.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import type { PostgresColumn, PostgresTable } from '@supabase/postgres-meta'
-import { get } from 'lib/common/fetch'
-import { ResponseError } from 'types'
-import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'
-import { IRootStore } from '../RootStore'
-
-export interface IForeignTableStore extends IPostgresMetaInterface<Partial<PostgresTable>> {
- loadById: (id: number | string) => Promise<Partial<PostgresTable> | { error: ResponseError }>
-}
-
-export default class ForeignTableStore extends PostgresMetaInterface<Partial<PostgresTable>> {
- constructor(
- rootStore: IRootStore,
- dataUrl: string,
- headers?: {
- [prop: string]: any
- },
- options?: { identifier: string }
- ) {
- super(rootStore, dataUrl, headers, options)
- }
-
- // Customize ForeignTableStore fetchData method to improve request performance
- async fetchData() {
- const headers = { 'Content-Type': 'application/json', ...this.headers }
- // load all foreign tables w/o columns info
- const _url = new URL(this.url)
- _url.searchParams.set('include_columns', 'false')
- const url = `${_url}`
- // load all columns
- const urlColumns = this.url.replace('/foreign-tables', '/columns')
- const [foreignTablesResponse, columnsResponse] = await Promise.all([
- get(url, { headers }),
- get(urlColumns, { headers }),
- ])
- if (foreignTablesResponse.error) throw foreignTablesResponse.error
- if (columnsResponse.error) throw columnsResponse.error
-
- // merge 2 response to create the final array
- const columnsByTableId = (columnsResponse as PostgresColumn[]).reduce((acc, curr) => {
- acc[curr.table_id] ??= []
- acc[curr.table_id].push(curr)
- return acc
- }, {} as Record<string, PostgresColumn[]>)
- const foreignTables: PostgresTable[] = []
- foreignTablesResponse.forEach((foreignTable: PostgresTable) => {
- const columns = columnsByTableId[foreignTable.id]
- foreignTables.push({ ...foreignTable, columns })
- })
-
- this.setDataArray(foreignTables)
- return foreignTables as any
- }
-
- // loadBySchema is not supported in this store
- async loadBySchema(schema: string) {
- return []
- }
-
- async loadById(id: number | string) {
- try {
- const url = this.url.includes('?') ? `${this.url}&id=${id}` : `${this.url}?id=${id}`
- const response = await get(url, { headers: this.headers })
- if (response.error) throw response.error
-
- const data = response as Partial<PostgresTable>
- // @ts-ignore
- this.data[id] = data
- return data
- } catch (error: any) {
- return { error }
- }
- }
-}
diff --git a/apps/studio/stores/pgmeta/FunctionsStore.ts b/apps/studio/stores/pgmeta/FunctionsStore.ts
deleted file mode 100644
index 2d6d7f18300..00000000000
--- a/apps/studio/stores/pgmeta/FunctionsStore.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import PostgresMetaInterface from '../common/PostgresMetaInterface'
-import { IRootStore } from '../RootStore'
-
-export default class FunctionsStore extends PostgresMetaInterface<any> {
- constructor(
- rootStore: IRootStore,
- dataUrl: string,
- headers?: {
- [prop: string]: any
- },
- options?: { identifier: string }
- ) {
- super(rootStore, dataUrl, headers, options)
- }
-
- /**
- * Get a list of all trigger functions data in the store as an array
- * @param filter A custom filter (eg: (x) => x.name === 'name')
- * @param options.allSchemas If true, will include "excluded" schemas
- */
- listTriggerFunctions(filter: any, options: any) {
- return this.listByReturnType('trigger', filter)
- }
-
- /**
- * Get a list of all functions data by return type in the store as an array
- * @param returnType Valid Postgres function return type (e.g. trigger, uuid, int4, etc.)
- * @param filter A custom filter (eg: (x) => x.name === 'name')
- * @param options.allSchemas If true, will include "excluded" schemas
- */
- listByReturnType(returnType: any, filter: any) {
- const typeFilter = (h: any) =>
- h.return_type === returnType && (typeof filter === 'function' ? filter(h) : true)
-
- return super.list(typeFilter)
- }
-}
diff --git a/apps/studio/stores/pgmeta/MaterializedViewStore.ts b/apps/studio/stores/pgmeta/MaterializedViewStore.ts
deleted file mode 100644
index b050e09b835..00000000000
--- a/apps/studio/stores/pgmeta/MaterializedViewStore.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import { PostgresColumn, PostgresMaterializedView } from '@supabase/postgres-meta'
-import { ResponseError } from 'types'
-import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'
-import { IRootStore } from '../RootStore'
-import { get } from 'lib/common/fetch'
-
-export interface IMaterializedViewStore extends IPostgresMetaInterface<PostgresMaterializedView> {
- loadById: (
- id: number | string
- ) => Promise<Partial<PostgresMaterializedView> | { error: ResponseError }>
-}
-
-export default class MaterializedViewStore extends PostgresMetaInterface<PostgresMaterializedView> {
- constructor(
- rootStore: IRootStore,
- dataUrl: string,
- headers?: {
- [prop: string]: any
- },
- options?: { identifier: string }
- ) {
- super(rootStore, dataUrl, headers, options)
- }
-
- // Customize MaterializedViewStore fetchData method to improve request performance
- async fetchData() {
- const headers = { 'Content-Type': 'application/json', ...this.headers }
- // load all materialized views w/o columns info
- const _url = new URL(this.url)
- _url.searchParams.set('include_columns', 'false')
- const url = `${_url}`
- // load all columns
- const urlColumns = this.url.replace('/materialized-views', '/columns')
- const [materializedViewsResponse, columnsResponse] = await Promise.all([
- get(url, { headers }),
- get(urlColumns, { headers }),
- ])
- if (materializedViewsResponse.error) throw materializedViewsResponse.error
- if (columnsResponse.error) throw columnsResponse.error
-
- // merge 2 response to create the final array
- const columnsByTableId = (columnsResponse as PostgresColumn[]).reduce((acc, curr) => {
- acc[curr.table_id] ??= []
- acc[curr.table_id].push(curr)
- return acc
- }, {} as Record<string, PostgresColumn[]>)
- const materializedViews: PostgresMaterializedView[] = []
- materializedViewsResponse.forEach((materializedView: PostgresMaterializedView) => {
- const columns = columnsByTableId[materializedView.id]
- materializedViews.push({ ...materializedView, columns })
- })
-
- this.setDataArray(materializedViews)
- return materializedViews as any
- }
-
- async loadById(id: number | string) {
- try {
- const url = `${this.url}?id=${id}`
- const response = await get(url, { headers: this.headers })
- if (response.error) throw response.error
-
- const data = response as Partial<PostgresMaterializedView>
- // @ts-ignore
- this.data[id] = data
- return data
- } catch (error: any) {
- return { error }
- }
- }
-}
diff --git a/apps/studio/stores/pgmeta/MetaStore.ts b/apps/studio/stores/pgmeta/MetaStore.ts
index 8cfe134c9fd..26ed19278b0 100644
--- a/apps/studio/stores/pgmeta/MetaStore.ts
+++ b/apps/studio/stores/pgmeta/MetaStore.ts
@@ -17,7 +17,6 @@ import { ResponseError } from 'types'
import { IPostgresMetaInterface } from '../common/PostgresMetaInterface'
import { IRootStore } from '../RootStore'
-import ColumnStore from './ColumnStore'
import OpenApiStore, { IOpenApiStore } from './OpenApiStore'
import TableStore, { ITableStore } from './TableStore'
@@ -38,10 +37,7 @@ import { getQueryClient } from 'data/query-client'
import { tableKeys } from 'data/tables/keys'
import { getTable } from 'data/tables/table-query'
import { getTables } from 'data/tables/tables-query'
-import ForeignTableStore, { IForeignTableStore } from './ForeignTableStore'
-import FunctionsStore from './FunctionsStore'
-import MaterializedViewStore, { IMaterializedViewStore } from './MaterializedViewStore'
-import PoliciesStore from './PoliciesStore'
+import PostgresMetaInterface from '../common/PostgresMetaInterface'
import PublicationStore from './PublicationStore'
import RolesStore, { IRolesStore } from './RolesStore'
import TriggersStore from './TriggersStore'
@@ -55,8 +51,6 @@ export interface IMetaStore {
tables: ITableStore
columns: IPostgresMetaInterface<PostgresColumn>
views: IViewStore
- materializedViews: IMaterializedViewStore
- foreignTables: IForeignTableStore
roles: IRolesStore
policies: IPostgresMetaInterface<any>
@@ -142,15 +136,13 @@ export default class MetaStore implements IMetaStore {
rootStore: IRootStore
openApi: OpenApiStore
tables: TableStore
- columns: ColumnStore
+ columns: PostgresMetaInterface<PostgresColumn>
views: ViewStore
- materializedViews: MaterializedViewStore
- foreignTables: ForeignTableStore
roles: RolesStore
- policies: PoliciesStore
+ policies: PostgresMetaInterface<any>
triggers: TriggersStore
- functions: FunctionsStore
+ functions: PostgresMetaInterface<any>
publications: PublicationStore
projectRef?: string
@@ -175,23 +167,25 @@ export default class MetaStore implements IMetaStore {
`${API_URL}/projects/${this.projectRef}/api/rest`
)
this.tables = new TableStore(this.rootStore, `${this.baseUrl}/tables`, this.headers)
- this.columns = new ColumnStore(this.rootStore, `${this.baseUrl}/columns`, this.headers)
- this.views = new ViewStore(this.rootStore, `${this.baseUrl}/views`, this.headers)
- this.materializedViews = new MaterializedViewStore(
+ this.columns = new PostgresMetaInterface(
this.rootStore,
- `${this.baseUrl}/materialized-views`,
+ `${this.baseUrl}/columns`,
this.headers
)
- this.foreignTables = new ForeignTableStore(
+ this.views = new ViewStore(this.rootStore, `${this.baseUrl}/views`, this.headers)
+
+ this.roles = new RolesStore(this.rootStore, `${this.baseUrl}/roles`, this.headers)
+ this.policies = new PostgresMetaInterface(
this.rootStore,
- `${this.baseUrl}/foreign-tables`,
+ `${this.baseUrl}/policies`,
this.headers
)
-
- this.roles = new RolesStore(this.rootStore, `${this.baseUrl}/roles`, this.headers)
- this.policies = new PoliciesStore(this.rootStore, `${this.baseUrl}/policies`, this.headers)
this.triggers = new TriggersStore(this.rootStore, `${this.baseUrl}/triggers`, this.headers)
- this.functions = new FunctionsStore(this.rootStore, `${this.baseUrl}/functions`, this.headers)
+ this.functions = new PostgresMetaInterface(
+ this.rootStore,
+ `${this.baseUrl}/functions`,
+ this.headers
+ )
this.publications = new PublicationStore(
this.rootStore,
`${this.baseUrl}/publications`,
@@ -974,12 +968,6 @@ export default class MetaStore implements IMetaStore {
this.views.setUrl(`${this.baseUrl}/views`)
this.views.setHeaders(this.headers)
- this.materializedViews.setUrl(`${this.baseUrl}/materialized-views`)
- this.materializedViews.setHeaders(this.headers)
-
- this.foreignTables.setUrl(`${this.baseUrl}/foreign-tables`)
- this.foreignTables.setHeaders(this.headers)
-
this.roles.setUrl(`${this.baseUrl}/roles`)
this.roles.setHeaders(this.headers)
diff --git a/apps/studio/stores/pgmeta/PoliciesStore.ts b/apps/studio/stores/pgmeta/PoliciesStore.ts
deleted file mode 100644
index 3cb81dc8c2f..00000000000
--- a/apps/studio/stores/pgmeta/PoliciesStore.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import PostgresMetaInterface from '../common/PostgresMetaInterface'
-import { IRootStore } from '../RootStore'
-
-export default class PoliciesStore extends PostgresMetaInterface<any> {
- constructor(
- rootStore: IRootStore,
- dataUrl: string,
- headers?: {
- [prop: string]: any
- },
- options?: { identifier: string }
- ) {
- super(rootStore, dataUrl, headers, options)
- }
-}
diff --git a/apps/studio/stores/project/ProjectFunctionsStore.ts b/apps/studio/stores/project/ProjectFunctionsStore.ts
deleted file mode 100644
index 9f1297596fd..00000000000
--- a/apps/studio/stores/project/ProjectFunctionsStore.ts
+++ /dev/null
@@ -1,203 +0,0 @@
-import { makeAutoObservable, toJS } from 'mobx'
-import { keyBy } from 'lodash'
-
-import { get, post, patch, delete_ } from 'lib/common/fetch'
-import { UserContent, UserContentMap } from 'types'
-import { IRootStore } from '../RootStore'
-import { API_ADMIN_URL } from 'lib/constants'
-
-export interface IProjectFunctionsStore {
- isLoading: boolean
- isInitialized: boolean
- isLoaded: boolean
- error: any
-
- baseUrl: string
- projectRef: string
-
- load: () => void
- list: (filter?: any) => any[]
- byId: (id?: any) => any
- reports: (filter?: any) => any[]
- sqlSnippets: (filter?: any) => any[]
- setProjectRef: (ref?: string) => void
-}
-
-export default class ProjectFunctionsStore implements IProjectFunctionsStore {
- rootStore: IRootStore
-
- STATES = {
- INITIAL: 'initial',
- LOADING: 'loading',
- ERROR: 'error',
- LOADED: 'loaded',
- }
-
- baseUrl: string
- projectRef: string
- // @ts-ignore
- data: UserContentMap = []
-
- state = this.STATES.INITIAL
- error = null
-
- constructor(rootStore: IRootStore, options: { projectRef: string }) {
- const { projectRef } = options
- this.projectRef = projectRef
- this.rootStore = rootStore
- this.baseUrl = ``
- makeAutoObservable(this)
- }
-
- get isLoading() {
- return this.state === this.STATES.INITIAL || this.state === this.STATES.LOADING
- }
-
- get isInitialized() {
- return this.state !== this.STATES.INITIAL
- }
-
- get isLoaded() {
- return this.state === this.STATES.LOADED
- }
-
- async fetchData() {
- const headers = {
- 'Content-Type': 'application/json',
- }
- const response = await get(this.baseUrl, { headers })
- if (response.error) {
- throw response.error
- }
- this.data = keyBy(response, 'id')
- return response
- }
-
- async load() {
- let { LOADING, ERROR, LOADED } = this.STATES
- try {
- this.error = null
- this.state = LOADING
- await this.fetchData()
- this.state = LOADED
- return this.data
- } catch (e: any) {
- console.error('Failed to load project content', e.message)
- this.error = e
- this.state = ERROR
- }
- }
-
- async loadPersistentData() {}
-
- async loadRemotePersistentData(userId: any) {
- const sqlSnippets = this.sqlSnippets((x: any) => x.owner_id === userId)
- }
-
- list(filter?: any) {
- const arr = Object.values(this.data)
- if (!!filter) {
- return arr.filter(filter).sort((a, b) => a.name.localeCompare(b.name))
- } else {
- return arr.sort((a, b) => a.name.localeCompare(b.name))
- }
- }
-
- byId(id: any) {
- return toJS(this.data)[id]
- }
-
- reports(filter?: any) {
- let arr = Object.values(this.data)
- if (!!filter) {
- return arr
- .filter((x) => x.type == 'report')
- .filter(filter)
- .sort((a, b) => a.name.localeCompare(b.name))
- } else {
- return arr.filter((x) => x.type == 'report').sort((a, b) => a.name.localeCompare(b.name))
- }
- }
-
- sqlSnippets(filter?: any) {
- let arr = Object.values(this.data)
- if (!!filter) {
- const arr_filtered = arr
- .filter((x) => x.type == 'sql')
- .filter(filter)
- .sort((a, b) => a.name.localeCompare(b.name))
-
- return arr_filtered
- } else {
- const arr_filtered = arr
- .filter((x) => x.type == 'sql')
- .sort((a, b) => a.name.localeCompare(b.name))
-
- return arr_filtered
- }
- }
-
- async create(payload: any) {
- try {
- const headers = {
- 'Content-Type': 'application/json',
- }
- const created = await post(this.baseUrl, payload, { headers })
- if (created.error) throw created.error
- this.data[created['id']] = created
- return { data: created, error: null }
- } catch (error) {
- return { data: null, error }
- }
- }
-
- async update(id: any, updates: any, type: UserContent['type']) {
- try {
- const headers = {
- 'Content-Type': 'application/json',
- }
- let payload = {
- ...updates,
- type,
- id,
- }
- const url = `${this.baseUrl}?id=${id}`
- const updated = await patch(url, payload, { headers })
- if (updated.error) throw updated.error
- this.data[id] = updated
- return { data: updated, error: null }
- } catch (error) {
- return { data: null, error }
- }
- }
-
- async updateSql(id: any, updates: any) {
- return this.update(id, updates, 'sql')
- }
-
- async updateReport(id: any, updates: any) {
- return this.update(id, updates, 'report')
- }
-
- async del(id: any) {
- try {
- const headers = {
- 'Content-Type': 'application/json',
- }
- const url = `${this.baseUrl}?id=${id}`
- const deleted = await delete_(url, {}, { headers })
- if (deleted.error) throw deleted.error
- delete this.data[id]
- return { data: true, error: null }
- } catch (error) {
- return { data: false, error }
- }
- }
-
- setProjectRef(ref?: string) {
- if (ref) {
- this.projectRef = ref
- this.baseUrl = `${API_ADMIN_URL}/projects/${ref}/functions`
- }
- }
-}