47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import { PrismaPg } from '@prisma/adapter-pg'
|
|
import { Pool } from 'pg'
|
|
import 'dotenv/config'
|
|
|
|
const connectionString = process.env.DATABASE_URL
|
|
const pool = new Pool({ connectionString })
|
|
const adapter = new PrismaPg(pool)
|
|
|
|
const prisma = new PrismaClient({ adapter })
|
|
|
|
async function main() {
|
|
console.log('Clearing data...')
|
|
|
|
// 1. Delete all ApprovalLogs
|
|
await prisma.approvalLog.deleteMany({})
|
|
console.log('Cleared all ApprovalLogs')
|
|
|
|
// 2. Delete all Requests
|
|
await prisma.request.deleteMany({})
|
|
console.log('Cleared all Requests')
|
|
|
|
// 3. Delete ActivityLogs to clear history page completely
|
|
await prisma.activityLog.deleteMany({})
|
|
console.log('Cleared all ActivityLogs')
|
|
|
|
// 4. Reset all Item quantities to 0
|
|
await prisma.item.updateMany({
|
|
data: {
|
|
totalQuantity: 0,
|
|
borrowedQty: 0,
|
|
trialQty: 0,
|
|
billedQty: 0,
|
|
availableQty: 0,
|
|
damagedQty: 0,
|
|
soldQty: 0,
|
|
}
|
|
})
|
|
console.log('Reset all item quantities to 0')
|
|
|
|
console.log('Done!')
|
|
}
|
|
|
|
main()
|
|
.catch(console.error)
|
|
.finally(() => prisma.$disconnect())
|