Skip to main content

Supabase の初期設定

事前準備

  • Supabase の章を参照して、設定を済ませておくこと

ローカル環境での Supabase の起動

  • ターミナルを開く
  • 以下のコマンドを実行する
npx supabase init
npx supabase start

以下のようなメッセージが表示されれば成功です。

Status: Downloaded newer image for public.ecr.aws/supabase/studio:20240729-ce42139
Started supabase local development setup.

API URL: http://127.0.0.1:54321
GraphQL URL: http://127.0.0.1:54321/graphql/v1
S3 Storage URL: http://127.0.0.1:54321/storage/v1/s3
DB URL: postgresql://postgres:postgres@127.0.0.1:54322/postgres
Studio URL: http://127.0.0.1:54323
Inbucket URL: http://127.0.0.1:54324
JWT secret: supe..
anon key: eyJh..
service_role key: eyJhb..
S3 Access Key: 6252..
S3 Secret Key: 8501..
S3 Region: local

.env.local ファイルを以下のように編集します。

NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhb...
DATABASE_URL="postgresql://postgres:postgres@127.0.0.1:54322/postgres"
DATABASE_URL_DIRECT="postgresql://postgres:postgres@127.0.0.1:54322/postgres"

ローカル環境での Supabase の停止

  • ターミナルを開く
  • 以下のコマンドを実行する
npx supabase stop
tip

DB 等を初期化したい場合は、以下を実行してください。

npx supabase stop --no-backup

ローカル環境での DB の初期化

  • ターミナルを開く
  • 以下のコマンドを実行する
npx prisma migrate dev

以下のようなメッセージ(Your database is now in sync with your schema) が表示されれば OK)

 ✘ ✝  repos/bdash/bdash-sources   BDAS-22-supabase-register-user±  npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "127.0.0.1:54322"

Applying migration `20241002055805_init`

The following migration(s) have been applied:

migrations/
└─ 20241002055805_init/
└─ migration.sql

Your database is now in sync with your schema.

✔ Generated Prisma Client (v5.20.0) to ./node_modules/@prisma/client in 102ms

Supabase の Web UI(ローカル)

Studio URL: http://127.0.0.1:54323

こちらにアクセスすると、Supabase の Web UI を閲覧できます。