managarten/packages/manadeck-database/src/schema/userStats.ts
Wuesteon f440ca2a8d fix(db): use TEXT for user_id columns across entire codebase
Better Auth generates non-UUID user IDs (32-char base62 format like
'otUe1YrfENPdHnrF3g1vSBfpkQfambCZ'). Changed all `uuid('user_id')` to
`text('user_id')` in Drizzle schemas for consistency with auth system.

Affected packages/apps:
- apps/calendar, clock, picture, zitare
- games/figgos, voxelava
- packages/manadeck-database, news-database, uload-database
- services/mana-core-auth (feedback schema)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-09 16:30:51 +01:00

25 lines
1.1 KiB
TypeScript

import { pgTable, text, integer, decimal, date, timestamp, index } from 'drizzle-orm/pg-core';
export const userStats = pgTable(
'user_stats',
{
userId: text('user_id').primaryKey(),
totalWins: integer('total_wins').default(0).notNull(),
totalSessions: integer('total_sessions').default(0).notNull(),
totalCardsStudied: integer('total_cards_studied').default(0).notNull(),
totalTimeSeconds: integer('total_time_seconds').default(0).notNull(),
averageAccuracy: decimal('average_accuracy', { precision: 5, scale: 2 }).default('0').notNull(),
streakDays: integer('streak_days').default(0).notNull(),
longestStreak: integer('longest_streak').default(0).notNull(),
lastStudyDate: date('last_study_date'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
},
(table) => [
index('idx_user_stats_total_wins').on(table.totalWins),
index('idx_user_stats_streak_days').on(table.streakDays),
]
);
export type UserStats = typeof userStats.$inferSelect;
export type NewUserStats = typeof userStats.$inferInsert;