Back to Supabase

First, get your access token from https://supabase.com/dashboard/account/tokens

apps/docs/content/_partials/quickstart_db_setup.mdx

1.26.052.8 KB
Original Source

<StepHikeCompact.Details title="Create a Supabase project">

Go to database.new and create a new Supabase project.

Alternatively, you can create a project using the Management API:

</StepHikeCompact.Details>

<StepHikeCompact.Code>

bash
# First, get your access token from https://supabase.com/dashboard/account/tokens
export SUPABASE_ACCESS_TOKEN="your-access-token"

# List your organizations to get the organization ID
curl -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
  https://api.supabase.com/v1/organizations

# Create a new project (replace <org-id> with your organization ID)
curl -X POST https://api.supabase.com/v1/projects \
  -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "organization_id": "<org-id>",
    "name": "My Project",
    "region": "us-east-1",
    "db_pass": "<your-secure-password>"
  }'

</StepHikeCompact.Code>

<StepHikeCompact.Details>

When your project is up and running, go to the Table Editor section of the Dashboard, create a new table and insert some data. Then in the Integrations > Data API section of the Dashboard, expose the specific tables or functions you want to access. To automatically grant access for new tables and functions in public, enable Default privileges for new entities.

Alternatively, you can run the following snippet in your project's SQL Editor.

This creates an instruments table with some sample data, sets a secure baseline by setting only the privileges each Postgres role needs, and adds Row Level Security (RLS) for enhanced security for database data by default.

</StepHikeCompact.Details>

<StepHikeCompact.Code>

```sql SQL_EDITOR
-- Create the table
create table instruments (
  id bigint primary key generated always as identity,
  name text not null
);

-- Insert sample data into the table
insert into instruments (name)
values
  ('violin'),
  ('viola'),
  ('cello');

-- Grant the privileges the role needs, which is read access
grant select on public.instruments to anon;

-- Enable row level security for the table
alter table instruments enable row level security;
```

</StepHikeCompact.Code>

<StepHikeCompact.Details>

Create an RLS policy to make the data in your table publicly readable:

</StepHikeCompact.Details>

<StepHikeCompact.Code>

```sql SQL_EDITOR
-- Create a policy to allow the anon role to read from the instruments table
create policy "public can read instruments"
on public.instruments
for select to anon
using (true);
```

</StepHikeCompact.Code>