mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 23:39:40 +02:00
Phase 3 of ManaDeck database migration: Database Package (@manacore/manadeck-database): - Configure package for NodeNext module resolution with .js extensions - Add build script and proper exports for ESM/CJS compatibility - Export schema types and Drizzle utilities Backend Migration: - Add DatabaseModule with singleton database provider - Create repository layer with Drizzle ORM: - DeckRepository: CRUD operations for decks - CardRepository: CRUD operations for cards - UserStatsRepository: Stats and leaderboard queries - DeckTemplateRepository: Template management - Update ApiController to use repositories for all database operations - Update PublicController to use repositories for featured decks, leaderboard, templates - Add DATABASE_URL environment variable support The backend now uses PostgreSQL via Drizzle ORM instead of Supabase SDK for database operations. Supabase is still used for auth (via Mana Core) and edge functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
105 lines
2.8 KiB
TypeScript
105 lines
2.8 KiB
TypeScript
import { getDb, closeDb } from './client.js';
|
|
import { deckTemplates } from './schema/index.js';
|
|
|
|
/**
|
|
* Seed the database with initial data
|
|
*/
|
|
async function seed() {
|
|
console.log('Seeding database...');
|
|
|
|
const db = getDb();
|
|
|
|
try {
|
|
// Seed deck templates
|
|
const templates = [
|
|
{
|
|
title: 'Language Basics',
|
|
description: 'Learn basic vocabulary and phrases for a new language',
|
|
category: 'languages',
|
|
templateData: {
|
|
cards: [
|
|
{
|
|
cardType: 'flashcard' as const,
|
|
content: { front: 'Hello', back: 'Hallo', hint: 'Greeting' },
|
|
},
|
|
{
|
|
cardType: 'flashcard' as const,
|
|
content: { front: 'Goodbye', back: 'Auf Wiedersehen' },
|
|
},
|
|
],
|
|
settings: { language: 'de' },
|
|
tags: ['language', 'basics', 'german'],
|
|
},
|
|
isActive: true,
|
|
isPublic: true,
|
|
popularity: 100,
|
|
},
|
|
{
|
|
title: 'Math Fundamentals',
|
|
description: 'Essential math concepts and formulas',
|
|
category: 'education',
|
|
templateData: {
|
|
cards: [
|
|
{
|
|
cardType: 'quiz' as const,
|
|
content: {
|
|
question: 'What is 2 + 2?',
|
|
options: ['3', '4', '5', '6'],
|
|
correctAnswer: 1,
|
|
explanation: '2 + 2 equals 4',
|
|
},
|
|
},
|
|
],
|
|
settings: { difficulty: 'beginner' },
|
|
tags: ['math', 'basics'],
|
|
},
|
|
isActive: true,
|
|
isPublic: true,
|
|
popularity: 80,
|
|
},
|
|
{
|
|
title: 'Programming Concepts',
|
|
description: 'Core programming concepts and terminology',
|
|
category: 'technology',
|
|
templateData: {
|
|
cards: [
|
|
{
|
|
cardType: 'flashcard' as const,
|
|
content: {
|
|
front: 'Variable',
|
|
back: 'A named storage location in memory that holds a value',
|
|
},
|
|
},
|
|
{
|
|
cardType: 'flashcard' as const,
|
|
content: {
|
|
front: 'Function',
|
|
back: 'A reusable block of code that performs a specific task',
|
|
},
|
|
},
|
|
],
|
|
settings: {},
|
|
tags: ['programming', 'coding', 'basics'],
|
|
},
|
|
isActive: true,
|
|
isPublic: true,
|
|
popularity: 90,
|
|
},
|
|
];
|
|
|
|
console.log('Inserting deck templates...');
|
|
await db.insert(deckTemplates).values(templates).onConflictDoNothing();
|
|
|
|
console.log('Seeding completed successfully!');
|
|
} catch (error) {
|
|
console.error('Seeding failed:', error);
|
|
throw error;
|
|
} finally {
|
|
await closeDb();
|
|
}
|
|
}
|
|
|
|
seed().catch((error) => {
|
|
console.error('Seed script failed:', error);
|
|
process.exit(1);
|
|
});
|