データモデル Data model

主要エンティティ、フィールド、リレーションをドメイン別に整理しました。 詳細な型は parky/web/portal/admin/src/lib/api.ts の TypeScript インターフェースが一次情報源です。

Core entities, fields, and relationships grouped by domain. The canonical source for field types is the TypeScript interfaces in parky/web/portal/admin/src/lib/api.ts.

ドメイン俯瞰図 Domain map

flowchart LR
  subgraph Parking["🅿️ Parking domain"]
    PL[parking_lots]
    PLI[parking_lot_images]
    PLT[parking_lot_tags]
    PLA[parking_lot_attributes]
    PLP[parking_lot_payment_methods]
    PLO[parking_lot_owners]
    PR[parking_reviews]
    PS[parking_sessions]
  end
  subgraph Users["👤 Users"]
    AU[app_users]
    USP[user_saved_parkings]
    UAL[user_activity_logs]
    US[user_subscriptions]
  end
  subgraph Owner["🏢 Owners"]
    OW[owners]
    OA[owner_applications]
    OC[owner_credits]
    CT[credit_transactions]
    B[boosts]
  end
  subgraph Game["🏆 Gamification"]
    BD[badge_definitions]
    UBP[user_badge_progress]
    UE[user_exp]
    LD[level_definitions]
    AER[activity_exp_rules]
  end
  subgraph Theme["🎨 Customization"]
    CTh[customization_themes]
    CTI[customization_theme_items]
    CTP[customization_theme_parts]
    TG[theme_gifts]
    UT[user_themes]
  end
  subgraph Ops["🛠 Operations"]
    ST[support_tickets]
    ER[error_reports]
    AT[admin_tasks]
    UN[user_notifications]
    AN[admin_notifications]
  end
  subgraph Content["📝 Content"]
    ART[articles]
    ADS[ads]
    TAG[tags]
  end
  subgraph Rev["💰 Revenue"]
    SP[subscription_plans]
    RT[revenue_transactions]
    RMS[(revenue_monthly_summary
view)] end subgraph Sys["⚙️ System"] AD[admins] RL[roles] RP[role_permissions] AS[assets] CD[codes] end PL --> PLI PL --> PLT PL --> PLA PL --> PLP PL --> PLO PL --> PR PL --> PS PLO --> OW AU --> PS AU --> PR AU --> USP AU --> UAL AU --> US AU --> UE AU --> UBP OW --> OA OW --> OC OW --> CT OW --> B B --> PL BD --> UBP LD --> UE CTh --> CTI CTI --> CTP CTh --> TG TG --> UT AT -.-> ST AT -.-> ER AT -.-> OA AT -.-> PL SP --> US RT --> SP AD --> RL RL --> RP

主要テーブル定義 Core table definitions

parking_lots core

駐車場の中核テーブル。GPS 座標は PostGIS の geography 型で保持され、nearby_parking_lots() RPC で周辺検索が可能。

The core parking lot table. GPS is stored in a PostGIS geography column and queried via the nearby_parking_lots() RPC.

FieldTypeNotes
iduuidPK
nametext
addresstext
lat / lngnumeric表示用。実体は location (geography)Display-only; source is location (geography)
locationgeography(point)PostGIS
total_spacesint
operating_hourstext / JSONB
structureenum平地 / 立体 / 地下などflat / multistory / underground
entry_methodenum
max_height_m / max_width_m / max_length_mnumeric車両制限Vehicle limits
max_weight_tnumeric
min_clearance_cmint
rulesJSONB料金ルール配列Array of pricing rules
statusenumnew / active / hidden / ...
sourceenumデータ取得元Data origin

app_users core

FieldTypeNotes
iduuidPK (Supabase Auth user)
display_nametext
emailemail
vehicle_typeenumsedan / suv / kei など (codes 参照)Master-coded
premiumboolean
statusenumactive / withdrawn / suspended
created_attimestamptz

parking_sessions

ユーザーの駐車履歴。入出庫時刻と請求額を保持。

Per-user parking history with entry / exit timestamps and billed amount.

FieldType
id, user_id, parking_lot_iduuid, FK, FK
started_at, ended_attimestamptz
statusenum (parking / completed / cancelled)
total_amountint (minor units)
memotext

owners, owner_applications, owner_credits, credit_transactions

badge_definitions, user_badge_progress, user_exp, level_definitions, activity_exp_rules gamification

TablePurpose
badge_definitionsバッジ定義 (名前、アイコン、条件、閾値)badge definitions (name, icon, conditions, threshold)
user_badge_progressユーザー × バッジの進捗カウントprogress count per user × badge
user_exp総 EXP と現在レベルtotal EXP and current level
level_definitionsレベル毎の必要 EXPrequired EXP per level
activity_exp_rulesアクティビティ型 → 付与 EXPactivity type → EXP granted
user_activity_logs全ての行動イベント。metadata (JSONB) にイベント詳細all activity events; detail in metadata (JSONB)
user_activity_log_targetsログの参照先 (parking / review / user 等) のマルチ参照multi-entity references for each log

customization_themes, ..._items, ..._parts, theme_gifts, user_themes theming

support_tickets, error_reports, admin_tasks ops

admin_tasks が 4 種類のソース (support / misinformation_report / owner_application / parking_new_registration) を task_kind + ref_id で指す設計。ポリモーフィックなリレーション。

admin_tasks polymorphically references four source tables via task_kind + ref_id, which is what enables the unified task inbox.

revenue_transactions & revenue_monthly_summary revenue

admins, roles, role_permissions system

管理者は Supabase Auth ユーザーと admins テーブルの 2 層で管理。ロールは roles、権限キーは role_permissions

Admins are tracked in both Supabase Auth and the admins table. Roles live in roles, permission keys in role_permissions.

codes master

カテゴリ付きラベル辞書 (user_status / vehicle_type / ...)。起動時に一括ロードされ、UI のドロップダウンとラベル表示に使われます。

A category-keyed label dictionary (user_status / vehicle_type / ...) that's loaded once at boot and powers every dropdown and label in the UI.

TypeScript 型との対応 TypeScript type mapping

各テーブルは src/lib/api.ts に対応する TS インターフェースを持ちます。 代表的なものを以下に示しますが、新しい機能を追加するときは必ずこのファイルを一次情報として確認してください。

Every table has a matching TS interface in src/lib/api.ts. Use that file as the source of truth when adding new features.

TableInterface
parking_lotsParkingLot (+ ParkingRule, RuleTier)
app_usersAppUser
parking_sessionsParkingSession
parking_reviewsParkingReview
ownersOwner
owner_applicationsOwnerApplication
owner_creditsOwnerCredit
credit_transactionsCreditTransaction
boostsBoost
badge_definitionsBadgeDefinition (+ BadgeCondition)
user_badge_progressUserBadgeProgress
user_expUserEXP
level_definitionsLevelDefinition
activity_exp_rulesActivityExpRule
user_activity_logsUserActivityLog
customization_themesCustomizationTheme
customization_theme_partsCustomizationThemePart
articles / adsArticle / Ad
user_notifications / admin_notificationsUserNotification / AdminNotification
admin_tasksAdminTask
admins / rolesAdmin / Role
assetsAsset
subscription_plansSubscriptionPlan
tagsTag
注意Caveat: フィールド定義はシード SQL / マイグレーション (parky/infra/supabase/migrations/) と TS 型の両方で進化します。齟齬があった場合はマイグレーション側を正とし、TS 型をフォローしてください。 Schema lives in both the migrations under parky/infra/supabase/migrations/ and in TypeScript. If they disagree, migrations win — update the TS types to follow.