04. モバイルが触るデータモデル 04. Mobile-facing data model

全 93 テーブルのうち、モバイルが読み書きするのはこの 12 テーブル。 Of the 93 tables total, these 12 are what the mobile app reads or writes.

Parky のデータベース(Supabase PostgreSQL)には 93 テーブルありますが、 モバイルアプリから見える/触れるのはこのページにまとめた少数のテーブルだけです。 残りは管理者ポータル・マーケティングポータル・内部処理のためのものです。

The Parky database (Supabase PostgreSQL) has 93 tables, but only a small set is visible to the mobile app. Everything else is for the admin portal, marketing portal, or internal workflows.

大前提:モバイルは BFF 経由でしか触らない Premise: mobile never touches these tables directly

モバイルはSupabase の DB を直接叩きません。全ての読み書きは Parky BFF(/v1/*)経由です。 本ページは「BFF のレスポンスに含まれるフィールドはどのテーブル由来か」を理解するための参考です。 RLS ポリシーは BFF の service_role コンテキストで評価されるので、クライアントからの個別 RLS 検証は必要ありません。 The mobile app never hits Supabase DB directly. Every read and write goes through the Parky BFF (/v1/*). This page is a reference for understanding where each BFF response field comes from. RLS is evaluated in the BFF's service-role context, so client-side RLS checks are not needed.

モバイルが関わる 12 テーブルの関係図 The 12 mobile-facing tables

erDiagram
  APP_USERS ||--o{ PARKING_SESSIONS : "starts"
  APP_USERS ||--o{ USER_SAVED_PARKING_LOTS : "favorites"
  APP_USERS ||--o{ USER_VEHICLES : "owns"
  APP_USERS ||--o{ USER_PUSH_TOKENS : "devices"
  APP_USERS ||--o{ USER_NOTIFICATIONS : "receives"
  APP_USERS ||--o| USER_SUBSCRIPTIONS : "has"
  APP_USERS ||--o{ USER_SEARCH_PRESETS : "saves"
  APP_USERS ||--o{ USER_EXP : "earns"
  APP_USERS ||--o{ USER_BADGES : "earns"
  APP_USERS ||--o{ REVIEWS : "posts"
  PARKING_LOTS ||--o{ PARKING_SESSIONS : "hosts"
  PARKING_LOTS ||--o{ REVIEWS : "receives"
  PARKING_LOTS ||--o{ USER_SAVED_PARKING_LOTS : "saved by"

  APP_USERS {
    uuid id PK
    uuid auth_user_id FK
    string display_name
    string email
    code user_status
    code vehicle_type
    bool premium
    timestamp deleted_at
  }
  PARKING_LOTS {
    uuid id PK
    string name
    point location
    jsonb pricing_rules
    jsonb tags
    code status
  }
  PARKING_SESSIONS {
    uuid id PK
    uuid user_id FK
    uuid parking_lot_id FK
    timestamp entry_at
    timestamp exit_at
    code session_status
    int fee_amount
  }
  USER_SAVED_PARKING_LOTS {
    uuid user_id FK
    uuid parking_lot_id FK
  }
  USER_VEHICLES {
    uuid id PK
    uuid user_id FK
    code vehicle_type
    string plate
    timestamp deleted_at
  }
  USER_PUSH_TOKENS {
    uuid id PK
    uuid user_id FK
    string token
    code device_type
    string app_version
  }
  USER_NOTIFICATIONS {
    uuid id PK
    uuid user_id FK
    code notif_type
    code notif_status
    timestamp read_at
  }
  USER_SUBSCRIPTIONS {
    uuid id PK
    uuid user_id FK
    code platform
    string product_id
    timestamp expires_at
  }
  USER_SEARCH_PRESETS {
    uuid id PK
    uuid user_id FK
    jsonb filters
    bool is_default
  }
  USER_EXP {
    uuid user_id FK
    int total_exp
    int level
  }
  USER_BADGES {
    uuid user_id FK
    string badge_code
    timestamp earned_at
  }
  REVIEWS {
    uuid id PK
    uuid user_id FK
    uuid parking_lot_id FK
    int rating
    text comment
    code review_status
  }

テーブル詳細 Table details

1. app_users

2. parking_lots (読み取り専用)

3. parking_sessions

4. user_saved_parking_lots

5. user_vehicles

6. user_push_tokens (重要)

7. user_notifications

8. user_subscriptions

9. user_search_presets

10. user_exp / user_badges(読み取り専用)

11. reviews

12. assets(参照のみ)

コードマスター(codes)の扱い Working with the code master (codes)

上の表で code と書かれている列(user_statusvehicle_typesession_statusnotif_typereview_status など)は、日本語ラベルではなくコード値(英語小文字)で保存されます。 表示ラベルは codes テーブルで管理されており、モバイルは GET /v1/codes(edge キャッシュ)で一括取得してローカル辞書として持っておきます。

Columns marked code above (user_status, vehicle_type, session_status, notif_type, review_status, etc.) store code values (lower-case English), not display labels. Display labels live in the codes table. The mobile app fetches them in bulk via GET /v1/codes (edge-cached) and keeps a local dictionary.

日時・位置情報の扱い Datetimes and locations

次のステップNext: データ構造を理解したら、05. FCM / R2 / Mapbox / ジオフェンス で外部連携を確認してください。 Next, check the four integrations in 05. FCM / R2 / Mapbox / Geofence.