82 lines
3.3 KiB
Plaintext
82 lines
3.3 KiB
Plaintext
// =============================================================================
|
|
// Presence Service - Prisma Schema (IT0)
|
|
// Table prefix: presence_ to avoid collision with other IT0 services
|
|
// userId: VarChar(36) for UUID format
|
|
// =============================================================================
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// 事件日志表 (append-only)
|
|
model EventLog {
|
|
id BigInt @id @default(autoincrement())
|
|
userId String? @map("user_id") @db.VarChar(36)
|
|
installId String @map("install_id") @db.VarChar(64)
|
|
eventName String @map("event_name") @db.VarChar(64)
|
|
eventTime DateTime @map("event_time") @db.Timestamptz()
|
|
deviceBrand String? @map("device_brand") @db.VarChar(64)
|
|
deviceModel String? @map("device_model") @db.VarChar(64)
|
|
deviceOs String? @map("device_os") @db.VarChar(32)
|
|
appVersion String? @map("app_version") @db.VarChar(32)
|
|
locale String? @map("locale") @db.VarChar(16)
|
|
properties Json? @db.JsonB
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
|
|
|
|
@@index([eventTime], name: "idx_presence_event_log_event_time")
|
|
@@index([eventName], name: "idx_presence_event_log_event_name")
|
|
@@index([eventName, eventTime], name: "idx_presence_event_log_event_name_time")
|
|
@@index([userId], name: "idx_presence_event_log_user_id")
|
|
@@index([deviceBrand], name: "idx_presence_event_log_device_brand")
|
|
@@index([appVersion], name: "idx_presence_event_log_app_version")
|
|
@@map("presence_event_log")
|
|
}
|
|
|
|
// 设备档案表 (每台设备一行, upsert 更新)
|
|
model DeviceProfile {
|
|
installId String @id @map("install_id") @db.VarChar(64)
|
|
userId String? @map("user_id") @db.VarChar(36)
|
|
deviceBrand String? @map("device_brand") @db.VarChar(64)
|
|
deviceModel String? @map("device_model") @db.VarChar(64)
|
|
deviceOs String? @map("device_os") @db.VarChar(32)
|
|
appVersion String? @map("app_version") @db.VarChar(32)
|
|
locale String? @map("locale") @db.VarChar(16)
|
|
firstSeenAt DateTime @default(now()) @map("first_seen_at") @db.Timestamptz()
|
|
lastSeenAt DateTime @updatedAt @map("last_seen_at") @db.Timestamptz()
|
|
eventCount Int @default(1) @map("event_count")
|
|
|
|
@@index([deviceBrand], name: "idx_presence_device_profile_brand")
|
|
@@index([appVersion], name: "idx_presence_device_profile_app_version")
|
|
@@index([userId], name: "idx_presence_device_profile_user_id")
|
|
@@index([lastSeenAt(sort: Desc)], name: "idx_presence_device_profile_last_seen")
|
|
@@map("presence_device_profile")
|
|
}
|
|
|
|
// 日活统计表
|
|
model DailyActiveStats {
|
|
day DateTime @id @map("day") @db.Date
|
|
dauCount Int @map("dau_count")
|
|
dauByProvince Json? @map("dau_by_province") @db.JsonB
|
|
dauByCity Json? @map("dau_by_city") @db.JsonB
|
|
calculatedAt DateTime @map("calculated_at") @db.Timestamptz()
|
|
version Int @default(1)
|
|
|
|
@@map("presence_daily_active_users")
|
|
}
|
|
|
|
// 在线人数快照表
|
|
model OnlineSnapshot {
|
|
id BigInt @id @default(autoincrement())
|
|
ts DateTime @unique @db.Timestamptz()
|
|
onlineCount Int @map("online_count")
|
|
windowSeconds Int @default(300) @map("window_seconds")
|
|
|
|
@@index([ts(sort: Desc)], name: "idx_presence_online_snapshots_ts")
|
|
@@map("presence_online_snapshots")
|
|
}
|