32 lines
912 B
JavaScript
32 lines
912 B
JavaScript
import { PrismaClient } from '@prisma/client'
|
|
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'
|
|
import { hash } from 'bcryptjs'
|
|
import path from 'path'
|
|
|
|
const password = process.env.SEED_ADMIN_PASSWORD
|
|
if (!password) {
|
|
console.error('SEED_ADMIN_PASSWORD requis')
|
|
process.exit(1)
|
|
}
|
|
|
|
const dbUrl = process.env.DATABASE_URL ?? 'file:./data/app.db'
|
|
const dbPath = dbUrl.startsWith('file:')
|
|
? path.resolve(process.cwd(), dbUrl.slice('file:'.length))
|
|
: dbUrl
|
|
|
|
const adapter = new PrismaBetterSqlite3({ url: dbPath })
|
|
const prisma = new PrismaClient({ adapter })
|
|
|
|
await prisma.user.upsert({
|
|
where: { email: 'mathieu.fort@gmail.com' },
|
|
update: {},
|
|
create: {
|
|
email: 'mathieu.fort@gmail.com',
|
|
name: 'Mathieu',
|
|
password: await hash(password, 12),
|
|
role: 'admin',
|
|
},
|
|
})
|
|
console.log('✅ Compte admin créé : mathieu.fort@gmail.com')
|
|
await prisma.$disconnect()
|