import { prisma } from '@/lib/prisma'; async function resetDatabase() { try { console.log('Starting database reset...'); // Clear all watch segments await prisma.videoWatchSegment.deleteMany({}); console.log('✓ Cleared VideoWatchSegment records'); // Clear all progress records await prisma.videoProgress.deleteMany({}); console.log('✓ Cleared VideoProgress records'); // Get all playlists with their videos const playlists = await prisma.playlist.findMany({ include: { videos: { orderBy: { index: 'asc' } } }, }); // For each playlist, unlock first video, lock the rest for (const playlist of playlists) { if (playlist.videos.length > 0) { // Unlock first video await prisma.video.updateMany({ where: { playlistId: playlist.id, index: 0 }, data: { locked: false }, }); // Lock all other videos await prisma.video.updateMany({ where: { playlistId: playlist.id, index: { gt: 0 } }, data: { locked: true }, }); console.log(`✓ Set unlock status for playlist: ${playlist.title}`); } } console.log('✓ Database reset complete!'); console.log('\nSummary:'); console.log('- All watch segments cleared'); console.log('- All progress records cleared'); console.log('- First video in each playlist unlocked'); console.log('- Remaining videos locked (require 80% completion of previous video)'); process.exit(0); } catch (error) { console.error('Error during reset:', error); process.exit(1); } } resetDatabase();