import Dexie, { type Table } from "dexie" import type { FamilyMember } from "@/types/family" export interface GlobalSettings { key: string value: any } export interface StoredImage { id: string blob: Blob mimeType: string createdAt: string } export interface ActivityLog { id: string action: "create" | "update" | "delete" | "import" | "export" entityType: "member" | "photo" | "story" | "settings" entityId?: string entityName?: string changes?: any timestamp: string userId?: string userName?: string } export class FamilyTreeDB extends Dexie { members!: Table settings!: Table images!: Table activityLogs!: Table constructor() { super("FamilyTreeDB") this.version(1).stores({ members: "id, fullName, fatherId, motherId, [fatherId+motherId]", // Index for searching settings: "key", // Key-value store for rootId etc. images: "id", // Store images by ID }) this.version(2).stores({ members: "id, fullName, fatherId, motherId, [fatherId+motherId]", // Index for searching settings: "key", // Key-value store for rootId etc. images: "id", // Store images by ID activityLogs: "id, timestamp, action, entityType, entityId", }) } } export const db = new FamilyTreeDB()