Prmbr/scripts/seed-credits.ts
2025-08-26 21:44:24 +08:00

49 lines
1.0 KiB
TypeScript

import { prisma } from '../src/lib/prisma'
import { addCredit } from '../src/lib/services/credit'
async function seedCredits() {
try {
// Find the first user to add sample credits
const user = await prisma.user.findFirst()
if (!user) {
console.log('No users found. Please create a user first.')
return
}
console.log(`Adding sample credits for user: ${user.email}`)
// Add system gift
await addCredit(
user.id,
5.0,
'system_gift',
'Welcome bonus - Free credits for new users!'
)
// Add monthly allowance
await addCredit(
user.id,
20.0,
'subscription_monthly',
'Pro plan monthly allowance'
)
// Add user purchase
await addCredit(
user.id,
10.0,
'user_purchase',
'Top-up purchase via Stripe'
)
console.log('✅ Sample credits added successfully!')
} catch (error) {
console.error('❌ Error seeding credits:', error)
} finally {
await prisma.$disconnect()
}
}
seedCredits()