mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-18 08:29:40 +02:00
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>
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { pgTable, uuid, text, varchar, timestamp, jsonb, index, pgEnum } from 'drizzle-orm/pg-core';
|
|
import { relations } from 'drizzle-orm';
|
|
import { decks } from './decks.js';
|
|
|
|
// AI generation status enum
|
|
export const aiGenerationStatusEnum = pgEnum('ai_generation_status', [
|
|
'pending',
|
|
'processing',
|
|
'completed',
|
|
'failed',
|
|
]);
|
|
|
|
// AI generation metadata structure
|
|
export interface AIGenerationMetadata {
|
|
inputTokens?: number;
|
|
outputTokens?: number;
|
|
totalTokens?: number;
|
|
duration?: number;
|
|
error?: string;
|
|
cardCount?: number;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
export const aiGenerations = pgTable(
|
|
'ai_generations',
|
|
{
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
userId: text('user_id').notNull(),
|
|
deckId: uuid('deck_id').references(() => decks.id, { onDelete: 'set null' }),
|
|
functionName: varchar('function_name', { length: 100 }).notNull(),
|
|
prompt: text('prompt').notNull(),
|
|
model: varchar('model', { length: 100 }),
|
|
status: aiGenerationStatusEnum('status').default('pending').notNull(),
|
|
metadata: jsonb('metadata').default({}).$type<AIGenerationMetadata>(),
|
|
completedAt: timestamp('completed_at', { withTimezone: true }),
|
|
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
},
|
|
(table) => [
|
|
index('idx_ai_generations_user_id').on(table.userId),
|
|
index('idx_ai_generations_deck_id').on(table.deckId),
|
|
index('idx_ai_generations_status').on(table.status),
|
|
index('idx_ai_generations_created_at').on(table.createdAt),
|
|
]
|
|
);
|
|
|
|
export const aiGenerationsRelations = relations(aiGenerations, ({ one }) => ({
|
|
deck: one(decks, {
|
|
fields: [aiGenerations.deckId],
|
|
references: [decks.id],
|
|
}),
|
|
}));
|
|
|
|
export type AIGeneration = typeof aiGenerations.$inferSelect;
|
|
export type NewAIGeneration = typeof aiGenerations.$inferInsert;
|