managarten/apps/presi/apps/backend/src/db/schema/decks.schema.ts
Till JS fd0516f119 feat(presi): add DB indexes, Swagger docs, hardened validation (score 81→86)
- Add 7 database indexes on all query paths (userId, deckId, order, themeId)
- Add timestamps with timezone for all tables
- Enable Swagger/OpenAPI documentation at /api/docs
- Add ApiTags and ApiBearerAuth to all controllers
- Add ParseUUIDPipe on all ID parameters
- Harden DTO validation: string length limits, @IsIn for enums,
  @IsUrl for URLs, @ArrayMaxSize for arrays, @Min(0) for order fields
- Update audit to reflect improvements

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 22:35:11 +01:00

33 lines
1.2 KiB
TypeScript

import { pgTable, uuid, text, boolean, timestamp, index } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
import { slides } from './slides.schema';
import { themes } from './themes.schema';
import { sharedDecks } from './shared-decks.schema';
export const decks = pgTable(
'decks',
{
id: uuid('id').primaryKey().defaultRandom(),
userId: text('user_id').notNull(), // TEXT for Better Auth nanoid user IDs
title: text('title').notNull(),
description: text('description'),
themeId: uuid('theme_id').references(() => themes.id),
isPublic: boolean('is_public').default(false).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
},
(table) => [
index('decks_user_id_idx').on(table.userId),
index('decks_user_updated_idx').on(table.userId, table.updatedAt),
index('decks_theme_id_idx').on(table.themeId),
]
);
export const decksRelations = relations(decks, ({ many, one }) => ({
slides: many(slides),
theme: one(themes, {
fields: [decks.themeId],
references: [themes.id],
}),
sharedDecks: many(sharedDecks),
}));