Files
supabase/apps/reference/docs/guides/integrations/sequin.mdx
2022-09-13 16:09:09 -07:00

85 lines
4.3 KiB
Plaintext

---
id: sequin
title: 'Sequin'
description: 'Sync platforms like Stripe and Salesforce with your Supabase database in real-time using Sequin.'
---
This guide explains how to quickly setup a sync between Sequin and a Supabase Postgres database.
[Sequin](https://sequin.io) allows you to sync platforms like Stripe and Salesforce with Supabase in real-time. You'll be able to read and write to your [Stripe](https://stripe.com/) customers or [Salesforce](https://www.salesforce.com/) accounts right from the Supabase client using SQL. Here's how to get setup.
## Step 1: Connect Sequin to Supabase
To connect Supabase to Sequin, you'll first need to retrieve the credentials for your Supabase Postgres database:
1. In the Supabase dashboard, go to the settings page and open up your **Database** settings. In the **Connection info** section, you'll find the credentials you need - like `host` and `user`:
![TBD](/img/guides/integrations/sequin/001_supabase_dash.png)
2. In the [Sequin console](https://app.sequin.io), go to your sync's configuration and open the **Destination** section. Select **Launch or Connect** and then click **Connect** to configure the connection to your Supabase Postgres:
![TBD](/img/guides/integrations/sequin/002_connect.png)
3. In the connection modal that appears, enter the `Host` and `Port` for your Supabase database and click **Continue**.
![TBD](/img/guides/integrations/sequin/003_step_1.png)
4. Now, enter the `Database name` and set the `schema` name for your sync. For instance, if your syncing Stripe, you'll likely want to name your synced schema something like `stripe`. Finally, enter the `user` and `password` for your Supabase database and then click **Continue**. Sequin will verify it can properly connect to your database with the correct permissions.
![TBD](/img/guides/integrations/sequin/004_step_2.png)
5. Sequin is now connected to your Supabase Postgres database and will ask you to confirm which database users should be able to access your synced schema. Select all of the users and click **Continue**:
![TBD](/img/guides/integrations/sequin/005_step_3.png)
6. That's it. Sequin will now create a new schema and permissions group in your Supabase database. Name the database connection in Sequin something like `Supabase` and your done!
In the Supabase dashboard, you can go to the **Table Editor** and you'll see a new schema full of your synced platform data.
![TBD](/img/guides/integrations/sequin/006_see_data.png)
## Step 2: Grant Permissions
To ensure the right users can access the synced schema Sequin manages, you'll need to run a couple permission grants.
1. In the Sequin console, click the **Connect** button next to your sync and copy down your `Schema` and unique `Read Group`.
![TBD](/img/guides/integrations/sequin/007_get_read.png)
2. Now, in the Supabase dashboard, go to the **SQL Editor** and run the following permission grants:
```sql
GRANT sequin_read_▒▒▒▒ TO postgres, anon, authenticated, service_role;
GRANT USAGE ON SCHEMA {{your_schema_name}} TO anon, authenticated, service_role;
GRANT ALL ON ALL TABLES IN SCHEMA {{your_schema_name}} TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres, supabase_admin IN SCHEMA {{your_schema_name}} GRANT ALL ON TABLES TO anon, authenticated, service_role;
```
These permission grants ensure that the various Supabase database users can access and read all the tables in your synced schema.
## Step 3: Configure the Supabase Client
Finally, you'll need to define a new [Supabase client](https://supabase.com/docs/reference/javascript/initializing#api-schemas) in your application to access your synced schema. In the file where you initialized your Supabase client, define a new client with a `schema` parameter:
```javascript
export const supabase_schema = createClient(
'https://xyzcompany.supabase.co',
'public-anon-key',
{
schema: {{your_schema_name}},
}
);
```
You'll use this client to query for data in your synced schema.
## Resources
- [Sequin](https://sequin.io*) official website.
- [Sequin Console](https://app.sequin.io*).
- [Sequin](https://docs.sequin.io/welcome) documentation.
- [Sequin + Supabase + Stripe Tutorial](https://github.com/sequin-io/build-a-saas-with-next-js-supabase-stripe-and-sequin)