Files
reader/scripts/wipe_db.js
T
virtus 75ed8e233b Add moderation APIs and admin UI
Add moderator/admin backend APIs and client features for managing novels and chapters. New endpoints include mod chapter routes (paginated list, single GET, PUT, DELETE, and bulk optimize), mod novel routes (create, GET by id, update, delete), genre CRUD, user bookmarks, novel comments, and rating endpoints. Update EPUB import to use a shared slugify util. Enhance moderator UI: chapter manager gains pagination, bulk optimization preview/apply, edit/delete dialogs; novel client adds genre management and edit/delete flows. Also update Prisma schema, add a DB wipe script, remove unused lib/data.ts, and adjust related types/utils and bookmark context.
2026-03-06 17:30:56 +07:00

61 lines
1.9 KiB
JavaScript

const { PrismaClient } = require('@prisma/client')
const mongoose = require('mongoose')
require('dotenv').config({ path: '.env.local' })
require('dotenv').config()
const prisma = new PrismaClient()
async function main() {
console.log('Connecting to MongoDB...')
// Connect to MongoDB using MONGODB_URI
const mongoUri = process.env.MONGODB_URI
if (!mongoUri) {
throw new Error('MONGODB_URI is not defined in env')
}
await mongoose.connect(mongoUri)
// Wipe MongoDB Chapters
console.log('Wiping chapters from MongoDB...')
try {
const chapterSchema = new mongoose.Schema({}, { strict: false })
const Chapter = mongoose.models.Chapter || mongoose.model('Chapter', chapterSchema, 'chapters')
const res = await Chapter.deleteMany({})
console.log(`Deleted ${res.deletedCount} chapters.`)
} catch (e) {
console.error('Error wiping mongo chapters', e)
}
// Wipe PostgreSQL Content
console.log('Wiping Novels, Genres, Comments, Bookmarks from PostgreSQL...')
try {
// Delete in order to respect foreign keys if Cascade isn't perfect, but Cascade is set on most.
await prisma.comment.deleteMany({})
console.log('Deleted all comments.')
await prisma.bookmark.deleteMany({})
console.log('Deleted all bookmarks.')
await prisma.novelGenre.deleteMany({})
console.log('Deleted all novel_genres.')
await prisma.genre.deleteMany({})
console.log('Deleted all genres.')
await prisma.novel.deleteMany({})
console.log('Deleted all novels.')
} catch (error) {
console.error('Error wiping postgres', error)
}
console.log('Cleanup complete.')
}
main()
.catch(console.error)
.finally(async () => {
await prisma.$disconnect()
await mongoose.disconnect()
process.exit(0)
})