feat: add user_stats, audit_logs and verification tokens schema
Made-with: Cursor
This commit is contained in:
26
src/db/schema/userStats.ts
Normal file
26
src/db/schema/userStats.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user