managarten/packages/manadeck-database/src/schema/cardProgress.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

58 lines
1.8 KiB
TypeScript

import {
pgTable,
uuid,
text,
integer,
timestamp,
index,
pgEnum,
decimal,
unique,
} from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
import { cards } from './cards.js';
// Progress status enum (SM-2 algorithm states)
export const progressStatusEnum = pgEnum('progress_status', [
'new',
'learning',
'review',
'relearning',
]);
export const cardProgress = pgTable(
'card_progress',
{
id: uuid('id').primaryKey().defaultRandom(),
userId: text('user_id').notNull(),
cardId: uuid('card_id')
.notNull()
.references(() => cards.id, { onDelete: 'cascade' }),
// SM-2 algorithm fields
easeFactor: decimal('ease_factor', { precision: 4, scale: 2 }).default('2.5').notNull(),
interval: integer('interval').default(0).notNull(), // Days until next review
repetitions: integer('repetitions').default(0).notNull(),
lastReviewed: timestamp('last_reviewed', { withTimezone: true }),
nextReview: timestamp('next_review', { withTimezone: true }),
status: progressStatusEnum('status').default('new').notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
},
(table) => [
index('idx_card_progress_user_id').on(table.userId),
index('idx_card_progress_card_id').on(table.cardId),
index('idx_card_progress_next_review').on(table.nextReview),
index('idx_card_progress_status').on(table.status),
unique('unique_user_card').on(table.userId, table.cardId),
]
);
export const cardProgressRelations = relations(cardProgress, ({ one }) => ({
card: one(cards, {
fields: [cardProgress.cardId],
references: [cards.id],
}),
}));
export type CardProgress = typeof cardProgress.$inferSelect;
export type NewCardProgress = typeof cardProgress.$inferInsert;