import Dexie, { type Table } from 'dexie'; import type { Monster } from './schema'; export class MonsterDatabase extends Dexie { monsters!: Table; constructor() { super('MonsterGeneratorDB'); this.version(1).stores({ monsters: '++id, name, createdAt' }); // Version 2: Add imageData field this.version(2).stores({ monsters: '++id, name, createdAt' }).upgrade(tx => { // No data migration needed, just schema update return tx.table('monsters').toCollection().modify(monster => { monster.imageData = monster.imageData || null; }); }); // Version 3: Add stats field this.version(3).stores({ monsters: '++id, name, createdAt' }).upgrade(tx => { // No data migration needed, just schema update return tx.table('monsters').toCollection().modify(monster => { monster.stats = monster.stats || null; }); }); } } export const db = new MonsterDatabase();