b6167bcb-7363-4695-9481-addd81de4367
This commit is contained in:
1 parent
fdc3b82d10
commit
d226dabba3
136 files changed
+13904
-2
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { exec } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const execAsync = promisify(exec)
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
export const maxDuration = 60
|
||||
|
||||
// POST /api/aos/seed — reseed the database (destructive, dev only)
|
||||
export async function POST() {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
return NextResponse.json({ error: 'not in production' }, { status: 403 })
|
||||
}
|
||||
try {
|
||||
// wipe via prisma (SQLite TRUNCATE not supported, use deleteMany per model in order)
|
||||
const { db } = await import('@/lib/db')
|
||||
await db.invoiceLine.deleteMany()
|
||||
await db.invoice.deleteMany()
|
||||
await db.asset.deleteMany()
|
||||
await db.licenseActivation.deleteMany()
|
||||
await db.license.deleteMany()
|
||||
await db.timeEntry.deleteMany()
|
||||
await db.task.deleteMany()
|
||||
await db.project.deleteMany()
|
||||
await db.lead.deleteMany()
|
||||
await db.deal.deleteMany()
|
||||
await db.person.deleteMany()
|
||||
await db.company.deleteMany()
|
||||
await db.auditLog.deleteMany()
|
||||
await db.setting.deleteMany()
|
||||
await db.module.deleteMany()
|
||||
await db.user.deleteMany()
|
||||
|
||||
await execAsync('bun run src/lib/seed.ts', { cwd: process.cwd() })
|
||||
return NextResponse.json({ ok: true })
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : 'seed failed'
|
||||
return NextResponse.json({ error: msg }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user