データモデル
Data model
Parky の PostgreSQL スキーマは 70 テーブル超で構成されています
(infra/supabase/migrations/ 内の 000_init_schema.sql に 55、
店舗連携マイグレーションで 5、地理階層マイグレーション 009_geo_hierarchy_and_hub_stats.sql で 6)。
すべてのクライアントがこの単一のスキーマに直接接続するため、本ページがプロダクト横断の正となります。
プロダクト固有のビュー・クエリ例は各セクションのデータモデルページを参照してください。
Parky's PostgreSQL schema contains 70+ tables — 55 from 000_init_schema.sql,
5 from store-integration migrations (001–005), and 6 from the geo-hierarchy migration
(009_geo_hierarchy_and_hub_stats.sql). Because every client talks to this single schema,
this page is the source of truth. For product-specific views or example queries see each
product's own data-model page.
ドメイングループDomain groups
1. ユーザー・管理者・権限1. Users, admins, permissions
| Table | 役割 | Purpose |
app_users | エンドユーザープロファイル | End-user profiles |
admins | 管理者アカウント(Auth連携) | Admin accounts linked to Auth |
roles / role_permissions | RBAC。ロールとパーミッションのマトリクス | RBAC matrix for admins |
owners / owner_applications / owner_credits | 駐車場オーナー情報と審査 | Parking owners and applications |
user_subscriptions / subscription_plans | プラン契約 | User subscriptions |
2. 駐車場2. Parking lots
| Table | 役割 | Purpose |
parking_lots | 駐車場本体(位置・基本属性) | Lots — location and core attributes |
parking_lot_attributes | EAV形式の付加属性 | Extensible EAV attributes |
parking_lot_hours | 営業時間(曜日別) | Operating hours by day of week |
parking_lot_images | 画像ギャラリー | Image gallery |
parking_lot_pricing_rules | 料金エンジンのルール | Fee engine rules |
parking_lot_payment_methods | 受入可能な支払方法 | Accepted payment methods |
parking_lot_tags + tags | タグ付け(リンクテーブル) | Tag assignment via link table |
parking_lot_owners | 駐車場-オーナーのリンク | Lot-owner link |
parking_reviews | ユーザーレビュー | User reviews |
3. 駐車セッション・売上3. Sessions & revenue
| Table | 役割 | Purpose |
parking_sessions | 駐車の開始〜終了イベント | Parking start/end events |
revenue_transactions | 売上トランザクション | Revenue transactions |
credit_transactions | クレジット増減 | Credit ledger |
user_saved_parkings | お気に入り駐車場 | User favorites |
4. ゲーミフィケーション4. Gamification
| Table | 役割 | Purpose |
user_exp / level_definitions | 経験値とレベル | XP and level thresholds |
activity_exp_rules | 行動 → EXP のルール | Activity → XP rules |
user_activity_logs / user_activity_log_targets / user_activity_counts | 行動ログと集計 | Activity log and aggregates |
badge_definitions / badge_definition_tags | バッジ定義 | Badge definitions |
user_badges / user_badge_progress | ユーザー獲得バッジと進捗 | Earned badges and progress |
5. カスタマイズ(着せ替え)5. Customization (theming)
| Table | 役割 | Purpose |
customization_themes | テーマ(上位カテゴリ) | Themes |
customization_theme_parts / customization_theme_part_tags | テーマ構成パーツ | Theme parts and their tags |
customization_theme_items | ショップに並ぶ商品 | Shop items |
customization_skins | スキン定義 | Skin definitions |
user_themes / user_active_themes / theme_gifts | 所有・適用中・ギフト | Owned, active, and gifted themes |
6. 広告・ブースト6. Ads & boosts
| Table | 役割 | Purpose |
ads | 広告枠コンテンツ | Ad inventory |
boosts | オーナーの露出ブースト | Owner visibility boosts |
boost_impression_logs / boost_click_logs / boost_conversion_logs | ブースト効果計測 | Boost funnel metrics |
7. エリアスポンサー7. Area sponsors
| Table | 役割 | Purpose |
area_sponsors | スポンサー施設マスター(位置・課金・通知設定・集計カウンター)。PostGIS geography(Point,4326) で位置、radius_m で影響半径を保持 | Sponsor facility master — location (PostGIS), billing, notification config, aggregate counters |
sponsor_impression_logs | スポンサー表示ログ(placement: map / detail / session) | Sponsor impression log by placement |
sponsor_click_logs | スポンサークリックログ | Sponsor click-through log |
sponsor_notification_logs | 近接通知送信・開封ログ | Proximity notification delivery & open log |
sponsor_checkins | ユーザーのスポンサーエリアへのチェックイン記録 | User check-in records at sponsor locations |
user_location_reports | ユーザーの最新位置報告(1 ユーザー 1 レコード、PostGIS geography)。近接通知機能で使用 | Latest user location reports (one per user, PostGIS geography). Used by proximity notifications |
newsletter_subscribers | TOKYO CAR LIFE メールマガジン購読者。/media/ フォームから anon で INSERT 可、SELECT は authenticated のみ | TOKYO CAR LIFE newsletter subscribers. INSERT allowed for anon via /media/ form; SELECT authenticated-only |
PostGIS 関数:
• nearby_sponsors(p_lng, p_lat, p_radius_m) — 近傍スポンサーを距離順で返す
• find_users_near_active_sponsors(p_cooldown_hours) — 近接通知対象 (ユーザー×スポンサー) を抽出。CF Cron Trigger handleSponsorProximity から呼び出し
コードマスター: sponsor_category(restaurant / cafe / shop / attraction / hotel / service / other)、sponsor_status(draft / active / paused / ended)、sponsor_placement(map / detail / session / notification)
cron: check_sponsor_proximity_every_10min (pg_cron) が 10 分毎に Cloudflare Workers を呼んで FCM 送信
PostGIS functions:
• nearby_sponsors(p_lng, p_lat, p_radius_m) returns active sponsors near a coordinate, ordered by distance
• find_users_near_active_sponsors(p_cooldown_hours) extracts (user × sponsor) targets for proximity notifications. Called from the CF Cron Trigger handleSponsorProximity
Code masters: sponsor_category, sponsor_status, sponsor_placement
Cron: check_sponsor_proximity_every_10min (pg_cron) runs every 10 minutes and invokes the Cloudflare Workers which sends FCM messages.
8. 通知8. Notifications
| Table | 役割 | Purpose |
admin_notifications | 管理者通知(Realtime購読) | Admin notifications (Realtime) |
admin_tasks | 管理者向けタスク | Tasks assigned to admins |
user_notifications | ユーザー向け通知(FCM配信) | User notifications (FCM) |
user_push_tokens | FCMトークンの保持 | FCM token store |
9. コンテンツ・サポート9. Content & support
| Table | 役割 | Purpose |
articles | 記事管理(管理者ポータル)。story_number カラムで TOKYO CAR STORY の話数 (#01, #02…) を永続化 | Articles CMS. The story_number column persists TOKYO CAR STORY issue numbers (#01, #02…) |
assets | バイナリアセットのメタデータ。s3_key で Cloudflare R2 内のオブジェクトを指す(実体は Supabase Storage ではなく R2 バケットに格納) | Metadata for binary assets — s3_key points to a Cloudflare R2 object (binaries live in R2, not Supabase Storage) |
support_tickets | サポート問い合わせ | Support tickets |
error_reports | クライアントからのエラー報告 | Client error reports |
10. マスターデータ10. Master data
| Table | 役割 | Purpose |
codes | コードマスター。全列挙値の日本語・英語ラベル | Code master — enum value labels in JA/EN |
11. 地理階層・ハブ統計11. Geographic hierarchy & hub stats
マイグレーション 009_geo_hierarchy_and_hub_stats.sql で追加。Web 版のハブページ(都道府県→市区町村→スポット)の
事前集計・リンク生成に利用します。
Added in 009_geo_hierarchy_and_hub_stats.sql. Used by the web app to pre-aggregate
and link hub pages (prefecture → city → spot).
| Table | 役割 | Purpose |
prefectures | 都道府県マスター(スラッグ付き) | Prefecture master (with slug) |
regions | 地方区分(関東・関西等) | Region groupings (Kanto, Kansai, …) |
cities | 市区町村マスター(スラッグ付き) | City master (with slug) |
stations | 駅マスター(位置・アクセス計算用) | Station master for access calculation |
landmarks | ランドマーク(観光地・施設) | Landmarks (sights, facilities) |
parking_lot_nearby_spots | 駐車場と周辺スポットのリンクテーブル(事前計算結果) | Precomputed parking-lot ↔ nearby-spot link table |
12. 店舗連携(外部データ取り込み)12. Store integrations (external data ingest)
マイグレーション 001–005 で追加。外部 POS / 売上管理システムとの同期、レビュー取り込み、日次集計を担います。
同期ジョブは Workers queue parky-store-sync 経由で実行されます。
Added in migrations 001–005. Handles syncs with external POS / revenue systems,
review ingestion, and daily roll-ups. Sync jobs run through the
Workers parky-store-sync queue.
| Table | 役割 | Purpose |
store_integrations | 連携する外部システムの設定 | External-system integration config |
store_sales_daily | 日次売上データ | Daily sales data |
store_app_metrics_daily | 日次アプリ指標(外部計測ベース) | Daily app metrics from external sources |
store_reviews | 外部サイトから取り込んだレビュー | Reviews ingested from external sites |
store_sync_runs | 同期ジョブ実行履歴(成功/失敗/件数) | Sync job execution history (success/failure/counts) |
13. AI検索13. AI search
マイグレーション 017 で追加。自然言語による駐車場検索のための LLM プロバイダー管理と使用状況トラッキング。
APIキーの実値は Supabase Vault に暗号化保存し、ai_providers.vault_secret_id で参照します。
Added in migration 017. LLM provider management and usage tracking for natural-language parking search.
Actual API keys are encrypted in Supabase Vault, referenced via ai_providers.vault_secret_id.
| Table | 役割 | Purpose |
ai_providers | LLMプロバイダー設定(Claude/Gemini/OpenAI)。モデル名・有効/無効・優先順位・Vault参照・コスト単価 | LLM provider config (Claude/Gemini/OpenAI). Model, enabled flag, priority, Vault ref, cost rates |
ai_usage_logs | AI検索リクエストごとのログ。トークン数・コスト・レイテンシ・ステータス(parsed/need_info/error)・フォールバック追跡 | Per-request AI search log. Tokens, cost, latency, status (parsed/need_info/error), fallback tracking |
論理ER図(主要テーブル)Logical ER diagram (core tables)
erDiagram
APP_USERS ||--o{ PARKING_SESSIONS : starts
PARKING_LOTS ||--o{ PARKING_SESSIONS : hosts
APP_USERS ||--o{ PARKING_REVIEWS : writes
PARKING_LOTS ||--o{ PARKING_REVIEWS : receives
PARKING_LOTS ||--o{ PARKING_LOT_IMAGES : has
PARKING_LOTS ||--o{ PARKING_LOT_HOURS : has
PARKING_LOTS ||--o{ PARKING_LOT_PRICING_RULES : has
PARKING_LOTS ||--o{ PARKING_LOT_TAGS : has
TAGS ||--o{ PARKING_LOT_TAGS : labels
OWNERS ||--o{ PARKING_LOT_OWNERS : owns
PARKING_LOTS ||--o{ PARKING_LOT_OWNERS : owned_by
APP_USERS ||--o{ USER_BADGES : earns
BADGE_DEFINITIONS ||--o{ USER_BADGES : defines
APP_USERS ||--|| USER_EXP : accrues
APP_USERS ||--o{ USER_NOTIFICATIONS : receives
APP_USERS ||--o{ USER_PUSH_TOKENS : has
APP_USERS ||--o{ USER_SUBSCRIPTIONS : holds
SUBSCRIPTION_PLANS ||--o{ USER_SUBSCRIPTIONS : priced_as
ADMINS ||--o{ ADMIN_NOTIFICATIONS : sees
ROLES ||--o{ ADMINS : assigned
ROLES ||--o{ ROLE_PERMISSIONS : grants
重要:
Important:
列挙値(status, type, category等)はすべて codes テーブルで管理されます。CHECK制約に日本語は入れません。
All enum values live in codes. Never put Japanese into CHECK constraints — see the Conventions page.