27 lines
967 B
TypeScript
27 lines
967 B
TypeScript
import { pgTable, uuid, integer, timestamp } from 'drizzle-orm/pg-core';
|
|
import { unique } from 'drizzle-orm/pg-core';
|
|
import { stackEnum, levelEnum } from './enums.js';
|
|
import { users } from './users.js';
|
|
|
|
export const userStats = pgTable(
|
|
'user_stats',
|
|
{
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
userId: uuid('user_id')
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: 'cascade' }),
|
|
stack: stackEnum('stack').notNull(),
|
|
level: levelEnum('level').notNull(),
|
|
totalQuestions: integer('total_questions').notNull().default(0),
|
|
correctAnswers: integer('correct_answers').notNull().default(0),
|
|
testsTaken: integer('tests_taken').notNull().default(0),
|
|
lastTestAt: timestamp('last_test_at', { withTimezone: true }),
|
|
},
|
|
(t) => ({
|
|
userStackLevelUnique: unique().on(t.userId, t.stack, t.level),
|
|
})
|
|
);
|
|
|
|
export type UserStat = typeof userStats.$inferSelect;
|
|
export type NewUserStat = typeof userStats.$inferInsert;
|