### Example Pre-Test Setup File for pgTAP and Test Helpers Source: https://supabase.com/docs/guides/local-development/testing/pgtap-extended This SQL file installs required extensions (pgtap, http, pg_tle, supabase-dbdev) and the basejump-supabase_test_helpers extension. It ends with a no-op test to verify the setup completed successfully. ```sql -- install tests utilities -- install pgtap extension for testing create extension if not exists pgtap with schema extensions; /* --------------------- ---- install dbdev ---- ---------------------- Requires: - pg_tle: https://github.com/aws/pg_tle - pgsql-http: https://github.com/pramsey/pgsql-http */ create extension if not exists http with schema extensions; create extension if not exists pg_tle; drop extension if exists "supabase-dbdev"; select pgtle.uninstall_extension_if_exists('supabase-dbdev'); select pgtle.install_extension( 'supabase-dbdev', resp.contents ->> 'version', 'PostgreSQL package manager', resp.contents ->> 'sql' ) from extensions.http( ( 'GET', 'https://api.database.dev/rest/v1/' || 'package_versions?select=sql,version' || '&package_name=eq.supabase-dbdev' || '&order=version.desc' || '&limit=1', array[ ('apiKey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s')::extensions.http_header ], null, null ) ) x, lateral ( select ((row_to_json(x) -> 'content') #>> '{}')::json -> 0 ) resp(contents); create extension "supabase-dbdev"; select dbdev.install('supabase-dbdev'); drop extension if exists "supabase-dbdev"; create extension "supabase-dbdev"; -- Install test helpers select dbdev.install('basejump-supabase_test_helpers'); create extension if not exists "basejump-supabase_test_helpers" version '0.0.6'; -- Verify setup with a no-op test begin; select plan(1); select ok(true, 'Pre-test hook completed successfully'); select * from finish(); rollback; ``` -------------------------------- ### Start Supabase stack after quick start Source: https://supabase.com/docs/guides/self-hosting/docker Run from the parent directory after the setup script finishes to start all services. ```shell cd supabase-project && \ sh run.sh start ``` -------------------------------- ### Verify local setup with supabase start and db reset Source: https://supabase.com/docs/guides/local-development/cli-workflows Run these commands to start the local Supabase stack and reset the database, applying all migrations and seed data. A successful run confirms the setup is reproducible. ```bash supabase start supabase db reset ``` -------------------------------- ### Create and populate instruments table Source: https://supabase.com/docs/guides/database/debugging-performance Example setup for the instruments table used to illustrate explain() output. Creates a table and inserts sample rows. ```sql create table instruments ( id int8 primary key, name text ); insert into instruments (id, name) values (1, 'violin'), (2, 'viola'), (3, 'cello'); ``` -------------------------------- ### Initialize and start local Supabase Postgres Source: https://supabase.com/docs/guides/ai/vecs-python-client Run these CLI commands in any folder to start a local Postgres instance. Docker must be running and the Supabase CLI must be installed. ```bash # Initialize your project supabase init # Start Postgres supabase start ``` -------------------------------- ### Set Up Ubuntu VM with Postgres Client and tmux Source: https://supabase.com/docs/guides/platform/migrating-to-supabase/postgres Install Postgres client tools and tmux on an Ubuntu VM, then start or attach to a tmux session for the migration. ```bash # Install Postgres client and tools sudo apt update sudo apt install software-properties-common sudo sh -c 'echo "deb http://apt.Postgres.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.Postgres.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt update sudo apt install Postgres-client-17 tmux htop iotop moreutils # Start or attach to tmux session tmux a -t migration || tmux new -s migration ``` -------------------------------- ### Create persons table Source: https://supabase.com/docs/guides/database/postgres/indexes Example table used throughout the guide. Run this in the SQL Editor or via psql. ```sql create table persons ( id bigint generated by default as identity primary key, age int, height int, weight int, name text, deceased boolean ); ``` -------------------------------- ### SQL setup for Blog table with timestamps Source: https://supabase.com/docs/guides/graphql/api Creates a Blog table with id, name, description, createdAt, and updatedAt columns. Used as a prerequisite for the node and collection examples. ```sql create table "Blog"( id serial primary key, name varchar(255) not null, description varchar(255), "createdAt" timestamp not null, "updatedAt" timestamp not null ); ``` -------------------------------- ### Start Supabase locally with Supabase CLI Source: https://supabase.com/docs/guides/ai/examples/building-chatgpt-plugins Run this command in the examples/providers folder to start the Supabase stack locally using Docker. It pulls necessary images and applies migrations, including pgvector setup. ```shell supabase start ``` -------------------------------- ### Create Blog table for nodeId example Source: https://supabase.com/docs/guides/graphql/api SQL setup for a simplified Blog table with id and name columns, used to illustrate the nodeId field. ```sql create table "Blog"( id serial primary key, name varchar(255) not null ); ``` -------------------------------- ### Initialize SupabaseClient in Supabase.swift Source: https://supabase.com/docs/guides/getting-started/quickstarts/ios-swiftui Create a Supabase.swift file and initialize the client with your project URL and publishable key from the Connect panel. The guide substitutes these values directly rather than reading them from a .env file, since mobile apps don't get runtime environment variables. ```swift import Supabase let supabase = SupabaseClient( supabaseURL: URL(string: "YOUR_SUPABASE_URL")!, supabaseKey: "YOUR_SUPABASE_PUBLISHABLE_KEY" ) ``` -------------------------------- ### Create a Pre-Test Setup File with supabase test new Source: https://supabase.com/docs/guides/local-development/testing/pgtap-extended Run this command to generate a setup file named 000-setup-tests-hooks.sql that runs first due to alphabetical ordering. It should contain shared extensions, utilities, and a basic always-green test. ```shell supabase test new 000-setup-tests-hooks ``` -------------------------------- ### Install and start Roboflow Inference server Source: https://supabase.com/docs/guides/ai/integrations/roboflow Installs the inference packages and starts the server on http://localhost:9001. Requires Docker to be installed. ```bash pip install inference inference-cli inference-sdk && inference server start ``` -------------------------------- ### Start the Next.js development server Source: https://supabase.com/docs/guides/auth/quickstarts/nextjs Run the dev server, then open http://localhost:3000 and navigate to /auth/sign-up to create a user. ```bash npm run dev ``` -------------------------------- ### Initialize a new Supabase project for Edge Functions Source: https://supabase.com/docs/guides/functions/quickstart Creates a new directory, navigates into it, and runs `supabase init` to set up a Supabase project. Use this when starting from scratch. ```shell mkdir my-edge-functions-project cd my-edge-functions-project supabase init ``` -------------------------------- ### Start Supabase services and serve the hello-world function locally Source: https://supabase.com/docs/guides/functions/quickstart Run after starting Docker to launch the local development server. On first use, `supabase start` downloads Docker images and starts all Supabase services, which can take a few minutes. The function is then available at http://localhost:54321/functions/v1/hello-world with hot reloading enabled. ```shell supabase start # Start all Supabase services supabase functions serve hello-world ``` -------------------------------- ### net.http_get Source: https://supabase.com/docs/guides/database/extensions/pg_net Creates an HTTP GET request and returns the request ID. The request is not started until the transaction is committed. ```APIDOC ## net.http_get ### Description Creates an HTTP GET request returning the request's ID. HTTP requests are not started until the transaction is committed. ### Method SQL function ### Endpoint `net.http_get(url text, params jsonb default '{}'::jsonb, headers jsonb default '{}'::jsonb, timeout_milliseconds int default 2000)` ### Parameters - **url** (text) - Required - The URL for the request. - **params** (jsonb) - Optional - Key/value pairs to be URL encoded and appended to the `url`. Default: `'{}'::jsonb`. - **headers** (jsonb) - Optional - Key/values to be included in request headers. Default: `'{}'::jsonb`. - **timeout_milliseconds** (int) - Optional - The maximum number of milliseconds the request may take before being canceled. Default: 2000. ### Returns - **request_id** (bigint) - The ID of the request. ### Example ```sql select net.http_get('https://news.ycombinator.com') as request_id; ``` ### Notes - This is a Postgres SECURITY DEFINER function. - The function is strict, volatile, parallel safe, and written in plpgsql. ``` -------------------------------- ### Copy .env.example to .env Source: https://supabase.com/docs/guides/getting-started/quickstarts/hono Run this command to create a .env file from the example, then update it with your Supabase project URL and publishable key. ```shell cp .env.example .env ``` -------------------------------- ### Schema setup for Realtime authorization examples Source: https://supabase.com/docs/guides/realtime/authorization?language=js&queryGroups=language Creates tables rooms, profiles, and rooms_users, grants permissions, enables RLS, and adds a policy for users to read their own room memberships. This schema is used in the following Broadcast examples. ```sql create table public.rooms ( id bigint generated by default as identity primary key, topic text not null unique ); GRANT SELECT ON public.rooms TO anon; alter table public.rooms enable row level security; create table public.profiles ( id uuid not null references auth.users on delete cascade, email text NOT NULL, primary key (id) ); GRANT SELECT ON public.profiles TO anon; GRANT SELECT, INSERT, UPDATE, DELETE ON public.profiles TO authenticated; alter table public.profiles enable row level security; create table public.rooms_users ( user_id uuid references auth.users (id), room_topic text references public.rooms (topic), created_at timestamptz default current_timestamp ); GRANT SELECT ON public.rooms_users TO authenticated; alter table public.rooms_users enable row level security; create policy "authenticated can read own room memberships" on public.rooms_users for select to authenticated using ((select auth.uid()) = user_id); ``` -------------------------------- ### Initialize Supabase in an existing project Source: https://supabase.com/docs/guides/functions/quickstart Navigates to an existing project directory and runs `supabase init` to configure it for Supabase. Use this if you already have a project but haven't initialized Supabase. ```shell cd your-existing-project supabase init # Initialize Supabase, if you haven't already ``` -------------------------------- ### Manual installation via Git clone Source: https://supabase.com/docs/guides/self-hosting/docker Clones the Supabase repository at a specific tag, copies the Docker configuration to a project directory, creates .env from example, records the version, and pulls images. Works on any OS with git installed. ```shell # Get the code git clone --depth 1 --branch self-hosted/v0.8.3 https://github.com/supabase/supabase # Make your new supabase project directory mkdir supabase-project # Tree should look like this # . # ├── supabase # └── supabase-project # Copy the configuration to your project cp -rf supabase/docker/. supabase-project # Switch to the project directory and create a .env from the example cd supabase-project && cp .env.example .env # Record the base version so update.sh can upgrade this install later printf 'ref=self-hosted/v0.8.3\n' > .supabase-version # Pull the latest images docker compose pull ``` -------------------------------- ### Initialize a new Prisma project with npm Source: https://supabase.com/docs/guides/database/prisma Run these commands to initialize a Node.js project, install Prisma and required dependencies, and set up TypeScript and Prisma. ```shell npm init -y npm install prisma tsx @types/pg --save-dev npm install @prisma/client @prisma/adapter-pg dotenv pg npx tsc --init npx prisma init ``` -------------------------------- ### http_get usage example Source: https://supabase.com/docs/guides/database/extensions/pg_net Calls net.http_get to create an HTTP GET request to the specified URL and returns the request ID. ```sql select net.http_get('https://news.ycombinator.com') as request_id; request_id ---------- 1 (1 row) ``` -------------------------------- ### Run supabase start to get local GraphQL URL and anon key Source: https://supabase.com/docs/guides/graphql The `supabase start` output lists the GraphQL URL for calling the GraphQL API directly, the Studio URL for the builtin GraphiQL IDE, and the anon key to use as API_KEY. ```shell > supabase start ... Started supabase local development setup. GraphQL URL: http://localhost:54321/graphql/v1 <-- GraphQL endpoint DB URL: ... Studio URL: http://localhost:54323 <-- Supabase Studio Inbucket URL: ... JWT secret: ... anon key: eyJhbGciOiJIUzI1... <-- API_KEY service_role key: ... ``` -------------------------------- ### Initialize Supabase Locally Source: https://supabase.com/docs/guides/ai/quickstarts/generate-text-embeddings Run these commands to initialize Supabase in your project root and start the local development stack. Requires the Supabase CLI installed. ```shell supabase init supabase start ``` -------------------------------- ### Initialize Node.js Project and Install Supabase Client Source: https://supabase.com/docs/guides/platform/migrating-within-supabase/backup-restore Create a new Node.js project and install the @supabase/supabase-js package using npm. This is the first step to set up the migration script. ```bash npm init -y npm install @supabase/supabase-js ``` -------------------------------- ### http_get function signature Source: https://supabase.com/docs/guides/database/extensions/pg_net Defines the net.http_get function, which creates an HTTP GET request and returns the request ID. The request is not started until the transaction is committed. ```sql net.http_get( -- url for the request url text, -- key/value pairs to be url encoded and appended to the `url` params jsonb default '{}'::jsonb, -- key/values to be included in request headers headers jsonb default '{}'::jsonb, -- the maximum number of milliseconds the request may take before being canceled timeout_milliseconds int default 2000 ) -- request_id reference returns bigint strict volatile parallel safe language plpgsql ``` -------------------------------- ### Create a new migration file for user management starter Source: https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs Run this command locally to create a new migration file named user_management_starter. Use this when working with local development to apply the schema changes. ```bash supabase migration new user_management_starter ``` -------------------------------- ### Create table with numeric and insert data Source: https://supabase.com/docs/guides/graphql/api SQL setup for the BigFloat scalar example: creates a GeneralLedger table with a numeric amount and inserts a row. ```sql create table "GeneralLedger"( id serial primary key, amount numeric(10,2) ); insert into "GeneralLedger"(amount) values (22.15); ``` -------------------------------- ### Create table with bigserial and insert data Source: https://supabase.com/docs/guides/graphql/api SQL setup for the BigInt scalar example: creates a Person table with a bigserial id and inserts a row. ```sql create table "Person"( id bigserial primary key, name text ); insert into "Person"(name) values ('J. Bazworth'); ``` -------------------------------- ### Initialize Refine app with refine-supabase preset Source: https://supabase.com/docs/guides/getting-started/tutorials/with-refine Run this command to create a new Refine app using the refine-supabase preset, which includes the Supabase client package and a headless UI. ```bash npm create refine-app@latest -- --preset refine-supabase ``` -------------------------------- ### Create a Reflex app with uv Source: https://supabase.com/docs/guides/getting-started/quickstarts/reflex Run these commands to create a new directory, initialize a uv project, add Reflex as a dependency, and scaffold a blank Reflex app using the blank template. ```shell mkdir my_app && cd my_app uv init uv add reflex uv run reflex init --template blank ``` -------------------------------- ### Sign up a new user with email and password using signUp() Source: https://supabase.com/docs/guides/auth/passwords Call signUp() with the user's email and password. Optionally specify a redirect URL via emailRedirectTo; it must be configured as a Redirect URL. If omitted, the user is redirected to the site URL (default localhost:3000). ```JavaScript async function signUpNewUser() { const { data, error } = await supabase.auth.signUp({ email: 'valid.email@supabase.io', password: 'example-password', options: { emailRedirectTo: 'https://example.com/welcome', }, }) } ``` -------------------------------- ### Run the Reflex development server with uv run reflex run Source: https://supabase.com/docs/guides/getting-started/quickstarts/reflex Starts the Reflex development server. After running it, open http://localhost:3000 in a browser to see the list of instruments. ```shell uv run reflex run ``` -------------------------------- ### Run Keycloak in Docker Source: https://supabase.com/docs/guides/auth/social-login/auth-keycloak Starts Keycloak in development mode on port 8080 with admin credentials admin/admin. Use this to run Keycloak locally as assumed by the guide. ```shell docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev ``` -------------------------------- ### Get Latest Events from Analytics Table Source: https://supabase.com/docs/guides/storage/analytics/query-with-postgres Retrieve the most recent events from the analytics.events table, ordered by event_timestamp descending. This example assumes the foreign table is named analytics.events. ```sql select event_id, event_name, event_timestamp from analytics.events order by event_timestamp desc limit 1000; ``` -------------------------------- ### Create BlogPost table and enable aggregate Source: https://supabase.com/docs/guides/graphql/configuration Example creating a table and enabling aggregate via comment. ```sql create table "BlogPost"( id serial primary key, title varchar(255) not null, rating int not null ); comment on table "BlogPost" is e'@graphql({"aggregate": {"enabled": true}})'; ``` -------------------------------- ### Create BlogPost table and enable totalCount Source: https://supabase.com/docs/guides/graphql/configuration Example creating a table and enabling totalCount via comment. ```sql create table "BlogPost"( id serial primary key, email varchar(255) not null ); comment on table "BlogPost" is e'@graphql({"totalCount": {"enabled": true}})'; ``` -------------------------------- ### Set up Supabase authentication with yarn redwood setup auth supabase Source: https://supabase.com/docs/guides/getting-started/tutorials/with-redwoodjs Run this command to install supabase-js and configure authentication. When prompted to overwrite existing auth.js, answer yes. ```shell yarn redwood setup auth supabase ``` -------------------------------- ### Create a minimal Expo app with create-expo-app Source: https://supabase.com/docs/guides/getting-started/quickstarts/expo-react-native Scaffolds a minimal Expo app named my-app using the blank TypeScript template. Run this command to start the Expo quickstart. ```shell npx create-expo-app my-app --template blank-typescript ``` -------------------------------- ### Initialize Flutter app with flutter create Source: https://supabase.com/docs/guides/getting-started/tutorials/with-flutter Run this command to create a new Flutter project named supabase_quickstart. ```shell flutter create supabase_quickstart ``` -------------------------------- ### Install @supabase/supabase-js and @supabase/ssr in the TanStack Start app Source: https://supabase.com/docs/guides/getting-started/quickstarts/tanstack Run from the project directory to add the Supabase client and the SSR cookie-session helper. @supabase/ssr manages cookie-based sessions for server-side rendering. ```shell cd my-app && npm install @supabase/supabase-js @supabase/ssr ``` -------------------------------- ### Initiate Project Claim Flow via OAuth Source: https://supabase.com/docs/guides/integrations/supabase-for-platforms Use this GET request to start the OAuth flow for transferring a project to a user's organization. Requires a personal access token. ```bash curl -L "https://api.supabase.com/v1/oauth/authorize/project-claim?project_ref={ref}&client_id={oauth_client_id}&response_type=code&redirect_uri={redirect_uri}" \ --request GET \ --header 'Authorization: Bearer {PERSONAL_ACCESS_TOKEN}' ```