(userId: string)
| 171 | * Always writes to the primary — never takes a read-routing executor. |
| 172 | */ |
| 173 | export async function ensureUserStatsExists(userId: string): Promise<void> { |
| 174 | await db |
| 175 | .insert(userStats) |
| 176 | .values({ |
| 177 | id: generateId(), |
| 178 | userId: userId, |
| 179 | currentUsageLimit: getFreeTierLimit().toString(), |
| 180 | usageLimitUpdatedAt: new Date(), |
| 181 | }) |
| 182 | .onConflictDoNothing({ target: userStats.userId }) |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Get comprehensive usage data for a user |
no test coverage detected