1
0
card/docs/DATABASE.md
2025-06-01 21:39:53 +09:00

102 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# データベース設定ガイド
## ローカル開発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
- 自動バックアップが有効
- ダッシュボードからダウンロード可能