データモデル 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_permissionsRBAC。ロールとパーミッションのマトリクス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_attributesEAV形式の付加属性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_subscribersTOKYO 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_tokensFCMトークンの保持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_keyCloudflare 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_providersLLMプロバイダー設定(Claude/Gemini/OpenAI)。モデル名・有効/無効・優先順位・Vault参照・コスト単価LLM provider config (Claude/Gemini/OpenAI). Model, enabled flag, priority, Vault ref, cost rates
ai_usage_logsAI検索リクエストごとのログ。トークン数・コスト・レイテンシ・ステータス(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.