Skip to content

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

adds self-hosted support for materialized views

Alaister Young10cf35aeffd5
diff --git a/studio/pages/api/pg-meta/[ref]/materialized-views.ts b/studio/pages/api/pg-meta/[ref]/materialized-views.ts
new file mode 100644
index 00000000000..5bd5550dbfa
--- /dev/null
+++ b/studio/pages/api/pg-meta/[ref]/materialized-views.ts
@@ -0,0 +1,32 @@
+import { NextApiRequest, NextApiResponse } from 'next'
+
+import apiWrapper from 'lib/api/apiWrapper'
+import { get } from 'lib/common/fetch'
+import { constructHeaders } from 'lib/api/apiHelpers'
+import { PG_META_URL } from 'lib/constants'
+
+export default (req: NextApiRequest, res: NextApiResponse) =>
+ apiWrapper(req, res, handler, { withAuth: true })
+
+async function handler(req: NextApiRequest, res: NextApiResponse) {
+ const { method } = req
+
+ switch (method) {
+ case 'GET':
+ return handleGetAll(req, res)
+ default:
+ res.setHeader('Allow', ['GET'])
+ res.status(405).json({ error: { message: `Method ${method} Not Allowed` } })
+ }
+}
+
+const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
+ const headers = constructHeaders(req.headers)
+ let response = await get(`${PG_META_URL}/materialized-views`, {
+ headers,
+ })
+ if (response.error) {
+ return res.status(400).json({ error: response.error })
+ }
+ return res.status(200).json(response)
+}