add claude
This commit is contained in:
102
docs/DATABASE.md
Normal file
102
docs/DATABASE.md
Normal file
@ -0,0 +1,102 @@
|
||||
# データベース設定ガイド
|
||||
|
||||
## ローカル開発(Docker Compose)
|
||||
|
||||
### 1. 起動
|
||||
```bash
|
||||
# データベースとAPIを起動
|
||||
docker-compose up -d
|
||||
|
||||
# ログを確認
|
||||
docker-compose logs -f
|
||||
```
|
||||
|
||||
### 2. データベース初期化
|
||||
```bash
|
||||
# APIコンテナに入る
|
||||
docker-compose exec api bash
|
||||
|
||||
# マイグレーション実行
|
||||
alembic upgrade head
|
||||
|
||||
# マスタデータ投入
|
||||
python init_db.py
|
||||
```
|
||||
|
||||
## Supabase連携
|
||||
|
||||
### 1. Supabaseプロジェクト作成
|
||||
1. [Supabase](https://supabase.com)でプロジェクト作成
|
||||
2. Settings > Database から接続情報を取得
|
||||
|
||||
### 2. 環境変数設定
|
||||
```bash
|
||||
# .env
|
||||
DATABASE_URL_SUPABASE=postgresql+asyncpg://postgres.[project-ref]:[password]@aws-0-[region].pooler.supabase.com:5432/postgres
|
||||
USE_SUPABASE=true
|
||||
```
|
||||
|
||||
### 3. テーブル作成
|
||||
Supabase SQL Editorで以下を実行:
|
||||
|
||||
```sql
|
||||
-- Alembicのマイグレーションを実行
|
||||
-- または直接SQLでテーブル作成
|
||||
```
|
||||
|
||||
## Cloudflare Tunnel設定
|
||||
|
||||
### 1. トンネル作成
|
||||
```bash
|
||||
# Cloudflareダッシュボードでトンネル作成
|
||||
# トークンを取得
|
||||
```
|
||||
|
||||
### 2. 環境変数設定
|
||||
```bash
|
||||
# .env
|
||||
CLOUDFLARE_TUNNEL_TOKEN=your-tunnel-token
|
||||
```
|
||||
|
||||
### 3. 起動
|
||||
```bash
|
||||
# tunnelプロファイルを含めて起動
|
||||
docker-compose --profile tunnel up -d
|
||||
```
|
||||
|
||||
## データベーススキーマ
|
||||
|
||||
### users
|
||||
- ユーザー情報(DID、ハンドル)
|
||||
|
||||
### card_master
|
||||
- カードマスタデータ(16種類)
|
||||
|
||||
### user_cards
|
||||
- ユーザー所有カード
|
||||
- uniqueカードフラグ付き
|
||||
|
||||
### unique_card_registry
|
||||
- グローバルuniqueカード登録
|
||||
- 各カードIDにつき1人のみ所有可能
|
||||
|
||||
### draw_history
|
||||
- ガチャ履歴
|
||||
|
||||
### gacha_pools
|
||||
- ピックアップガチャ設定
|
||||
|
||||
## バックアップ
|
||||
|
||||
### ローカル
|
||||
```bash
|
||||
# バックアップ
|
||||
docker-compose exec postgres pg_dump -U postgres aicard > backup.sql
|
||||
|
||||
# リストア
|
||||
docker-compose exec -T postgres psql -U postgres aicard < backup.sql
|
||||
```
|
||||
|
||||
### Supabase
|
||||
- 自動バックアップが有効
|
||||
- ダッシュボードからダウンロード可能
|
Reference in New Issue
Block a user