In this guide, we outline the steps required to securely connect your Supabase database to your Velvet workspace. You may be able to skip some of these steps if you've previously connected your database to other services.
Depending on whether you're starting a new project from scratch, or connecting a database that's already configured for a third-party tool - this will take between 10 minutes and 2 hours.
- Create a read-only user
- Set up a static IP address (guide here)
- Identify and copy your connection string
- Configure which database tables you want to connect with Velvet
It's best practice to create a user with read-only permissions for products like Velvet. Create a user with read-only permissions in Supabase.
Navigate to the Supabase query editor.
Run the following SQL statements via psql. These statements create a
velvet readonly user with the password
a very good password and gives them the
PostgreSQL v14 includes a
pg_read_all_data role. Run
SELECT version() in the Supabase query editor to determine your version.
-- Create a new user with read-only access to the database
-- Recommend to run each step one by one, as some steps may
-- fail if the user does not have the necessary privileges.
-- Step 1: Create the user
CREATE USER velvet_readonly WITH LOGIN PASSWORD 'your_secure_password';
-- Step 2: Grant connect privilege to the database
-- (replace your_database_name with the actual name - on supabase it's postgres)
GRANT CONNECT ON DATABASE postgres TO velvet_readonly;
-- Step 3: Grant usage on schemas. This allows the user to see the schemas
GRANT USAGE ON SCHEMA public TO velvet_readonly;
GRANT USAGE ON SCHEMA auth TO velvet_readonly; -- optional
-- Step 4: Grant select on all tables and views in the schemas
GRANT SELECT ON ALL TABLES IN SCHEMA public TO velvet_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO velvet_readonly;
-- Step 5: Ensure future tables and views in these schemas are also accessible
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO velvet_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO velvet_readonly;
-- [OPTIONAL] Step 6: Bypass RLS policies
ALTER ROLE velvet_readonly BYPASSRLS;
Click Run and execute query.
Make sure you've enabled transaction mode (instead of session mode) from the Supabase database settings page. The only difference is the port number goes from 5432 to 6543.
For example, our read-only user connection string looks like postgres://velvet_readonly.[projectid]:[password]@aws-0-us-east-1.pooler.supabase.com:6543/postgres.
Further reading on optimizing your Supabase connection pooler here.
Set up a static IP using our static IP configuration guide.
Find your database connection string to paste it into your Velvet workspace config. If you already have a connection string, jump ahead to section #4.
Or, follow the guide below for building your connection string for the first time.
Read our general guide on URI construction here. The Supabase-specific overview is below.
- Log into Supabase and navigate to your project.
- Navigate to "Project Settings" > "Database Settings".
- Scroll down to Connection string and click on the URI.
- If required, change from
postgresto a read-only user (follow a guide here).
- Copy the Supabase URI (note: as of January 26 2024, you'll need to copy the URI from the Connection Pooling section).
Configure Supabase as a remote database connection and select which tables you want connected.
- Tap into a workspace in your Velvet dashboard
- Tap "Add a data source"
- Select type "Remote database"
- Name your database
- Paste in your database URI. Note: After providing your database credentials for the first time, we manage the connection using ClickHouse. If required, you can add ClickHouse's Static IPs to an allowlist - Read their API documentation here.
- Select and configure the table you want to connect as a source.
- Name your table and create the source.
- Repeat steps 6 and 7 to add each table you want included as a data source.
- You can now view, search, and filter data inside your database source.
Great job, you’ve connected your internal database as a data source. We’ll capture data from your connected tables so you can query them in your Velvet workspace.
Email [email protected] for support or feedback.
Updated about 3 hours ago