Skip to content

Instantly share code, notes, and snippets.

Role API/Tool
supabase_admin Used by Supabase to configure projects and for monitoring
authenticator PostgREST (Database API)
supabase_auth_admin Auth
supabase_storage_admin Storage
supabase_realtime_admin Realtime
supabase_replication_admin Synchronizes Read Replicas
postgres Supabase Dashboard and External Tools (e.g., Prisma, SQLAlchemy, PSQL...)
Custom roles defined by user External Tools (e.g., Prisma, SQLAlchemy, PSQL...)
select
cast(postgres_logs.timestamp as datetime) as timestamp,
parsed.error_severity,
parsed.user_name,
parsed.query,
parsed.sql_state_code,
event_message
from postgres_logs
cross join unnest(metadata) as metadata
cross join unnest(metadata.parsed) as parsed
select
cast(timestamp as datetime) as timestamp,
event_message,
status_code
from edge_logs
cross join unnest(metadata) as metadata
cross join unnest(metadata.request) as request
cross join unnest(metadata.response) as response
where
-- only look for requests through the database API
@TheOtherBrian1
TheOtherBrian1 / logging_supabase2.sql
Created January 21, 2024 18:36
How to log in Supabase
CREATE OR REPLACE FUNCTION example (num INT DEFAULT 10) RETURNS TEXT AS $$
DECLARE
var1 INT := 20;
var2 TEXT;
BEGIN
-- Logging start of function
RAISE LOG 'logging start of call to function example: (%)', (SELECT NOW());
-- Logging a variable from a SELECT query
SELECT col_1 FROM some_table INTO var1;
@TheOtherBrian1
TheOtherBrian1 / clerk.sql
Last active January 4, 2024 11:55
Create Clerk Pseudo FDW
-- ADD YOUR PRIVATE KEY
select vault.create_secret('<PRIVATE KEY>', 'clerk_private_key');
-- after executing the below code, you can query your user data from Clerk with the following query:
-- SELECT * FROM clerk_users;
-- Requires HTTP extension to function
create extension if not exists http with schema extensions;
CREATE OR REPLACE FUNCTION clerk_get_data()
-- Issue relates back to this GitHub Ticket for PG_NET:
-- https://github.com/supabase/pg_net/issues/86
-- Summary:
-- When PG_NET is called excessively, calls are not made to endpoints.
-- The net._http_response table will record responses as "timed_out"
-- I recommend creating a new project in Supabase to test the issue.
@TheOtherBrian1
TheOtherBrian1 / foreign_data_wrapper.c
Created August 24, 2023 00:16
Foreign Data Wrapper for PostgreSQL example
/*
CONTEXT:
This is an annotated version of Dolthub's tutorial on
Foreign Data Wrappers.
SOURCE: https://www.dolthub.com/blog/2022-01-26-creating-a-postgres-foreign-data-wrapper/
This code matches this schema:
CREATE EXTENSION tutorial_fdw;
CREATE SERVER tutorial_server FOREIGN DATA WRAPPER tutorial_fdw;
CREATE FOREIGN TABLE sequential_ints ( val int ) SERVER tutorial_server OPTIONS ( start '0', end '64' )
@TheOtherBrian1
TheOtherBrian1 / logging_supabase.sql
Last active December 31, 2023 17:11
How to log in supabase
CREATE OR REPLACE FUNCTION example (num INT DEFAULT 10) RETURNS TEXT AS $$
DECLARE
var1 INT := 20;
var2 TEXT;
BEGIN
-- Logging a variable from a SELECT query
SELECT col_1 FROM some_table INTO var1;
RAISE LOG 'logging a variable (%)', var1;
-- It is also possible to avoid using variables, by returning the values of your query to the log
RAISE LOG 'logging a query with a single return value(%)', (SELECT some_message_value FROM some_table LIMIT 1);
<!--Header-->
<h1> Change Widgets Color </h1>
<!-- Short app explanation -->
<p>
Will change the color of all objects with the key word in their title
</p>
<!--Asks user for a hex color value-->
<label for = 'hex-input'>
//Tells Figma to display your custom UI
figma.showUI(__html__);
//Resizes your plugin UI in pixels
figma.ui.resize(400, 400)
/*
This is our custom function
When a user submits an input from our plugin UI,
this will take care of it