design database
This commit is contained in:
@@ -36,3 +36,69 @@ import {
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
import { id, createdAt, updatedAt } from "../common";
|
||||
import { user } from "./auth.db";
|
||||
|
||||
// Levels table: Store information about each programming level
|
||||
export const level = pgTable("level", {
|
||||
id,
|
||||
title: varchar("title", { length: 255 }).notNull(),
|
||||
description: text("description"),
|
||||
difficulty: integer("difficulty").notNull(), // 1-5 scale
|
||||
order: integer("order").notNull().unique(), // Level sequence
|
||||
codeBlocks: jsonb("code_blocks"), // Available code blocks for this level (JSON array)
|
||||
initialCode: jsonb("initial_code"), // Starting code structure (JSON)
|
||||
solution: jsonb("solution"), // Correct solution (JSON, optional for validation)
|
||||
rewards: jsonb("rewards"), // Rewards upon completion (JSON: points, badges, etc.)
|
||||
isActive: boolean("is_active").default(true).notNull(),
|
||||
createdAt,
|
||||
updatedAt,
|
||||
});
|
||||
|
||||
// User Level Progress: Track user progress through levels
|
||||
export const userLevelProgress = pgTable("user_level_progress", {
|
||||
id,
|
||||
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
levelId: integer("level_id").notNull().references(() => level.id, { onDelete: "cascade" }),
|
||||
completed: boolean("completed").default(false).notNull(),
|
||||
score: integer("score"), // Points earned
|
||||
timeTaken: integer("time_taken"), // Time in seconds
|
||||
attempts: integer("attempts").default(1).notNull(),
|
||||
codeSnapshot: jsonb("code_snapshot"), // Final code state (JSON)
|
||||
completedAt: timestamp("completed_at"),
|
||||
createdAt,
|
||||
updatedAt,
|
||||
});
|
||||
|
||||
// Achievements: Store available achievements
|
||||
export const achievement = pgTable("achievement", {
|
||||
id,
|
||||
title: varchar("title", { length: 255 }).notNull(),
|
||||
description: text("description"),
|
||||
icon: varchar("icon", { length: 255 }), // Icon URL or identifier
|
||||
type: varchar("type", { length: 50 }).notNull(), // e.g., 'level_completion', 'streak', 'sharing'
|
||||
condition: jsonb("condition"), // Criteria for unlocking (JSON)
|
||||
points: integer("points").default(0).notNull(),
|
||||
isActive: boolean("is_active").default(true).notNull(),
|
||||
createdAt,
|
||||
updatedAt,
|
||||
});
|
||||
|
||||
// User Achievements: Track unlocked achievements per user
|
||||
export const userAchievement = pgTable("user_achievement", {
|
||||
id,
|
||||
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
achievementId: integer("achievement_id").notNull().references(() => achievement.id, { onDelete: "cascade" }),
|
||||
unlockedAt: timestamp("unlocked_at").defaultNow().notNull(),
|
||||
createdAt,
|
||||
updatedAt,
|
||||
});
|
||||
|
||||
// Parent-Child Relations: For parents to monitor children (optional, assuming parents are also users)
|
||||
export const parentChildRelation = pgTable("parent_child_relation", {
|
||||
id,
|
||||
parentId: text("parent_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
childId: text("child_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
relation: varchar("relation", { length: 50 }).default("parent").notNull(), // e.g., 'parent', 'guardian'
|
||||
createdAt,
|
||||
updatedAt,
|
||||
});
|
||||
Reference in New Issue
Block a user