The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
renames Function Hooks to "Database Webhooks"
Copple8f19eec50aad
diff --git a/apps/www/_blog/2021-07-30-supabase-functions-updates.mdx b/apps/www/_blog/2021-07-30-supabase-functions-updates.mdxindex 827f4b2cd90..86735235130 100644--- a/apps/www/_blog/2021-07-30-supabase-functions-updates.mdx+++ b/apps/www/_blog/2021-07-30-supabase-functions-updates.mdx@@ -60,13 +60,15 @@ This is especially true for our Enterprise customers, but also Jamstack developeTo meet these goals, we're releasing Supabase Functions in stages:-- _Stage 1:_ Give developers the ability to trigger external HTTP functions - today, using Function Hooks.+- _Stage 1:_ Give developers the ability to trigger external HTTP functions - today, using Database Webhooks.- _Stage 2:_ Give developers the ability to trigger their own Serverless functions on AWS and GCP - Q4 2021.- _Stage 3:_ Release our own Serverless Functions (Supabase Functions) - Q4 for Early Preview customers.-## Function Hooks (Alpha)+## Database Webhooks (Alpha)++(Note: Database Webhooks were previosuly named "Function Hooks")Today we're releasing Functions Hooks in `ALPHA`. The `ALPHA` tag means that it is NOT stable, but it's available for testing and feedback. The API will change, so do not use it for anything critical. You have been warned.@@ -76,7 +78,7 @@ Postgres already has the concept of [Triggers](https://www.postgresql.org/docs/c### Hook Events-Function Hooks allow you to "listen" to any change in your tables to trigger an asynchronous Function. You can hook into a few different events:`INSERT`, `UPDATE`, and `DELETE`. All events are fired **after** a database row is changed. Keen eyes will be able to spot the similarity to Postgres triggers, and that's because Function Hooks are just a convenience wrapper around triggers.+Database Webhooks allow you to "listen" to any change in your tables to trigger an asynchronous Function. You can hook into a few different events:`INSERT`, `UPDATE`, and `DELETE`. All events are fired **after** a database row is changed. Keen eyes will be able to spot the similarity to Postgres triggers, and that's because Database Webhooks are just a convenience wrapper around triggers.@@ -88,7 +90,7 @@ Supabase will support several different targets.- AWS Lambda/Google Cloud Run: Provide Supabase with a restricted IAM role to trigger Serverless functions natively.- Supabase Functions: We'll develop an end-to-end experience.-+### Hook Payload@@ -120,14 +122,14 @@ type DeletePayload = {## Hooks technical design: `pg_net v0.1`-As with most of the Supabase platform, we leverage PostgreSQL's native functionality to implement Function Hooks.+As with most of the Supabase platform, we leverage PostgreSQL's native functionality to implement Database Webhooks (previosuly called "Function Hooks").To build hooks, we've released a new PostgreSQL Extension, [pg_net](https://github.com/supabase/pg_net/), an asynchronous networking extension with an emphasis on scalability/throughput. In its initial (unstable) release we expose:- asynchronous HTTP `GET` requests.- asynchronous HTTP `POST` requests with a JSON payload.-The extension is (currently) capable of >300 requests per second and is the networking layer underpinning Function Hooks. For a complete view of capabilities, check out [the docs](https://supabase.github.io/pg_net/api/).+The extension is (currently) capable of >300 requests per second and is the networking layer underpinning Database Webhooks. For a complete view of capabilities, check out [the docs](https://supabase.github.io/pg_net/api/).### **Usage**@@ -244,7 +246,7 @@ This is only the beginning! First we'll thoroughly test it and make a stable rel## Get started today-Function Hooks is enabled today on all [new projects](https://app.supabase.com). Find it under Database > Alpha Preview > Function Hooks.+Database Webhooks is enabled today on all [new projects](https://app.supabase.com). Find it under Database > Alpha Preview > Database Webhooks.diff --git a/apps/www/_blog/2021-09-10-supabase-beta-august-2021.mdx b/apps/www/_blog/2021-09-10-supabase-beta-august-2021.mdxindex 254427ee8f9..0ee022965e3 100644--- a/apps/www/_blog/2021-09-10-supabase-beta-august-2021.mdx+++ b/apps/www/_blog/2021-09-10-supabase-beta-august-2021.mdx@@ -145,7 +145,7 @@ If you want to keep up to date, make sure you [subscribe to our YouTube channel]- Allow a function with single unnamed parameter to be called with POST<br />[https://github.com/PostgREST/postgrest/issues/1735](https://github.com/PostgREST/postgrest/issues/1735)-### pg_net (Function Hooks)+### pg_net (Database Webhooks)- Better handling of URL errors<br />[https://github.com/supabase/pg_net/issues/39](https://github.com/supabase/pg_net/issues/39)diff --git a/apps/www/_blog/2021-10-28-supabase-series-a.mdx b/apps/www/_blog/2021-10-28-supabase-series-a.mdxindex 38a83d553cc..33f64259e46 100644--- a/apps/www/_blog/2021-10-28-supabase-series-a.mdx+++ b/apps/www/_blog/2021-10-28-supabase-series-a.mdx@@ -227,7 +227,7 @@ existing functionality.- **Row Level Security:** restrict user access to data and files using Postgres Policies.- **Realtime data streams:** subscribe to database changes using the logical replication stream.-- **Function Hooks:** trigger external systems using Postgres triggers and our [async request extension](https://github.com/supabase/pg_net/).+- **Database Webhooks (previosuly "Function Hooks"):** trigger external systems using Postgres triggers and our [async request extension](https://github.com/supabase/pg_net/).- **RESTful APIs:** query your database [tables](/docs/reference/javascript/select) and [functions](/docs/reference/javascript/rpc) over HTTP, using [PostgREST](https://postgrest.org).### Phase 3: Cloud-native PostgreSQLdiff --git a/apps/www/_blog/2022-02-22-supabase-beta-january-2022.mdx b/apps/www/_blog/2022-02-22-supabase-beta-january-2022.mdxindex aad8eeef5fd..e20790dd937 100644--- a/apps/www/_blog/2022-02-22-supabase-beta-january-2022.mdx+++ b/apps/www/_blog/2022-02-22-supabase-beta-january-2022.mdx@@ -102,9 +102,9 @@ Check out the new [Remix Auth example](https://github.com/supabase/supabase/treeOur React Native example has been correctly updated to be an Expo example.[Check it out here](https://github.com/supabase/supabase/tree/master/examples/todo-list/expo-todo-list).-## Video: API requests with Function Hooks+## Video: API requests with Database Webhooks-There's no stopping [Jon Meyers](https://jonmeyers.io/videos)! He’s back with an in-depth video on how to easily [automate API requests](https://www.youtube.com/watch?v=codAs9-NeHM&feature=emb_title) using our very own Function Hooks.+There's no stopping [Jon Meyers](https://jonmeyers.io/videos)! He’s back with an in-depth video on how to easily [automate API requests](https://www.youtube.com/watch?v=codAs9-NeHM&feature=emb_title) using our very own Database Webhooks.You'll learn how to listen to _any_ database change, then send those changes [in a payload](https://supabase.com/blog/2021/07/30/supabase-functions-updates#hook-payload) via HTTP request.diff --git a/apps/www/pages/partners/integrations/index.tsx b/apps/www/pages/partners/integrations/index.tsxindex 8e30744a075..c1ae01f974d 100644--- a/apps/www/pages/partners/integrations/index.tsx+++ b/apps/www/pages/partners/integrations/index.tsx@@ -24,7 +24,7 @@ export async function getStaticProps() {props: {partners,},- // TODO: consider using Next.js' On-demand Revalidation with Supabase function hooks instead+ // TODO: consider using Next.js' On-demand Revalidation with Supabase database webhooks insteadrevalidate: 18000, // In seconds - refresh every 5 hours}}diff --git a/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.ts b/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.tsindex 34b383178a2..7388a3542db 100644--- a/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.ts+++ b/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.ts@@ -88,7 +88,7 @@ export const generateDatabaseMenu = (project?: Project): ProductMenuGroup[] => {...(showHooksRoute? [{- name: 'Function Hooks',+ name: 'Database Webhooks',key: 'hooks',url: `/project/${ref}/database/hooks`,items: [],diff --git a/studio/pages/project/[ref]/database/hooks/index.tsx b/studio/pages/project/[ref]/database/hooks/index.tsxindex ad827c89d08..0d845254a20 100644--- a/studio/pages/project/[ref]/database/hooks/index.tsx+++ b/studio/pages/project/[ref]/database/hooks/index.tsx@@ -170,13 +170,13 @@ const TriggersList: FC<any> = observer({hooks.length == 0 ? (<div className="flex h-full w-full items-center justify-center"><ProductEmptyState- title="Function Hooks"- ctaButtonLabel="Create Function Hook"+ title="Database Webhooks"+ ctaButtonLabel="Create Webhook"onClickCta={() => createHook()}><AlphaPreview /><p className="text-scale-1100 text-sm">- Function Hooks can be used to trigger serverless functions or send requests to an+ Database Webhooks can be used to trigger serverless functions or send requests to anHTTP endpoint.</p></ProductEmptyState>diff --git a/web/docs/guides/database.mdx b/web/docs/guides/database.mdxindex 67f823b2a6d..a63a4110017 100644--- a/web/docs/guides/database.mdx+++ b/web/docs/guides/database.mdx@@ -4,11 +4,9 @@ title: Databasedescription: Use Supabase to manage your data.-----Every Supabase project comes with a full [Postgres](https://www.postgresql.org/) database, a free and open source+Every Supabase project comes with a full [Postgres](https://www.postgresql.org/) database, a free and open sourcedatabase which is considered one of the world's most stable and advanced databases.-## Postgres or PostgreSQL?PostgreSQL the database was derived from the POSTGRES Project, a package written at the University of California at Berkeley in 1986.@@ -17,47 +15,41 @@ This package included a query language called "PostQUEL".In 1994, Postgres95 was built on top of POSTGRES code, adding an SQL language interpreter as a replacement for PostQUEL.Eventually, Postgres95 was renamed to PostgreSQL to reflect the SQL query capability.-After this, many people referred to it as Postgres since it's less prone to confusion. Supabase is all about+After this, many people referred to it as Postgres since it's less prone to confusion. Supabase is all aboutsimplicity, so we also refer to it as Postgres.-## Features-### Table View+### Table ViewYou don't have to be a database expert to start using Supabase. Our table view makes Postgres as easy to use as a spreadsheet.-### Relationships-Dig into the relationships within your data.-+Dig into the relationships within your data.<video width="99%" loop="" muted="" playsInline="" controls="true">-<source src="/docs/videos/relational-drilldown-zoom.mp4" type="video/mp4" />+ <source src="/docs/videos/relational-drilldown-zoom.mp4" type="video/mp4" /></video>-### Clone tablesYou can duplicate your tables, just like you would inside a spreadsheet.<video width="99%" muted playsInline controls={true}>-<source src="/docs/videos/duplicate-tables.mp4" type="video/mp4" muted playsInline />+ <source src="/docs/videos/duplicate-tables.mp4" type="video/mp4" muted playsInline /></video>-### The SQL Editor-Supabase comes with a SQL Editor. You can also save your favorite queries to run later!+Supabase comes with a SQL Editor. You can also save your favorite queries to run later!<video width="99%" muted playsInline controls={true}>-<source src="/docs/videos/favorites.mp4" type="video/mp4" muted playsInline />+ <source src="/docs/videos/favorites.mp4" type="video/mp4" muted playsInline /></video>-### Additional features- Supabase extends Postgres with realtime functionality using our [Realtime Server](https://github.com/supabase/realtime).@@ -73,34 +65,34 @@ To expand the functionality of your Postgres database, you can use extensions.You can enable Postgres extensions with the click of a button within the Supabase dashboard.<video width="99%" muted playsInline controls={true}>-<source src="/docs/videos/toggle-extensions.mp4" type="video/mp4" muted playsInline />+ <source src="/docs/videos/toggle-extensions.mp4" type="video/mp4" muted playsInline /></video>[Learn more](/docs/guides/database/extensions) about all the extensions provided on Supabase.## Tips-### Realtime+### Realtime-Supabase provides a realtime engine on top of Postgres, so that you can listen to changes as they happen.+Supabase provides a realtime engine on top of Postgres, so that you can listen to changes as they happen.Our realtime engine uses the built-in replication functionality of Postgres.Realtime server broadcasts database changes to authorized users depending on your Row Level Security (RLS) policies.We recommend that you enable row level security and set row security policies on tables that you add to the publication.However, you may choose to disable RLS on a table and have changes broadcast to all connected clients.-You can manage the realtime system, simply by+You can manage the realtime system, simply by[updating](/docs/guides/database/replication) the `supabase_realtime` publication.For example to enable realtime only for individual tables:```sql-begin;+begin;-- remove the realtime publication- drop publication if exists supabase_realtime;+ drop publication if exists supabase_realtime;-- re-create the publication but don't enable it for any tables- create publication supabase_realtime;+ create publication supabase_realtime;commit;-- add a table to the publication@@ -110,7 +102,7 @@ alter publication supabase_realtime add table products;alter publication supabase_realtime add table posts;```-By default only "new" values are sent, but if you want to receive the old record (previous values) whenever you `update` or `delete` a record,+By default only "new" values are sent, but if you want to receive the old record (previous values) whenever you `update` or `delete` a record,you can update the replica identity of your tables, setting it to `full`:```sql@@ -119,72 +111,61 @@ alter table your_table replica identity full;### Migrating between projects-Migrating projects can be achieved using standard PostgreSQL tooling. This is particularly useful for older projects (e.g. to use a newer Postgres version).+Migrating projects can be achieved using standard PostgreSQL tooling. This is particularly useful for older projects (e.g. to use a newer Postgres version).#### Before you begin- Make sure [Postgres](https://www.postgresql.org/download/) is installed so you can run `psql` and `pg_dump`.- Create a new Supabase project.-- If you enabled Function Hooks on your old project, enable it on your new project.+- If you enabled Database Webhooks on your old project, enable it on your new project.- Store the old project's database URL as `$OLD_DB_URL` and the new project's as `$NEW_DB_URL`.#### Migrate the database-1. Run `ALTER ROLE postgres SUPERUSER` in the *old* project's SQL editor+1. Run `ALTER ROLE postgres SUPERUSER` in the _old_ project's SQL editor2. Run `pg_dump --clean --if-exists --quote-all-identifiers -h $OLD_DB_URL -U postgres > dump.sql` from your terminal-3. Run `ALTER ROLE postgres NOSUPERUSER` in the *old* project's SQL editor-4. Run `ALTER ROLE postgres SUPERUSER` in the *new* project's SQL editor+3. Run `ALTER ROLE postgres NOSUPERUSER` in the _old_ project's SQL editor+4. Run `ALTER ROLE postgres SUPERUSER` in the _new_ project's SQL editor5. Run `psql -h $NEW_DB_URL -U postgres -f dump.sql` from your terminal-6. Run `TRUNCATE storage.objects` in the *new* project's SQL editor-7. Run `ALTER ROLE postgres NOSUPERUSER` in the *new* project's SQL editor+6. Run `TRUNCATE storage.objects` in the _new_ project's SQL editor+7. Run `ALTER ROLE postgres NOSUPERUSER` in the _new_ project's SQL editor#### Migrate storage objectsThis script moves storage objects from one project to another. If you have more than 10k objects, we can move the objects for you. Just contact us at [[email protected]](mailto:[email protected]).```js-const { createClient } = require("@supabase/supabase-js");--const OLD_PROJECT_URL = "https://xxx.supabase.co";-const OLD_PROJECT_SERVICE_KEY = "old-project-service-key-xxx";--const NEW_PROJECT_URL = "https://yyy.supabase.co";-const NEW_PROJECT_SERVICE_KEY = "new-project-service-key-yyy";--(async () => {- const oldSupabaseRestClient = createClient(- OLD_PROJECT_URL,- OLD_PROJECT_SERVICE_KEY,- { schema: "storage" }- );- const oldSupabaseClient = createClient(- OLD_PROJECT_URL,- OLD_PROJECT_SERVICE_KEY- );- const newSupabaseClient = createClient(- NEW_PROJECT_URL,- NEW_PROJECT_SERVICE_KEY- );+const { createClient } = require('@supabase/supabase-js')++const OLD_PROJECT_URL = 'https://xxx.supabase.co'+const OLD_PROJECT_SERVICE_KEY = 'old-project-service-key-xxx'++const NEW_PROJECT_URL = 'https://yyy.supabase.co'+const NEW_PROJECT_SERVICE_KEY = 'new-project-service-key-yyy'++;(async () => {+ const oldSupabaseRestClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY, {+ schema: 'storage',+ })+ const oldSupabaseClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY)+ const newSupabaseClient = createClient(NEW_PROJECT_URL, NEW_PROJECT_SERVICE_KEY)// make sure you update max_rows in postgrest settings if you have a lot of objects// or paginate here- const { data: oldObjects, error } = await oldSupabaseRestClient- .from("objects")- .select();+ const { data: oldObjects, error } = await oldSupabaseRestClient.from('objects').select()if (error) {- console.log("error getting objects from old bucket");- throw error;+ console.log('error getting objects from old bucket')+ throw error}for (const objectData of oldObjects) {- console.log(`moving ${objectData.id}`);+ console.log(`moving ${objectData.id}`)try {- const { data, error: downloadObjectError } =- await oldSupabaseClient.storage- .from(objectData.bucket_id)- .download(objectData.name);+ const { data, error: downloadObjectError } = await oldSupabaseClient.storage+ .from(objectData.bucket_id)+ .download(objectData.name)if (downloadObjectError) {- throw downloadObjectError;+ throw downloadObjectError}const { _, error: uploadObjectError } = await newSupabaseClient.storage@@ -193,16 +174,16 @@ const NEW_PROJECT_SERVICE_KEY = "new-project-service-key-yyy";upsert: true,contentType: objectData.metadata.mimetype,cacheControl: objectData.metadata.cacheControl,- });+ })if (uploadObjectError) {- throw uploadObjectError;+ throw uploadObjectError}} catch (err) {- console.log("error moving ", objectData);- console.log(err);+ console.log('error moving ', objectData)+ console.log(err)}}-})();+})()```#### Caveats@@ -234,4 +215,3 @@ Read more in [Database Configuration](/docs/guides/database/managing-timezones).- Read more about [Postgres](/docs/postgres/server/about)- Sign in: [app.supabase.com](https://app.supabase.com)-