← Back to list

supabase-setup
by forone-ai
電卓アプリ(Template Repositoryテスト用)
⭐ 0🍴 0📅 Jan 16, 2026
SKILL.md
name: supabase-setup description: | Supabaseプロジェクトの初期設定を行うスキル。 Webアプリ生成サブエージェントから呼び出される。 プロジェクト作成、マイグレーション、RLS設定を行う。 allowed-tools: Bash, Read, Write, Edit
Supabase設定スキル
目的
新規アプリ用のSupabaseプロジェクトを設定する。 セキュリティを考慮したデフォルト設定を適用する。
前提条件
- Supabase CLIがインストール済み
- Supabaseにログイン済み
- forone-ai組織のSupabaseにアクセス権限あり
実行手順
Step 1: プロジェクト作成
# 組織IDを取得
supabase orgs list
# プロジェクト作成(リージョンは東京)
supabase projects create {app-name} \
--org-id dgykcravofxrmeoyoaoo \
--db-password "$(openssl rand -base64 32)" \
--region ap-northeast-1
Step 2: ローカル初期化
# Supabase初期化
supabase init
# プロジェクトとリンク
supabase link --project-ref {project-ref}
Step 3: 基本テーブル作成
supabase/migrations/00001_initial.sql を作成:
-- ======================================
-- 基本設定
-- ======================================
-- UUIDを生成する拡張機能
create extension if not exists "uuid-ossp";
-- ======================================
-- プロファイルテーブル(Supabase Auth連携)
-- ======================================
create table public.profiles (
id uuid references auth.users on delete cascade primary key,
email text,
display_name text,
avatar_url text,
created_at timestamp with time zone default now() not null,
updated_at timestamp with time zone default now() not null
);
-- プロファイルのRLS有効化
alter table public.profiles enable row level security;
-- プロファイルのRLSポリシー
create policy "Users can view own profile"
on public.profiles for select
using (auth.uid() = id);
create policy "Users can update own profile"
on public.profiles for update
using (auth.uid() = id);
-- 新規ユーザー登録時にプロファイルを自動作成
create or replace function public.handle_new_user()
returns trigger as $$
begin
insert into public.profiles (id, email, display_name)
values (
new.id,
new.email,
coalesce(new.raw_user_meta_data->>'display_name', split_part(new.email, '@', 1))
);
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
-- ======================================
-- updated_at自動更新用関数
-- ======================================
create or replace function public.update_updated_at()
returns trigger as $$
begin
new.updated_at = now();
return new;
end;
$$ language plpgsql;
Step 4: アプリ固有テーブル作成
要件に基づいて追加テーブルを作成。 テンプレート例(請求書管理アプリの場合):
-- supabase/migrations/00002_app_tables.sql
-- ======================================
-- 顧客テーブル
-- ======================================
create table public.customers (
id uuid default uuid_generate_v4() primary key,
user_id uuid references auth.users not null,
name text not null,
email text,
address text,
created_at timestamp with time zone default now() not null,
updated_at timestamp with time zone default now() not null
);
alter table public.customers enable row level security;
create policy "Users can manage own customers"
on public.customers for all
using (auth.uid() = user_id);
create trigger update_customers_updated_at
before update on public.customers
for each row execute procedure public.update_updated_at();
-- ======================================
-- 請求書テーブル
-- ======================================
create table public.invoices (
id uuid default uuid_generate_v4() primary key,
user_id uuid references auth.users not null,
customer_id uuid references public.customers not null,
invoice_number text not null,
issue_date date not null,
due_date date,
status text default 'draft' check (status in ('draft', 'sent', 'paid')),
total_amount integer default 0,
notes text,
created_at timestamp with time zone default now() not null,
updated_at timestamp with time zone default now() not null
);
alter table public.invoices enable row level security;
create policy "Users can manage own invoices"
on public.invoices for all
using (auth.uid() = user_id);
create trigger update_invoices_updated_at
before update on public.invoices
for each row execute procedure public.update_updated_at();
Step 5: マイグレーション実行
# リモートDBに適用
supabase db push
# 確認
supabase db diff
Step 6: 環境変数取得
# プロジェクト情報を取得
supabase projects list
# APIキーを取得(Supabaseダッシュボードから)
# Settings > API > Project URL, anon key
Step 7: .env.local作成
cat > .env.local << EOF
NEXT_PUBLIC_SUPABASE_URL=https://{project-ref}.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY={anon-key}
EOF
テーブル設計ガイドライン
必須カラム
すべてのテーブルに以下を含める:
id uuid default uuid_generate_v4() primary key,
created_at timestamp with time zone default now() not null,
updated_at timestamp with time zone default now() not null
ユーザー関連テーブル
ユーザーに紐づくデータは user_id で関連付け:
user_id uuid references auth.users not null,
RLSポリシー
すべてのテーブルでRLSを有効化し、適切なポリシーを設定:
-- 基本パターン:自分のデータのみアクセス可能
create policy "Users can manage own data"
on public.{table_name} for all
using (auth.uid() = user_id);
セキュリティチェックリスト
- すべてのテーブルでRLSが有効化されているか
- 適切なRLSポリシーが設定されているか
- パスワードは安全に生成されているか
- 環境変数は.env.localに保存されているか
- .env.localが.gitignoreに含まれているか
トラブルシューティング
プロジェクト作成に失敗
Error: organization not found
→ 組織IDが正しいか確認。supabase orgs list で確認。
マイグレーションに失敗
Error: relation already exists
→ 既存のテーブルと重複している。テーブル名を変更するか、既存テーブルを削除。
RLSでアクセス拒否
Error: new row violates row-level security policy
→ RLSポリシーを確認。auth.uid() が正しく設定されているか確認。
Score
Total Score
45/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
○言語
プログラミング言語が設定されている
0/5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon