managarten/packages/cards-database/src/schema/decks.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

40 lines
1.6 KiB
TypeScript

import { uuid, text, varchar, boolean, timestamp, jsonb, index } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
import { cardsSchema } from './schema';
import { cards } from './cards';
import { studySessions } from './studySessions';
import { aiGenerations } from './aiGenerations';
export const decks = cardsSchema.table(
'decks',
{
id: uuid('id').primaryKey().defaultRandom(),
userId: text('user_id').notNull(),
title: varchar('title', { length: 255 }).notNull(),
description: text('description'),
coverImageUrl: text('cover_image_url'),
isPublic: boolean('is_public').default(false).notNull(),
isFeatured: boolean('is_featured').default(false).notNull(),
featuredAt: timestamp('featured_at', { withTimezone: true }),
settings: jsonb('settings').default({}).$type<Record<string, unknown>>(),
tags: text('tags').array().default([]),
metadata: jsonb('metadata').default({}).$type<Record<string, unknown>>(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
},
(table) => [
index('idx_decks_user_id').on(table.userId),
index('idx_decks_is_public').on(table.isPublic),
index('idx_decks_is_featured').on(table.isFeatured),
index('idx_decks_updated_at').on(table.updatedAt),
]
);
export const decksRelations = relations(decks, ({ many }) => ({
cards: many(cards),
studySessions: many(studySessions),
aiGenerations: many(aiGenerations),
}));
export type Deck = typeof decks.$inferSelect;
export type NewDeck = typeof decks.$inferInsert;