managarten/packages/cards-database/src/schema/deckTemplates.ts
Till JS 3ea28b9065 refactor(db): consolidate ~20+ databases into 2 (mana_platform + mana_sync)
Mirrors the frontend unification (single IndexedDB) on the backend.
All services now use pgSchema() for isolation within one shared database,
enabling cross-schema JOINs, simplified ops, and zero DB setup for new apps.

- Migrate 7 services from pgTable() to pgSchema(): mana-user (usr),
  mana-media (media), todo, traces, presi, uload, cards
- Update all DATABASE_URLs in .env.development, docker-compose, configs
- Rewrite init-db scripts for 2 databases + 12 schemas
- Rewrite setup-databases.sh for consolidated architecture
- Update shared-drizzle-config default to mana_platform
- Update CLAUDE.md with new database architecture docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 14:31:28 +02:00

46 lines
1.4 KiB
TypeScript

import {
uuid,
varchar,
text,
boolean,
integer,
timestamp,
jsonb,
index,
} from 'drizzle-orm/pg-core';
import { cardsSchema } from './schema';
// Template data structure
export interface DeckTemplateData {
cards: Array<{
title?: string;
content: Record<string, unknown>;
cardType: 'text' | 'flashcard' | 'quiz' | 'mixed';
}>;
settings?: Record<string, unknown>;
tags?: string[];
}
export const deckTemplates = cardsSchema.table(
'deck_templates',
{
id: uuid('id').primaryKey().defaultRandom(),
title: varchar('title', { length: 255 }).notNull(),
description: text('description'),
category: varchar('category', { length: 100 }),
templateData: jsonb('template_data').notNull().$type<DeckTemplateData>(),
isActive: boolean('is_active').default(true).notNull(),
isPublic: boolean('is_public').default(true).notNull(),
popularity: integer('popularity').default(0).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
},
(table) => [
index('idx_deck_templates_category').on(table.category),
index('idx_deck_templates_is_active').on(table.isActive),
index('idx_deck_templates_popularity').on(table.popularity),
]
);
export type DeckTemplate = typeof deckTemplates.$inferSelect;
export type NewDeckTemplate = typeof deckTemplates.$inferInsert;